QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#492913#5109. Spider Walkarnold518WA 279ms9348kbC++172.0kb2024-07-26 17:10:302024-07-26 17:10:30

Judging History

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

  • [2024-07-26 17:10:30]
  • 评测
  • 测评结果:WA
  • 用时:279ms
  • 内存:9348kb
  • [2024-07-26 17:10:30]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 2e5;
const int MAXM = 5e5;

int N, M, S;
pii A[MAXM+10];

ll tree[MAXN+10];
void update(int i, int k) { for(; i<=N; i+=(i&-i)) tree[i]+=k; }
int query(int i) { ll ret=0; for(; i>0; i-=(i&-i)) ret+=tree[i]; return ret; }

int norm(int k)
{
    k%=N;
    if(k<=0) k+=N;
    return k;
}

void update(int l, int r, int k)
{
    update(l, k);
    if(r+1<=N) update(r+1, -k);
}
void update2(int l, int r, int k)
{
    if(l>r) return;
    l=norm(l); r=norm(r);
    if(l<=r) update(l, r, k);
    else update(l, N, k), update(1, r, k);
}
int query2(int k) { return query(norm(k)); }

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);

    scanf("%d%d%d", &N, &M, &S);
    for(int i=1; i<=M; i++) scanf("%d%d", &A[i].first, &A[i].second);
    sort(A+1, A+M+1, greater<pii>());

    for(int i=1; i<=N; i++) update2(i, i, min({abs(S-i), abs(S+N-i), abs(S-N-i)}));

    for(int i=1; i<=M; i++)
    {
        int p=A[i].second;
        int a=query2(p), b=query2(p+1);
        if(a<b)
        {
            update2(p, p, 1); update2(p+1, p+1, -1);
            if(query2(p-1)<a) update2(p, p, -1);

            int lo=1, hi=N;
            while(lo+1<hi)
            {
                int mid=lo+hi>>1;
                if(query2(p+mid)==a+mid) lo=mid;
                else hi=mid;
            }
            update2(p+2, lo, -1);
        }
        else if(b<a)
        {
            update2(p, p, -1); update2(p+1, p+1, 1);
            if(query2(p+2)<b) update2(p+1, p+1, -1);

            int lo=0, hi=N-1;
            while(lo+1<hi)
            {
                int mid=lo+hi>>1;
                if(query2(p-mid)==a+mid) lo=mid;
                else hi=mid;
            }
            update2(p-lo, p-1, -1);
        }
        // for(int i=1; i<=N; i++) printf("%d ", query2(i)); printf("\n");
    }
    for(int i=1; i<=N; i++) printf("%d\n", query2(i));
}

详细

Test #1:

score: 100
Accepted
time: 273ms
memory: 9348kb

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: 279ms
memory: 9284kb

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
1
2
2
3
3
5
5
7
9
9
10
11
11
13
14
14
15
16
16
19
19
19
19
20
20
20
19
21
22
22
23
24
25
25
26
26
27
28
27
27
29
29
31
32
33
33
35
35
37
39
39
40
40
42
42
44
44
45
45
47
50
51
51
52
52
53
53
55
55
57
59
60
62
64
67
67
69
69
69
72
73
72
74
74
76
76
79
79
80
80
81
81
85
86
86
87
89
91
92
92
94
94
95...

result:

wrong answer 2nd lines differ - expected: '0', found: '1'