Submission #60989924
Source Code Expand
// Problem: D - Santa Claus 2
// Contest: AtCoder - UNIQUE VISION Programming Contest 2024 Christmas (AtCoder Beginner Contest 385)
// URL: https://atcoder.jp/contests/abc385/tasks/abc385_d
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define AC return 0
const ll mod = 1; // Be careful, 998244353 or 998244853.
const ll dx[] = {0, 1, 0, -1};
const ll dy[] = {1, 0, -1, 0};
mt19937 rnd(chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now().time_since_epoch()).count());
void ts() {
cerr << "The code is running!\n";
}
ll read() {
char c;
bool isf = 0;
while (!isdigit(c = getchar())) isf = (c == '-');
ll res = (c ^ 48);
while (isdigit(c = getchar())) res = (res << 3) + (res << 1) + (c ^ 48);
return isf ? -res : res;
}
void write(ll x) {
if (x < 0)
putchar('-'), x = -x;
if (x >= 10)
write(x / 10);
putchar('0' + x % 10);
}
void updmin(ll& x, ll y) {
x = min(x, y);
}
void updmax(ll& x, ll y) {
x = max(x, y);
}
ll qpow(ll x, ll y) {
if (y == 0) {
return 1;
}
ll res = qpow(x, y / 2);
res *= res;
res %= mod;
if (y % 2) {
res *= x;
res %= mod;
}
return res;
}
ll randint(ll l, ll r) {
return rnd() % (r - l + 1) + l;
}
void openf(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
ll tc = 1, n, m, x, y, ans, px[214514], py[214514];
set<ll> xx, yy;
map<ll, ll> tox, toy;
set<ll> sx[214514], sy[214514];
const ll inf = 1e18;
void init() {
;
}
void solve() {
init();
cin >> n >> m >> x >> y;
for (ll i = 1; i <= n; i++) {
cin >> px[i] >> py[i];
xx.insert(px[i]);
yy.insert(py[i]);
sx[i].insert(-inf);
sx[i].insert(inf);
sy[i].insert(-inf);
sy[i].insert(inf);
}
ll tot = 0;
for (ll kk : xx) {
tot++;
tox[kk] = tot;
}
tot = 0;
for (ll kk : yy) {
tot++;
toy[kk] = tot;
}
for (ll i = 1; i <= n; i++) {
sx[tox[px[i]]].insert(py[i]);
sy[toy[py[i]]].insert(px[i]);
px[i] = tox[px[i]];
py[i] = toy[py[i]];
}
for (ll i = 1; i <= m; i++) {
char c;
cin >> c;
ll d;
cin >> d;
ll nx = x, ny = y;
if (c == 'U') {
ny += d;
} else if (c == 'D') {
ny -= d;
} else if (c == 'L') {
nx -= d;
} else {
nx += d;
}
vector<ll> bin;
if (nx == x) {
if (tox.find(x) != tox.end()) {
ll tx = tox[x];
auto it1 = lower_bound(sx[tx].begin(), sx[tx].end(), min(ny, y));
auto it2 = upper_bound(sx[tx].begin(), sx[tx].end(), max(ny, y));
for (auto it = it1; it != it2 && it != sx[tx].end(); it++) {
if (*it == inf || *it == -inf) {
continue;
}
ans++;
bin.push_back(*it);
}
for (ll num : bin) {
sx[tx].erase(num);
sy[toy[num]].erase(x);
}
}
} else if (ny == y) {
if (toy.find(y) != toy.end()) {
ll ty = toy[y];
auto it1 = lower_bound(sy[ty].begin(), sy[ty].end(), min(nx, x));
auto it2 = upper_bound(sy[ty].begin(), sy[ty].end(), max(nx, x));
for (auto it = it1; it != it2 && it != sy[ty].end(); it++) {
if (*it == inf || *it == -inf) {
continue;
}
ans++;
bin.push_back(*it);
}
for (ll num : bin) {
sy[ty].erase(num);
sx[tox[num]].erase(y);
}
}
}
x = nx;
y = ny;
}
cout << x << " " << y << " " << ans;
}
int main() {
// openf("data");
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
// tc = read();
while (tc--) {
solve();
putchar("\n "[(!tc)]);
}
// printf("Time: %.6lf\n", (double)clock() / CLOCKS_PER_SEC);
AC;
}
/*
Things to check:
1. When testing multiple sets of data, remember to clear the array.
2. When clearing, pay attention to clearing the area, starting from 0 or 1. If time permits, use memset.
3. Delete the debugged code.
4. Do you need to enable file input/output.
5. Use faster input and output methods.
6. INT or long long.
7. Pay attention to time complexity and space complexity, and control constants.
8. Think twice before acting.
9. Talk is cheap, show me the code.
10. The most important one, zxq's brain.
*/
/*
_|_|_|_|_| _| _| _|_| _| _| _|_| _| _|_| _| _|
_| _| _| _| _| _| _| _| _| _| _| _| _| _| _|
_| _| _| _|_| _| _| _| _| _| _|_|_|_|
_| _| _| _| _| _| _| _| _| _| _| _|
_|_|_|_|_| _| _| _|_| _| _| _| _|_|_|_| _| _|_|_|_| _|
.................................................................................................................
.................................................................................................................
.................................................................................................................
.................................................................................................................
.................................................................................................................
.......RRRRRRRRRRRRRRRRRRRR...................PPPPPPPPPPPPPPPPPPPP...............................................
.......RRRRRRRRRRRRRRRRRRRRRR.................PPPPPPPPPPPPPPPPPPPPPP.............................................
.......RRRRRRRRRRRRRRRRRRRRRRR................PPPPPPPPPPPPPPPPPPPPPPPP...........................................
.......RRRR.................RRRRR.............PPPP...............PPPPP...........................................
.......RRRR.................RRRRR.............PPPP................PPPPP..........................................
.......RRRR.................RRRRR.............PPPP................PPPPP..........................................
.......RRRR...............RRRRR...............PPPP...............PPPPP...........................................
.......RRRR............RRRRRR.................PPPP.............PPPPPP............................................
.......RRRR............RRRRRR.................PPPP............PPPPPP.............................................
.......RRRR........RRRRRR.....................PPPP........PPPPPPP................................................
.......RRRRRRRRRRRRRRRRRR.....................PPPPPPPPPPPPPPPPPP.................................................
.......RRRRRRRRRRRRRRRRRR.....................PPPPPPPPPPPPPPPP...................................................
.......RRRR..........RRRR.....................PPPPP.................................+++................+++.......
.......RRRR...........RRRR....................PPPPP.................................+++................+++.......
.......RRRR.............RRRR..................PPPPP.................................+++................+++.......
.......RRRR..............RRRR.................PPPPP...........................+++++++++++++++....+++++++++++++++.
.......RRRR...............RRRR................PPPPP...........................+++++++++++++++....+++++++++++++++.
.......RRRR................RRRR...............PPPPP.................................+++................+++.......
.......RRRR.................RRRR..............PPPPP.................................+++................+++.......
.......RRRR...................RRRR............PPPPP.................................+++................+++.......
.................................................................................................................
.................................................................................................................
.................................................................................................................
.................................................................................................................
.................................................................................................................
*/
Submission Info
| Submission Time |
|
| Task |
D - Santa Claus 2 |
| User |
joe_zxq |
| Language |
C++ 20 (gcc 12.2) |
| Score |
0 |
| Code Size |
8606 Byte |
| Status |
TLE |
| Exec Time |
2212 ms |
| Memory |
117488 KiB |
Compile Error
Main.cpp: In function ‘void openf(std::string)’:
Main.cpp:68:12: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
68 | freopen((s + ".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:69:12: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
69 | freopen((s + ".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
0 / 425 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
sample_01.txt, sample_02.txt |
| All |
hand.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, sample_01.txt, sample_02.txt |
| Case Name |
Status |
Exec Time |
Memory |
| hand.txt |
AC |
8 ms |
23768 KiB |
| random_01.txt |
AC |
27 ms |
23716 KiB |
| random_02.txt |
AC |
27 ms |
23700 KiB |
| random_03.txt |
AC |
27 ms |
23704 KiB |
| random_04.txt |
AC |
534 ms |
105076 KiB |
| random_05.txt |
AC |
577 ms |
105628 KiB |
| random_06.txt |
TLE |
2210 ms |
45316 KiB |
| random_07.txt |
TLE |
2212 ms |
76200 KiB |
| random_08.txt |
AC |
547 ms |
103964 KiB |
| random_09.txt |
AC |
649 ms |
117488 KiB |
| random_10.txt |
AC |
97 ms |
41720 KiB |
| random_11.txt |
AC |
362 ms |
83372 KiB |
| random_12.txt |
AC |
410 ms |
83296 KiB |
| random_13.txt |
AC |
292 ms |
83300 KiB |
| random_14.txt |
AC |
362 ms |
83368 KiB |
| random_15.txt |
AC |
375 ms |
83304 KiB |
| random_16.txt |
AC |
406 ms |
83360 KiB |
| random_17.txt |
AC |
376 ms |
83232 KiB |
| random_18.txt |
AC |
363 ms |
83164 KiB |
| random_19.txt |
AC |
378 ms |
83368 KiB |
| random_20.txt |
AC |
378 ms |
83432 KiB |
| random_21.txt |
AC |
374 ms |
83232 KiB |
| random_22.txt |
AC |
397 ms |
83312 KiB |
| sample_01.txt |
AC |
9 ms |
23688 KiB |
| sample_02.txt |
AC |
9 ms |
23712 KiB |