QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#727202#9242. An Easy Geometry ProblemsitablechairAC ✓1905ms33404kbC++144.4kb2024-11-09 11:58:242024-11-09 11:58:26

Judging History

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

  • [2024-11-09 11:58:26]
  • 评测
  • 测评结果:AC
  • 用时:1905ms
  • 内存:33404kb
  • [2024-11-09 11:58:24]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define sz(x) (signed)x.size()
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define For(i,l,r) for(int i=l;i<=r;i++)
#define ForD(i,l,r) for(int i=r;i>=l;i--)
#define F "C"
#define fio freopen(F".inp","r",stdin);freopen(F".out","w",stdout);

using namespace std;

#ifdef NCGM
#include<C:/NCGM/headers/debug.h>
#else
#define debug(...) "mmb"
#endif

const int N=2e5+3,MOD=1e9+7,BASE=10007;

int n,q,k,b,a[N],b1[N];
ll POW[N];

struct BIT {
    ll pf[N];
    void upd(int idx,int val) {
        if (idx<=0) return;
        while(idx<=n) {
            pf[idx]+=val;
            idx+=idx&(-idx);
        }
    }
    ll query(int idx) {
        ll ans=0;
        while(idx>0) {
            ans+=pf[idx];
            idx-=idx&(-idx);
        }
        return ans;
    }
    void update(int l,int r,int val) {
        upd(l,val);
        upd(r+1,-val);
    }
} bit;

struct Node {
    ll hsh;
    int l,r;
    Node(ll hsh=0,int l=0,int r=0): hsh(hsh),l(l),r(r) {};
} st[4*N],st1[4*N];
Node mrg(const Node &A,const Node &B) {
    if (A.l<0) return B;
    if (B.l<0) return A;
    Node ans(B.hsh,A.l,B.r);
    ans.hsh=(B.hsh+A.hsh*POW[B.r-B.l+1]);
    return ans;
}
void build(int id,int l,int r,int *src,Node *out) {
    if (l==r) {
        out[id]=Node(src[l],l,l);
        return;
    }
    int mid=l+r>>1;
    build(id*2,l,mid,src,out);
    build(id*2+1,mid+1,r,src,out);
    out[id]=mrg(out[id*2],out[id*2+1]);
}
void update(int id,int l,int r,int u,int val,Node *out) {
    if (l>u || r<u) return;
    if (l==r)return void(out[id]=Node(out[id].hsh+val,l,l));

    int mid=l+r>>1;
    update(id*2,l,mid,u,val,out);
    update(id*2+1,mid+1,r,u,val,out);
    out[id]=mrg(out[id*2],out[id*2+1]);
}
Node query(int id,int l,int r,int u,int v,Node *in) {
    if (l>v || r<u) return Node(0,-1,-1);
    if (l>=u && r<=v) return in[id];
    int mid=l+r>>1;
    return mrg(query(id*2,l,mid,u,v,in),query(id*2+1,mid+1,r,u,v,in));
}
bool check(int l,int r) {
    if (l<=0 || r>n) return 0;
    if ((r-l)%2) return 0;
    return (bit.query(r)-bit.query(l)==k*((r-l)/2)+b);
}
void refine(int x) {
    if (x<=0 || x>n-2) return;
    int nw=bit.query(x)-2*bit.query(x+1)+bit.query(x+2);
    int old=query(1,1,n-2,x,x,st).hsh;
    update(1,1,n-2,x,nw-old,st);
    update(1,1,n-2,n-x-1,nw-old,st1);
}
int main() {
    //fio
    cin.tie(0)->sync_with_stdio(0);
    cin >> n >> q >> k >> b;
    POW[0]=1;
    For(i,1,n) POW[i]=POW[i-1]*BASE;
    For(i,1,n) cin >> a[i];
    For(i,1,n-2) b1[i]=a[i+2]-2*a[i+1]+a[i];
    //For(i,1,n-2) cout << b1[i] << " ";
    //cout << endl;
    build(1,1,n-2,b1,st);
    reverse(b1+1,b1+n-1);
    build(1,1,n-2,b1,st1);
    For(i,1,n) bit.update(i,i,a[i]);
    /*For(i,1,n-2) cout << query(1,1,n-2,i,i,st).hsh << " ";
    cout << endl;
    For(i,1,n-2) cout << query(1,1,n-2,i,i,st1).hsh << " ";
    cout << endl;*/
    while(q--) {
        int t;
        cin >> t;
        if (t==1) {
            int l,r,val;
            cin >> l >> r >> val;
            bit.update(l,r,val);
            refine(r-1);
            refine(r);
            refine(l-1);
            refine(l-2);
            /*For(i,1,n-2) cout << query(1,1,n-2,i,i,st).hsh << " ";
            cout << endl;
            For(i,1,n-2) cout << query(1,1,n-2,i,i,st1).hsh << " ";
            cout << endl;&*/
        } else {
            int i;
            cin >> i;
            if (!check(i-3,i+3) && check(i-2,i+2) && check(i-1,i+1)) {
                cout << 2 << endl;
                continue;
            }
            if (!check(i-2,i+2) && check(i-1,i+1)) {
                cout << 1 << endl;
                continue;
            }
            if (!check(i-1,i+1)) {
                cout << 0 << endl;
                continue;
            }
            int l=1,r=min(i-3,n-i-2);
            while(l<r) {
                int mid=l+(r-l+1)/2;
                if (query(1,1,n-2,i-mid-2,i-3,st).hsh==query(1,1,n-2,n-i-mid-1,n-i-2,st1).hsh) l=mid;
                else r=mid-1;
            }
            int tmp=l;
            l=3,r=tmp+2;
            while(l<r) {
                int mid=l+(r-l+1)/2;
                if (check(i-mid,i+mid) && check(i-mid+1,i+mid-1)) l=mid;
                else r=mid-1;
            }
            cout << l << endl;
        }
    }
    return 0;
}

这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 31676kb

input:

6 6 6 2
1 5 9 10 15 18
2 2
1 3 3 -3
2 2
1 3 4 3
2 3
2 4

output:

1
0
2
0

result:

ok 4 number(s): "1 0 2 0"

Test #2:

score: 0
Accepted
time: 11ms
memory: 33072kb

input:

5000 5000 2 0
-329 -328 -327 -326 -325 -324 -323 -322 -321 -320 -319 -318 -317 -316 -315 -314 -313 -312 -311 -310 -309 -308 -307 -306 -305 -304 -303 -302 -301 -300 -299 -298 -297 -296 -295 -294 -293 -292 -291 -290 -289 -288 -287 -286 -285 -284 -283 -282 -281 -280 -279 -278 -277 -276 -275 -274 -273 -...

output:

2
304
73
29
61
292
139
48
17
99
6
5
53
93
3
91
65
29
33
306
21
24
17
21
281
12
16
1
33
7
18
96
7
40
39
13
7
46
43
16
1
72
33
16
22
5
6
189
27
1
35
107
43
34
3
27
20
21
44
56
96
36
2
27
22
30
32
6
5
105
27
37
12
58
2
21
154
17
110
57
3
7
33
15
24
94
68
25
1
14
10
4
10
2
25
39
36
33
164
11
19
181
11
3...

result:

ok 3337 numbers

Test #3:

score: 0
Accepted
time: 7ms
memory: 32464kb

input:

5000 5000 2 0
793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 86...

output:

362
82
14
234
140
5
44
136
22
43
29
96
59
23
25
61
193
22
39
39
23
53
48
76
100
58
120
24
12
106
32
48
73
63
116
16
136
10
28
15
84
30
65
1
54
15
16
70
1
95
74
14
17
20
36
254
22
29
70
172
106
2
25
8
98
35
169
16
2
2
99
10
36
40
3
69
272
170
219
12
79
26
78
100
10
167
140
70
34
17
23
21
55
10
6
17
6...

result:

ok 3313 numbers

Test #4:

score: 0
Accepted
time: 7ms
memory: 31856kb

input:

5000 5000 2 0
-456 -455 -454 -453 -452 -451 -450 -449 -448 -447 -446 -445 -444 -443 -442 -441 -440 -439 -438 -437 -436 -435 -434 -433 -432 -431 -430 -429 -428 -427 -426 -425 -424 -423 -422 -421 -420 -419 -418 -417 -416 -415 -414 -413 -412 -411 -410 -409 -408 -407 -406 -405 -404 -403 -402 -401 -400 -...

output:

8
75
80
408
385
73
37
402
338
43
11
163
3
7
80
0
339
47
384
8
10
47
162
307
30
28
36
14
27
126
271
151
4
11
11
9
92
154
2
15
28
160
205
12
59
79
114
23
22
141
7
12
31
42
120
0
34
2
167
157
76
32
20
298
47
104
76
33
49
34
1
40
16
1
28
7
4
55
14
8
68
17
7
117
1
14
14
80
44
8
45
49
65
15
49
56
50
40
14...

result:

ok 3296 numbers

Test #5:

score: 0
Accepted
time: 228ms
memory: 33336kb

input:

200000 199999 -195 -119
-267 -146 191 -456 835 265 -226 -264 160 -101 739 -988 -967 890 -753 -854 514 491 -733 662 681 -362 804 -714 -1000 -790 931 -450 212 94 239 638 400 -167 -360 18 606 256 445 695 -509 643 -892 213 -32 42 400 733 -667 -986 225 493 -699 547 409 -35 394 920 -163 -908 -576 921 -997...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 133315 numbers

Test #6:

score: 0
Accepted
time: 258ms
memory: 33348kb

input:

200000 200000 -847 -858
977 -248 439 -318 -623 -838 -996 484 415 -888 550 940 -880 -224 95 666 -898 -36 922 346 538 858 619 771 234 909 182 -577 -399 -793 -217 -150 -805 -22 -35 -818 342 -469 -620 778 855 -156 699 464 923 935 -824 315 -156 -222 55 282 -800 -542 192 -358 -158 79 259 -57 842 -882 -690...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 133062 numbers

Test #7:

score: 0
Accepted
time: 226ms
memory: 33332kb

input:

199994 199991 -131 936
-384 633 390 191 -647 79 -481 -95 -719 -131 -225 654 392 -232 390 -520 671 440 814 95 945 -854 477 304 -29 -884 -823 -798 -386 -404 614 -875 -792 -630 875 -379 -412 -464 805 -749 952 -737 -765 -36 295 -20 571 419 -519 763 505 803 -14 307 -979 955 743 -210 159 935 499 13 -750 -...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 133017 numbers

Test #8:

score: 0
Accepted
time: 555ms
memory: 33404kb

input:

200000 200000 448 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

output:

5388
1796
9803
17353
10388
6660
29833
1132
10416
3492
28995
2953
5964
9845
4293
158
931
30
224
7765
7894
2412
21159
21128
8630
4778
3830
1241
3750
795
5013
529
2176
2266
566
194
2702
4520
2348
1577
6922
372
895
667
650
5530
8798
670
2806
2395
1525
4602
1558
1278
1635
5413
2804
1167
731
3000
1663
529...

result:

ok 79952 numbers

Test #9:

score: 0
Accepted
time: 790ms
memory: 32884kb

input:

100000 100000 2 0
-866 890 -406 10 512 859 494 362 -955 -475 128 553 -986 -885 763 77 449 310 787 -656 -204 -709 -270 76 -267 184 170 -985 33 -822 666 418 26 -247 898 -104 85 -146 980 631 359 908 -560 -744 -764 836 -103 -531 -116 316 681 -148 226 206 -439 -961 -792 598 -629 -705 -479 -494 -169 608 -...

output:

5945
19533
15508
14075
35558
23781
46506
34124
44894
32242
34480
43972
45792
39812
30588
7998
25358
22005
11197
3273
43673
14284
5162
25652
32519
16639
7967
34906
3142
24285
20597
39451
13542
33435
0
34534
39229
7380
45632
11415
30503
29542
7808
18077
18828
87
32329
44233
34055
21021
41973
33289
799...

result:

ok 99900 numbers

Test #10:

score: 0
Accepted
time: 1905ms
memory: 33280kb

input:

200000 200000 2 0
-866 890 -406 10 512 859 494 362 -955 -475 128 553 -986 -885 763 77 449 310 787 -656 -204 -709 -270 76 -267 184 170 -985 33 -822 666 418 26 -247 898 -104 85 -146 980 631 359 908 -560 -744 -764 836 -103 -531 -116 316 681 -148 226 206 -439 -961 -792 598 -629 -705 -479 -494 -169 608 -...

output:

5945
19533
79394
80827
35558
71121
46506
34124
44894
32242
34480
43972
49110
55090
30588
86904
69544
72897
11197
91629
43673
80618
5162
69250
32519
78263
86935
59996
3142
24285
20597
55451
81360
61467
96742
60368
55673
87522
45632
83487
30503
65360
7808
18077
76074
87
62573
44233
34055
21021
41973
3...

result:

ok 199800 numbers

Extra Test:

score: 0
Extra Test Passed