QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#390061#5109. Spider Walk0_GB_RAM#WA 352ms9200kbC++232.4kb2024-04-15 01:33:382024-04-15 01:33:39

Judging History

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

  • [2024-04-15 01:33:39]
  • 评测
  • 测评结果:WA
  • 用时:352ms
  • 内存:9200kb
  • [2024-04-15 01:33:38]
  • 提交

answer

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

using ll=long long;
//#define int ll
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define all(x) begin(x),end(x)
#define sz(x) (int)((x).size())
using pii=pair<int,int>;
using vi=vector<int>;
#define fi first
#define se second
#define pb push_back

int t[200500];
int get(int v)
{
    v++;
    int s = 0;
    for (int i=v; i>0; i=i&(i+1), i--)
        s += t[i];
    return s;
}

void upd(int v, int x)
{
    v++;
    for (int i=v; i<200500; i|=(i+1))
        t[i] += x;
}

int n, m, s;
int gett(int v)
{
    return get((v+n+n+n)%n);
}

void upd(int l, int r, int d)
{
    if (l > r)
        return;
    for (int i=-1; i<=1; i++)
    {
        int lx = max(l+i*n, 0);
        int rx = min(r+i*n, n-1);
        if (lx <= rx)
            upd(lx, d), upd(rx+1, -d);
    }
}

void bridge(int t) {
//    for (int i=0; i<n; i++)
//        cout<<get(i)<<" ";
//    cout<<"\n";
    int x = get(t);
    int y = get((t + 1) % n);
    int d = y - x;
    upd(t, d);
    upd(t + 1, -d);
    upd((t + 1) % n, -d);
    upd((t + 1) % n + 1, d);

    swap(x, y);
    if (x < y)
    {
        if (gett(t+2) < y - 1)
            upd((t+1)%n, -1), upd((t+1)%n+1, 1);
        int r = t;
        int l = t-n;
        while (r-l>1)
        {
            int m = (l+r)/2;
            if (gett(m) - x == t - m + 1)
                r = m;
            else
                l = m;
        }
        upd(r, t-1, -1);
    }
    else
    {
        if (gett(t-1) < x - 1)
            upd(t, -1), upd(t+1, 1);
        int l = t+1;
        int r = t+n+1;
        while (r-l>1)
        {
            int m = (l+r)/2;
            if (gett(m) - y == m - (t+1) + 1)
                l = m;
            else
                r = m;
        }
        upd(t+2, l, -1);
    }
}

signed main() {
	cin.tie(0)->sync_with_stdio(0);
    cin.exceptions(cin.failbit);

    cin>>n>>m>>s;
    s--;
    vector<pair<int, int> > br;
    for (int i=0; i<m; i++)
    {
        int d, t;
        cin>>d>>t;
        t--;
        br.pb({d, t});
    }
    for (int i=0; i<n; i++)
    {
        int d = min(abs(i-s), abs(i+n-s));
        upd(i, d);
        upd(i+1, -d);
    }

    sort(br.begin(), br.end());
    reverse(br.begin(), br.end());
    for (auto [d, t] : br)
        bridge(t);
    for (int i=0; i<n; i++)
        cout<<get(i)<<"\n";
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 297ms
memory: 8552kb

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: 332ms
memory: 9164kb

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: 0
Accepted
time: 352ms
memory: 9200kb

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:

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
8740
8740
8741
8742
8743
8744
8745
8746
8747
8748
8749
...

result:

ok 189566 lines

Test #4:

score: -100
Wrong Answer
time: 350ms
memory: 7660kb

input:

181447 483992 86977
107095 161626
239957 140211
424191 79709
399773 77498
277365 32886
190721 131207
240187 140835
218366 6622
33108 76258
330939 140453
164405 119170
476970 49217
21280 120632
97648 159438
135504 178839
359378 170055
274161 44870
119531 84308
166512 22284
271134 116871
87409 101513
...

output:

93562
86215
86031
86030
86029
86028
86027
86026
86025
86024
86023
86022
86021
86020
86019
86018
86017
86017
86016
86015
86014
86013
86012
86011
86010
86009
86008
86007
86006
86005
86004
86003
86002
86001
86000
85999
85999
85998
85997
85996
85995
85994
85993
85992
85991
85990
85989
85988
85987
85986
...

result:

wrong answer 1st lines differ - expected: '86033', found: '93562'