QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#473068 | #5109. Spider Walk | karuna | WA | 399ms | 18432kb | C++20 | 2.3kb | 2024-07-11 21:34:26 | 2024-07-11 21:34:26 |
Judging History
answer
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#define ff first
#define ss second
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
int main() {
cin.tie(0); ios_base::sync_with_stdio(0);
int n, m, s;
cin >> n >> m >> s;
--s;
pii c[m];
for (auto &[x, y] : c) cin >> x >> y, --y;
sort(c, c + m);
int a[n] = {};
for (int i = 0; i < n; i++) a[i] = 1e9;
for (int i = 0; i < n; i++) {
a[(s + i) % n] = min(a[(s + i) % n], i);
a[(s + n - i) % n] = min(a[(s + n - i) % n], i);
}
int b[n] = {};
for (int i = 0; i < n; i++) {
b[i] = a[(i + 1) % n] - a[i];
}
set<int> S[3];
for (int i = 0; i < n; i++) S[b[i] + 1].insert(i);
for (int i = m; i > 0; i--) {
int p = c[i - 1].ss;
if (s == p) s = (p + 1) % n;
else if (s == (p + 1) % n) s = p;
if (b[p] == 0) continue;
if (b[p] == 1) {
int pos = 1e9;
for (int t : {0, 1}) {
if (S[t].empty()) continue;
auto it = S[t].lower_bound(p);
int k = it == S[t].end() ? n + *S[t].begin() : *it;
pos = min(pos, k);
}
pos %= n;
S[b[pos] + 1].erase(pos);
b[pos] += 1;
S[b[pos] + 1].insert(pos);
int q = (p + n - 1) % n;
if (b[q] == 1) {
S[b[p] + 1].erase(p);
b[p] -= 1;
S[b[p] + 1].insert(p);
}
else {
S[b[q] + 1].erase(q);
b[q] += 1;
S[b[q] + 1].insert(q);
S[b[p] + 1].erase(p);
b[p] -= 2;
S[b[p] + 1].insert(p);
}
}
else {
int pos = -1e9;
for (int t : {1, 2}) {
if (S[t].empty()) continue;
auto it = S[t].upper_bound(p);
int k = it == S[t].begin() ? *prev(S[t].end()) - n : *prev(it);
pos = max(pos, k);
}
pos = (n + pos % n) % n;
S[b[pos] + 1].erase(pos);
b[pos] -= 1;
S[b[pos] + 1].insert(pos);
int q = (p + 1) % n;
if (b[q] == -1) {
S[b[p] + 1].erase(p);
b[p] += 1;
S[b[p] + 1].erase(p);
}
else {
S[b[q] + 1].erase(q);
b[q] -= 1;
S[b[q] + 1].insert(q);
S[b[p] + 1].erase(p);
b[p] += 2;
S[b[p] + 1].insert(p);
}
}
}
a[s] = 0;
for (int i = 0; i < n; i++) {
a[(s + i + 1) % n] = a[(s + i) % n] + b[(s + i) % n];
}
for (int i = 0; i < n; i++) {
cout << a[i] << '\n';
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 371ms
memory: 18428kb
input:
200000 500000 116205 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50...
output:
2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...
result:
ok 200000 lines
Test #2:
score: -100
Wrong Answer
time: 399ms
memory: 18432kb
input:
200000 500000 200000 1 148896 2 178903 3 36800 4 98361 5 79634 6 29266 7 51632 8 166082 9 66246 10 145043 11 41644 12 81858 13 87530 14 199625 15 127160 16 49786 17 181673 18 48403 19 30274 20 101455 21 105100 22 52149 23 22810 24 79308 25 191579 26 96365 27 154697 28 45255 29 64965 30 192604 31 330...
output:
1 0 1 1 2 2 3 3 4 5 6 7 8 8 9 10 11 12 12 11 12 13 14 15 16 17 18 17 18 19 20 21 21 22 23 24 25 26 27 28 27 28 28 29 30 31 31 32 32 33 34 35 36 37 38 39 40 41 42 42 43 44 45 46 47 48 49 50 51 52 52 53 54 55 56 57 58 59 59 60 61 62 61 62 63 64 65 66 66 67 67 68 68 69 70 70 71 72 73 74 75 76 76 77 78 ...
result:
wrong answer 73258th lines differ - expected: '72426', found: '72424'