QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#789458#9634. 序列grass8cow40 1551ms156604kbC++172.5kb2024-11-27 20:25:372024-11-27 20:25:45

Judging History

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

  • [2024-11-27 20:25:45]
  • 评测
  • 测评结果:40
  • 用时:1551ms
  • 内存:156604kb
  • [2024-11-27 20:25:37]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int n;
#define pi pair<int,int>
const int N=5e5+10;
#define pb push_back
#define pi pair<int,int>
#define fi first
#define se second
vector<pi>G[N],H[N],Q[N];int a[N],q;
#define ll long long
ll ans[N];
ll sb[N<<2],s1[N<<2],s2[N<<2],mi[N<<2],mi2[N<<2],t1[N<<2],t2[N<<2],t3[N<<2];
//t1:把 max 都改成 t2 
//t2:b+=a*t1
//t3:对于mx的位置, b+=t3
void sc(int p){
    int l=(p<<1),r=(p<<1|1);
    mi[p]=min(mi[l],mi[r]),mi2[p]=min(mi2[l],mi2[r]);
    if(mi[l]!=mi[r])mi2[p]=min(mi2[p],max(mi[l],mi[r]));
    sb[p]=sb[l]+sb[r],s1[p]=s2[p]=0;
    for(int o=0;o<2;o++){
        if(mi[l]<=mi[r])s1[p]+=s1[l],s2[p]+=s2[l];
        else s1[p]+=s1[l]+mi[l]*s2[l];
        swap(l,r);
    }
}
void uc(int p,ll z1,ll z2,ll z3){
    sb[p]+=s1[p]*z2+s2[p]*z3;
    if(z1)mi[p]=z1,t1[p]=z1;
    t2[p]+=z2,t3[p]+=z3;
}
void pd(int p){
    int l=(p<<1),r=(p<<1|1);
    for(int o=0;o<2;o++){
        if(mi[l]<=mi[r])
            uc(l,t1[p],t2[p],t3[p]);
        else 
            uc(l,0,t2[p],t2[p]*mi[l]);
        swap(l,r);
    }
    t1[p]=t2[p]=t3[p]=0;
}
ll ask(int p,int l,int r,int x){
    if(l==r)return sb[p];
    pd(p);int mid=(l+r)>>1;
    if(x<=mid)return ask(p<<1,l,mid,x);
    return sb[p<<1]+ask(p<<1|1,mid+1,r,x);
}
void up(int p,int l,int r,int x,int y,int z){
    if(mi[p]>=z)return;
    if(x<=l&&r<=y&&z<mi2[p])return uc(p,z,0,0);
    pd(p);int mid=(l+r)>>1;
    if(x<=mid)up(p<<1,l,mid,x,y,z);
    if(y>mid)up(p<<1|1,mid+1,r,x,y,z);
    sc(p);
}
void up2(int p,int l,int r,int x,int z){
    if(l==r){
        mi[p]=0,mi2[p]=1e9+7;
        s1[p]=0,s2[p]=z;
        return;
    }
    pd(p);int mid=(l+r)>>1;
    if(x<=mid)up2(p<<1,l,mid,x,z);
    else up2(p<<1|1,mid+1,r,x,z);
    sc(p);
}
bool aq[N];
int main(){
    int q;
    scanf("%d%d",&n,&q);
    for(int i=1,x;i<=n;i++)scanf("%d",&x),G[i].pb({x,1});
    for(int i=1,op,x,y;i<=q;i++){
        scanf("%d%d%d",&op,&x,&y);
        if(op==1)G[x].pb({y,i+1});
        if(op==2)H[x].pb({i,1}),H[y+1].pb({i,0});
        if(op==3)Q[x-1].pb({i,-1}),Q[y].pb({i,1}),aq[i]=1;
    }
    for(int i=1;i<=q*4;i++)mi2[i]=1e9+7;
    for(int i=1;i<=n;i++){
        for(pi o:H[i])up2(1,1,q,o.fi,o.se);
        int sz=G[i].size();
        for(int j=0;j<sz;j++)if(G[i][j].se<=q)
        up(1,1,q,G[i][j].se,((j!=sz-1)?(G[i][j+1].se-1):q),G[i][j].fi);
        uc(1,0,1,mi[1]);
        for(pi o:Q[i])
        ans[o.fi]+=ask(1,1,q,o.fi)*o.se;
    }
    for(int i=1;i<=q;i++)if(aq[i])printf("%lld\n",ans[i]);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 5
Accepted

Test #1:

score: 5
Accepted
time: 3ms
memory: 45396kb

input:

1000 1000
200255705 18851142 736009342 406246331 351992319 749189355 944184790 785599293 530084396 616825582 73892135 176401717 973078957 225462579 140426746 324124972 229974996 750749128 879242920 854856469 515750108 662437499 10800517 96488944 534239216 379225718 1241451 150390174 183892560 613018...

output:

115323323048
65823230682
0
47168872319
60782985614
348599053983
918484726470
208925010382
841530027736
1163442457471
2608439690799
2128414546126
2471685184070
2278023608377
4122371223088
1458343349705
62968981524
4425943072510
5286986186209
537921635417
6006016656637
6374912810574
4556755081981
4090...

result:

ok 319 lines

Test #2:

score: 5
Accepted
time: 8ms
memory: 45788kb

input:

675 498
75499042 789966903 502155346 54108007 467143562 114588937 94686746 295185255 554039744 259329427 158379833 138282372 561461541 957169421 692456397 450721274 101897728 872864525 297269606 128259204 146200569 334256573 638122576 708088255 258863311 783805088 186494595 159493286 860425671 36583...

output:

3210556218
191560004083
104947218282
135015954140
89106128730
315174748560
850455290830
215793984626
105038927720
671668276124
293473436208
1370960719682
307802923002
1044297322034
471948015606
1812945110331
509687537766
877665782562
5988747959725
2402086669705
665467763330
3875485682146
30788930819...

result:

ok 157 lines

Test #3:

score: 5
Accepted
time: 3ms
memory: 47332kb

input:

832 956
63423286 492662095 483038836 43381328 710704754 275209586 772971912 639125432 123099101 440862460 183294225 125906357 452957650 331299449 449896214 12572018 605185437 64801748 40959720 490409349 609153090 532014716 503601695 886231182 433385802 11363084 17467752 140921783 203238927 515442553...

output:

159703328433
728165156759
460962189958
139692978146
459083548685
2010218005483
160646809572
1998558719788
2532122916025
208715188685
3433514558392
1245744189229
2304867462814
1101186845031
4646172459091
3539374659926
2219710349880
2981467606232
1639756233272
3123456308009
129830992916
2707661776087
...

result:

ok 298 lines

Test #4:

score: 5
Accepted
time: 4ms
memory: 46492kb

input:

107 458
539936263 550880224 110849701 171862479 40453865 42606847 118258420 901511714 62978713 994457516 790180985 231543035 67333164 220103435 863166805 693458691 735393617 656359198 456294870 483207020 36257117 51902430 86590102 656792972 473981545 132412739 956528165 655526259 389318494 722510414...

output:

37703321582
61151152486
38167350208
27335153157
13391394310
39026827445
9471505258
132653861927
53752862940
55529822900
30680946663
4850841785
63192296538
51576868617
68746826458
72693752015
9960381094
54341149280
153650643409
85423704752
30991460260
76087303259
206268124856
210773791402
16018411054...

result:

ok 147 lines

Test #5:

score: 5
Accepted
time: 8ms
memory: 47080kb

input:

933 247
290494705 534765936 691140472 652599148 796414457 950767936 884921919 736175995 398100604 985864598 604544799 325091836 100139758 78534816 237456204 966229805 77069564 843105831 62870326 241741343 997490857 25434019 587844838 826260504 87495532 783942134 938382330 817416196 861328912 8872012...

output:

527080492570
170522861753
35492358564
1118019649402
1245650784268
517846428173
157238640740
64050364170
1165387164835
797344988879
905518201748
585830293577
1469275121374
2090399342887
993895826760
563204905613
2275566746139
891332495993
510813367529
3220707417878
4014471703279
1232981799608
1788988...

result:

ok 88 lines

Subtask #2:

score: 15
Accepted

Test #6:

score: 15
Accepted
time: 176ms
memory: 76164kb

input:

100000 100000
4637 12023 22485 24887 33065 35780 37538 49402 71281 72891 82706 82752 91276 108256 240372831 135259 144119 527163065 139510686 183411 214260 269767144 246850 265137 200716505 279533 283217 309516 310867 466875375 322790 328304 352577 362081 368658 370430 393854 410075 413844 417924 42...

output:

0
30726293751614
23279151095632
41852587040702
88334302224542
55145178872681
133708315362378
122479400900129
51466277782595
118512887868405
11037534475440
65035924904178
10603452209550
199208093593954
265893836606312
214479670680947
204140164589562
309440794035363
371664753856955
431192829952188
223...

result:

ok 33171 lines

Test #7:

score: 15
Accepted
time: 161ms
memory: 78028kb

input:

100000 100000
19723 39392 45074 51502 53631 57384 62795 83715 87504 89050 841832193 866044146 107373 108026 345025215 112030 116974 122686 123235 148805 149471 956007390 165128 786395423 169262 171279 178785 179135 179363 180975 182200 187213 212008 217112 218394 221491 233714 819427472 238361 24227...

output:

0
32124614467875
69730586575982
15351815760648
39463147851339
16268178614557
303342370917063
346244985109518
292833305376516
352153160757784
158244261040178
599241224673877
67404589393329
432694296417372
124742290707994
314297538152335
495171088283939
417004525148234
143916527742938
338939254812923
...

result:

ok 33331 lines

Test #8:

score: 15
Accepted
time: 228ms
memory: 71968kb

input:

100000 100000
2908 10473 29474 35649 40424 46783 50041 68445 81098 96582 90025 102538 128766 120910 131449 149397 169408 167938 187128 192288 196084 207953 217258 231306 247570 248623 250548 266615 274685 296144 299431 306652 323405 326332 341744 340727 363155 376283 381987 389450 398454 406178 4118...

output:

377915538139549
79386636621796
310648735973954
1115465766317781
1174759112421105
1267214610548620
144309126675820
791491017938869
790485778190958
1992438100036954
3728927904532942
3450408776333060
1148459259855542
3434668196031763
1429031077622813
4384069058754410
4712920036420316
1905079428498382
1...

result:

ok 4980 lines

Test #9:

score: 15
Accepted
time: 137ms
memory: 71920kb

input:

100000 100000
1 5416 10193 20973 43641 59111 59710 61214 83161 89367 92875 103278 120697 123362 132339 144415 150301 177312 177726 186305 198765 215887 229844 225598 243960 243968 253899 264297 270663 295463 297815 313600 322370 325050 339675 343618 366146 371128 372853 399869 392890 416762 427071 4...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
12506289774675
30993852542994
1476270298068
19859163976805
256593130788
4863792552078
36510986090424
0
8793244932194
0
27496507734929
46196387428852
10116507432109
39651727981238
9881579282058
47734322666145
9721472071510
13783772572906
49612189104874
34561802750647
709...

result:

ok 90082 lines

Test #10:

score: 15
Accepted
time: 171ms
memory: 75176kb

input:

100000 100000
1 19147 10463 34611 35980 52756 56153 69683 88615 99259 98503 116764 125535 124685 147668 148442 165440 179502 177942 189770 192749 210988 225546 239486 239605 256115 254808 277994 280096 281446 304064 310129 314591 338439 341802 353959 354678 367015 375732 388669 401837 415599 425050 ...

output:

0
0
4895336576636
24273351987479
0
29184129318917
6733439631000
0
22091734242466
0
30621121378918
9663021894490
10825012438813
16599195369255
18919747078225
70174059707617
106918147267604
162528871022197
91971637270994
110828263125883
184744551106766
39546233888866
135239194093210
136071671449847
18...

result:

ok 4885 lines

Subtask #3:

score: 20
Accepted

Test #11:

score: 20
Accepted
time: 374ms
memory: 98080kb

input:

199996 199998
5015 394604305 13416 39971157 16609 21608 24264 407389425 31670 31976 33151 38949 39093 43561 45026 52355 53865 59168 62183 64166 66110 67179 69567 78899 10409535 393971884 104797 109461 109501 114704 118658 123559 123907 130465 131312 140968 144801 146183 157067 160370 796894425 17818...

output:

124830885330445
163133190457804
21829962212270
97332810213576
143489565142015
101516391700168
11850432340486
170205236804236
447031192227296
157109166149152
992595580711424
2459784243144
90627247023452
229326680354895
929560394107059
338204574812304
609780011775761
527358703064443
385256587900185
16...

result:

ok 66818 lines

Test #12:

score: 20
Accepted
time: 448ms
memory: 99248kb

input:

199998 199999
168 3359 6105 15486 21875 25864 26468 30351 43952 43989 53793 53923 61996 63968 65630 70205 78972 81963 94601 94496 96858 109506 114092 118673 120001 125356 130839 134104 143348 141897 151011 153528 157134 164610 167357 171010 177495 186843 193531 193638 201233 202713 208183 212666 223...

output:

0
4378051270375
0
6903808423403
13362901828733
18444776076770
24372543933372
158384277197471
6735580542339
25778920050816
111413592672333
200397968479242
143113451226432
205402754231468
0
434973423866394
42704336802074
442387964318825
171170830546889
18443266342726
582023884944817
819893988905193
94...

result:

ok 66333 lines

Test #13:

score: 20
Accepted
time: 386ms
memory: 95044kb

input:

199996 199998
1 8536 12954 19783 24275 23112 27131 34314 36101 42615 48466 55598 62138 62041 66894 76298 80786 83532 94549 95266 99934 103499 106876 115843 124352 125509 131309 133329 142222 147539 148560 151511 159600 163448 171677 174052 178953 184230 188029 193110 199225 203957 211003 214530 2173...

output:

0
0
0
0
14230186293404
15014710688740
69339379467107
157959280933497
124274051765400
86841342219535
125440741040951
374686462687449
1769370913820
224600387765048
108156479666221
3476736401531
4338871624824
29506026393352
358909490712855
246444614376890
159607092663372
143268992784813
674698942075974...

result:

ok 10049 lines

Test #14:

score: 20
Accepted
time: 535ms
memory: 98148kb

input:

199999 199997
1 4065 13359 10483 20784 20157 25556 39760 41476 45884 52871 54407 55577 65959 69590 74858 81749 86436 91329 98879 97009 105999 113477 117069 116743 122114 126146 134968 141127 149818 150629 157016 159290 169139 168704 174398 182101 189350 188710 190054 195317 202111 208298 213463 2184...

output:

356664773280160
271576584537205
327103957637028
2437225740748747
424187891897923
3136989129319026
1823818488324464
2616111643348778
1096269625861496
101009675213988
4940972090515486
6514435670175637
7612523705881197
2639797844667310
4384189184591598
962636216165669
4693306475088573
9631726489351068
...

result:

ok 9919 lines

Test #15:

score: 20
Accepted
time: 299ms
memory: 101284kb

input:

199998 199996
1 487 6502 19580 16435 25298 31247 31018 40108 40947 54517 56109 57587 66623 72598 78065 75147 80358 87866 91253 103921 106603 112657 119454 115153 123264 126135 139643 142286 146464 148647 158426 160574 167320 167984 172186 184199 182075 188571 196590 201899 204304 210013 217785 21714...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
52089694319421
5136957493076
3450951990644
61850716056488
31244298493786
21509654027244
80848058425062
38845223723325
84427687790134
42434414680971
78744664386759
44358604063388
59495332272505
93887268574436
11926208216313
8042283208270
84995354850496
65164553742256
138...

result:

ok 179917 lines

Subtask #4:

score: 0
Wrong Answer

Test #16:

score: 20
Accepted
time: 899ms
memory: 153468kb

input:

499996 499997
1 2646 3802 4717 7652 9462 10048 15736 15959 17076 21684 21628 25147 26990 26023 28835 33604 34213 36006 39643 38238 40133 45193 44699 47403 48437 51742 53992 57055 56322 61353 61812 62008 67837 66136 70512 72503 72294 75169 77534 81608 80173 85831 85776 87518 89661 93233 93800 96640 9...

output:

0
0
0
0
0
105147493356021
18039314547119
60123011205734
797041402206
80680889110877
0
97607273260486
71194267494796
23670063883525
92041637115786
11373629471803
104829243846562
112256838369147
16646163554581
83634910857933
110480671764271
2174900945295
97605316257427
25997394270292
1924389041448
137...

result:

ok 450128 lines

Test #17:

score: 0
Wrong Answer
time: 1028ms
memory: 151796kb

input:

499998 499996
1 3471 2549 4182 8919 10258 11561 15179 16303 17220 20893 23445 24991 27357 26370 28731 30556 35428 37486 37835 39061 43719 43122 44729 48319 51703 50012 52147 57593 57437 61479 63875 64817 67167 67191 69596 70253 73553 76856 76030 78391 83022 82701 87998 88253 90359 92016 93464 96464 ...

output:

1293275144175713
2098057486611995
8222351022350847
17610615352954277
6318371993395498
13728539476460850
6533073631723592
14700814893017093
21018382511562240
5631782124013074
6045739759458044
32012453560709915
4647695248557350
33891352492409939
25680366630303673
30384715040873579
21745305855945815
23...

result:

wrong answer 4398th lines differ - expected: '9279427647422327013', found: '-9167316426287224603'

Subtask #5:

score: 0
Wrong Answer

Test #19:

score: 0
Wrong Answer
time: 1551ms
memory: 156604kb

input:

499999 499997
1 913 5858 7110 8076 9893 13142 12135 14769 16455 20711 22647 22330 25867 26677 28695 32280 33608 34824 39255 40515 43887 42090 46155 49082 48316 50861 55535 54485 56506 59203 61928 62076 66600 68030 69805 72680 74796 75455 79690 78235 83297 82398 85367 87069 89711 93646 92554 95923 97...

output:

103621325428465
194930859933753
353758078534853
1405031453939581
1104512586294893
480139615473767
1033865068621131
1418492876310288
1129269195811974
845644688375455
3918331221480338
4521399133967034
482692294649644
1270881159480750
2064526258912334
7779855812924988
5610050149593744
1191164601160151
...

result:

wrong answer 12671st lines differ - expected: '9252676369918254289', found: '-9194067703791297327'

Subtask #6:

score: 0
Wrong Answer

Test #23:

score: 0
Wrong Answer
time: 1252ms
memory: 154776kb

input:

500000 499997
811 680 2664 6777 6210 8794 10852 13568 17252 18119 19538 22423 23434 24510 27591 29645 31329 33806 37129 37447 40339 41361 45606 47813 47448 50532 50029 53543 54938 56738 59038 63199 62439 67323 68737 71432 71039 75469 76122 79648 80334 81276 84567 85506 89609 91503 91445 94036 97338 ...

output:

0
0
46530827437710
159760134281336
281467808921043
372576789411254
270515121922085
273418740230876
314163853033674
465151417299684
39902282964668
608644183868574
3945842783692
13545278446404
658747128786432
8688035320113
175738882065799
103795597112962
0
751662464688101
182137815371386
3400806326455...

result:

wrong answer 111431st lines differ - expected: '9261750822065135130', found: '-9184993251644416486'