QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#574732 | #5109. Spider Walk | RngBased | WA | 314ms | 9164kb | C++20 | 3.1kb | 2024-09-19 00:08:16 | 2024-09-19 00:08:17 |
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';
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){
int l = v, r = n, c = bit.query(1);
while (l < r){
int mid = (l + r) >> 1;
if (bit.query(mid) - c - 1 == n - mid + 1)
r = mid;
else l = mid + 1;
}
bit.modify(1, -1), bit.modify(u, 1);
bit.modify(l, -1), bit.modify(n + 1, 1);
}
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);
}
if (bit.query(n) - bit.query(v) == n - v + 1){
int l = 1, r = u + 1, c = bit.query(n);
while (l < r){
int mid = (l + r) >> 1;
if (bit.query(mid) - c - 1 == mid + 1)
l = mid + 1;
else r = mid;
}
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);
}
// 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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 314ms
memory: 9164kb
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 -1 0 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...
result:
wrong answer 3rd lines differ - expected: '2', found: '-1'