QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#574796 | #5109. Spider Walk | RngBased | WA | 373ms | 9072kb | C++20 | 3.6kb | 2024-09-19 00:38:47 | 2024-09-19 00:38:47 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define x first
#define y second
#define all(x) x.begin(), x.end()
#define N 200005
using namespace std;
int n, m, s;
vector<pii> edge;
struct BIT{
int arr[N];
void modify(int x, int c){
for (; x < N; x += (x & -x))
arr[x] += c;
}
int query(int x){
int ans = 0;
for (; x > 0; x -= (x & -x))
ans += arr[x];
return ans;
}
}bit;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m >> s;
for (int i = 1; i <= m; i++){
int a, b; cin >> a >> b;
edge.emplace_back(a, b);
}
sort(all(edge)), reverse(all(edge));
for (int i = 1; i <= n; i++){
int d = min(abs(i - s), n - abs(s - i));
bit.modify(i, d), bit.modify(i + 1, -d);
}
// cerr << "OK\n";
// for (int i = 1; i <= n; i++)
// cerr << bit.query(i) << " \n"[i == n];
for (auto [_, u]: edge){
int v = (u == n) ? 1 : u + 1;
int c1 = bit.query(u), c2 = bit.query(v);
int c0 = (u == 1) ? bit.query(n) : bit.query(u - 1), c3 = (v == n) ? bit.query(1) : bit.query(v + 1);
// cerr << u << " " << v << " " << c1 << " " << c2 << '\n';
assert(abs(c1 - c2) <= 1);
bit.modify(u, c2 - c1 - (c2 == c0 + 2)), bit.modify(u + 1, c1 - c2 + (c2 == c0 + 2));
bit.modify(v, c1 - c2 - (c1 == c3 + 2)), bit.modify(v + 1, c2 - c1 + (c1 == c3 + 2));
if (bit.query(1) - bit.query(u) == u || (u == 1 && bit.query(n) - bit.query(1) == 2)){
int l = v, r = n + 1, c = bit.query(n);
while (l < r){
int mid = (l + r) >> 1;
if (bit.query(mid) - c == n - mid)
r = mid;
else l = mid + 1;
}
bit.modify(1, -1), bit.modify(u, 1);
bit.modify(l, -1), bit.modify(n + 1, 1);
// cerr << "go left1 " << l << '\n';
}
else {
int l = 1, r = u, c = bit.query(u);
while (l < r){
int mid = (l + r) >> 1;
if (bit.query(mid) - c == u - mid + 1)
r = mid;
else l = mid + 1;
}
bit.modify(l, -1), bit.modify(u, 1);
// cerr << "go left2 " << l << "\n";
}
if (bit.query(n) - bit.query(v) == n - v + 1 || (v == n && bit.query(1) - bit.query(n) == 2)){
int l = 1, r = u + 1, c = bit.query(1);
while (l < r){
int mid = (l + r) >> 1;
if (bit.query(mid) - c == mid - 1)
l = mid + 1;
else r = mid;
}
// cerr << "go right1 " << l << " " << c << '\n';
bit.modify(v + 1, -1), bit.modify(n + 1, 1);
bit.modify(1, -1), bit.modify(l, 1);
}
else {
int l = v + 1, r = n + 1, c = bit.query(v);
while (l < r){
int mid = (l + r) >> 1;
if (bit.query(mid) - c == mid - v + 1)
l = mid + 1;
else r = mid;
}
bit.modify(v + 1, -1), bit.modify(l, 1);
// cerr << "go right2 " << l << "\n";
}
// for (int i = 1; i <= n; i++)
// cerr << bit.query(i) << " \n"[i == n];
}
for (int i = 1; i <= n; i++)
cout << bit.query(i) << "\n";
return 0;
}
/*
8 16 5
1 8
2 7
3 6
4 5
5 4
6 3
7 2
8 1
9 8
10 7
11 6
12 5
13 4
14 3
15 2
16 1
7 5 6
2 1
4 3
6 3
8 7
10 5
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 335ms
memory: 7904kb
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: 0
Accepted
time: 357ms
memory: 8640kb
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:
ok 200000 lines
Test #3:
score: -100
Wrong Answer
time: 373ms
memory: 9072kb
input:
189566 481938 180576 30827 77075 266878 6648 251124 43809 22925 151090 165947 34594 248343 179640 217340 68611 1607 145089 312862 151436 72904 160893 55989 147148 189122 110726 408438 184618 461208 122245 404636 154726 148242 165504 8878 31007 300131 17893 433102 58524 388216 49111 307221 65807 1774...
output:
8690 8691 8692 8693 8694 8695 8696 8697 8698 8699 8700 8701 8702 8703 8704 8705 8706 8707 8708 8709 8710 8711 8712 8713 8714 8715 8716 8717 8718 8719 8720 8721 8722 8723 8724 8725 8726 8727 8728 8729 8730 8731 8732 8733 8734 8735 8736 8737 8738 8739 8739 8740 8741 8742 8743 8744 8745 8746 8747 8748 ...
result:
wrong answer 1st lines differ - expected: '8691', found: '8690'