ABC385
2024年12月28日小于 1 分钟
D - Santa Claus 2
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n, m, sx, sy;
map<int, set<int>> xx, yy;
int ans = 0;
// 摧毁 (x,l~r) 上的房子,并计数
void checkX(int x, int l, int r)
{
while (1)
{
auto p = xx[x].lower_bound(l);
if (p != xx[x].end() && *p <= r)
{
ans++;
xx[x].erase(p);
yy[*p].erase(x);
}
else
{
break;
}
}
}
// 摧毁 (l~r,y) 上的房子,并计数
void checkY(int y, int l, int r)
{
while (1)
{
auto p = yy[y].lower_bound(l);
if (p != yy[y].end() && *p <= r)
{
ans++;
yy[y].erase(p);
xx[*p].erase(y);
}
else
{
break;
}
}
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m >> sx >> sy;
for (int i = 1; i <= n; i++)
{
int x, y;
cin >> x >> y;
xx[x].insert(y);
yy[y].insert(x);
}
ans = 0;
for (int i = 1; i <= m; i++)
{
char op;
int len;
cin >> op >> len;
if (op == 'U')
{
checkX(sx, sy, sy + len);
sy += len;
}
if (op == 'D')
{
checkX(sx, sy - len, sy);
sy -= len;
}
if (op == 'L')
{
checkY(sy, sx - len, sx);
sx -= len;
}
if (op == 'R')
{
checkY(sy, sx, sx + len);
sx += len;
}
}
cout << sx << " " << sy << " " << ans;
return 0;
}