QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#574778#5109. Spider WalkRngBasedWA 329ms8404kbC++203.5kb2024-09-19 00:27:192024-09-19 00:27:20

Judging History

你现在查看的是最新测评结果

  • [2024-09-19 00:27:20]
  • 评测
  • 测评结果:WA
  • 用时:329ms
  • 内存:8404kb
  • [2024-09-19 00:27:19]
  • 提交

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 || (u == 1 && bit.query(n) - bit.query(1) == 2)){
            int l = v, r = n + 1, c = bit.query(1);
            while (l < r){
                int mid = (l + r) >> 1;
                if (bit.query(mid) - c == 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);
            // 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(n);
            while (l < r){
                int mid = (l + r) >> 1;
                if (bit.query(mid) - c == mid)
                    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"[i == n];
    
    return 0;
}
/*
8 8 5
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8

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: 0
Wrong Answer
time: 329ms
memory: 8404kb

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:

wrong answer 116211th lines differ - expected: '2', found: '3'