QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#439663#8304. Key ProjectmoyujiangAC ✓178ms4544kbC++141.4kb2024-06-12 15:44:192024-06-12 15:44:21

Judging History

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

  • [2024-06-12 15:44:21]
  • 评测
  • 测评结果:AC
  • 用时:178ms
  • 内存:4544kb
  • [2024-06-12 15:44:19]
  • 提交

answer

#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a),i##END=(b);i<=i##END;i++)
#define Rof(i,b,a) for(int i=(b),i##END=(a);i>=i##END;i--)
#define go(u) for(int i=head[u];i;i=nxt[i])
#define ll long long
using namespace std;
inline int read(){
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
    return x*f;
}
const int N=810,M=5e4+10; 
int n,m,d[N],cnt[N];
vector<int> A[N],B[N];
ll ans;
signed main(){
	n=read(),m=read();For(i,1,n-1)d[i]=read();
	For(i,1,m){int x=read(),y=read();A[x].push_back(y);}
	For(i,1,m){int x=read(),y=read();B[x].push_back(y);}
	For(i,1,n)sort(A[i].begin(),A[i].end(),greater<int>());
	For(i,1,n)sort(B[i].begin(),B[i].end(),greater<int>());
	while(m--){
		int W=1e9,X=0,Y=0;
		int id=0,sum=1e9;
		For(i,1,n){
			if(i>1)sum+=cnt[i-1]>=0?d[i-1]:-d[i-1];
			if(!A[i].empty()&&A[i].back()<sum)sum=A[i].back(),id=i;
			if(!B[i].empty()&&sum+B[i].back()<W)W=sum+B[i].back(),X=id,Y=i;
		}id=0,sum=1e9;
		Rof(i,n,1){
			if(i<n)sum+=cnt[i]<=0?d[i]:-d[i];
			if(!A[i].empty()&&A[i].back()<sum)sum=A[i].back(),id=i;
			if(!B[i].empty()&&sum+B[i].back()<W)W=sum+B[i].back(),X=id,Y=i;
		}ans+=W;
		A[X].pop_back(),B[Y].pop_back();
		if(X<Y)For(i,X,Y-1)cnt[i]++;
		else Rof(i,X-1,Y)cnt[i]--;
		printf("%lld\n",ans);
	}
	return 0;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3916kb

input:

4 3
1 1 1
1 1
1 2
4 6
2 1
2 2
3 5

output:

3
8
20

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 1ms
memory: 3788kb

input:

50 500
118837 951904 671499 484461 639888 359339 502649 627559 5961 20812 433609 905677 200996 201161 615383 263424 151528 844324 472585 154315 741222 247963 722818 858419 386517 100125 931060 752896 865319 23063 949988 220229 897126 259228 583375 813279 112033 676073 925357 53124 394997 392593 4992...

output:

249916
1627724
4297306
7521922
11058813
14819098
18595354
22833314
27397118
32192806
38169968
44605698
51210995
57983422
65947214
73960441
82121445
90336822
99546401
109165243
119438147
129792015
140327562
150872437
161950777
173380273
185460073
198299711
211179357
224215634
237469142
251993186
2668...

result:

ok 500 lines

Test #3:

score: 0
Accepted
time: 5ms
memory: 3896kb

input:

100 5000
161024 333083 427714 106026 344162 443967 300826 786012 190136 836472 739686 718645 621258 379491 896890 853718 132289 761595 425423 238212 266456 878908 987607 383196 425157 464423 910874 113988 596436 427196 677260 53939 353039 610651 203820 412321 810742 75711 522237 749361 213154 313223...

output:

244596
673367
1114774
1653086
2235799
2859280
3550743
4328294
5111265
5970416
6833438
7698546
8596718
9537334
10673653
11841335
13117454
14432273
15830547
17278727
18734845
20229311
21782032
23362360
24997850
26692528
28391424
30147387
31907288
33748546
35691188
37645806
39609940
41609598
43629263
4...

result:

ok 5000 lines

Test #4:

score: 0
Accepted
time: 31ms
memory: 4128kb

input:

300 20000
589233 424913 26472 555010 877553 764101 539779 342418 861724 439040 459313 518843 421817 463969 416326 348384 802183 187604 666745 329607 31379 864405 383948 216216 214607 823562 806785 481248 308705 60717 10231 892503 634831 778333 229345 254773 810990 139390 203897 878093 12605 556113 7...

output:

100488
213140
349180
573842
815426
1116056
1462744
1812722
2244746
2703883
3174800
3651102
4147393
4650694
5158675
5668646
6183335
6716217
7283456
7888069
8500618
9122205
9750795
10400551
11050357
11710647
12415089
13120968
13843813
14567012
15300273
16039492
16782040
17525930
18274542
19025483
1979...

result:

ok 20000 lines

Test #5:

score: 0
Accepted
time: 117ms
memory: 4416kb

input:

500 50000
389931 323526 397980 127878 810602 175326 183833 681018 182880 117266 603325 622561 639554 107960 301053 423699 585725 728312 759747 401710 708795 716319 677907 222410 106480 693183 12062 99078 319397 27265 184818 547305 591605 673437 248572 838416 783112 514511 590199 304268 743695 152614...

output:

28948
81176
142183
274273
412436
564080
723576
907555
1106837
1312014
1542499
1776945
2029643
2293083
2564408
2845238
3127258
3429326
3734724
4077784
4422610
4769373
5120211
5471271
5829254
6193440
6559204
6925157
7299056
7676687
8055873
8443295
8835706
9228277
9633028
10040983
10449860
10867427
112...

result:

ok 50000 lines

Test #6:

score: 0
Accepted
time: 117ms
memory: 4516kb

input:

500 50000
814225 718009 509305 663885 692938 81949 338865 256208 633763 538065 610352 418799 569529 240073 343174 858775 891248 978222 901898 541225 323850 259144 910646 494961 849671 631595 295951 684765 524225 528563 429209 29451 321964 184405 921803 6456 513800 394234 893204 858219 803508 851048 ...

output:

32751
89317
166464
257082
348771
490700
648348
829128
1048079
1268375
1494342
1728593
1974587
2230719
2490912
2751796
3018462
3288633
3567772
3849039
4133945
4422081
4712826
5006032
5300689
5605787
5917468
6231159
6553893
6879972
7225427
7587043
7954449
8323543
8693476
9063928
9452161
9842002
102336...

result:

ok 50000 lines

Test #7:

score: 0
Accepted
time: 114ms
memory: 4416kb

input:

500 50000
297562 973909 125150 594402 338413 800413 807418 507160 762601 679162 117527 20844 475754 356840 543005 70892 856074 111791 693020 842664 379999 451111 352568 516972 38094 960557 817785 653832 326000 388241 480706 997676 661863 872152 825240 622564 472444 781153 531220 657266 724498 325778...

output:

28166
61873
140869
265278
443959
623089
818253
1016724
1217343
1421306
1632243
1847700
2063786
2291906
2521700
2764826
3013266
3266487
3531216
3798951
4069988
4349099
4628951
4917513
5214365
5526450
5842545
6160755
6488215
6825410
7166464
7516286
7889086
8264302
8645444
9036030
9428791
9827768
10232...

result:

ok 50000 lines

Test #8:

score: 0
Accepted
time: 117ms
memory: 4424kb

input:

500 50000
408111 405860 980043 244502 311678 482866 300809 331874 724233 686311 305918 921260 327868 264944 224337 60710 593865 827670 626005 558689 715008 629254 291239 622999 57298 716794 670939 203622 748638 54966 498570 206475 563919 824272 225928 601663 486714 340463 817279 395076 532063 800143...

output:

80084
176593
273344
375931
481391
606044
736304
909760
1086021
1262904
1452696
1652385
1857661
2063357
2273828
2486817
2704613
2927180
3153212
3385254
3625587
3873051
4123281
4384294
4686927
4998140
5310843
5638828
5967724
6302992
6652379
7023175
7404980
7787562
8182298
8577298
8991930
9407686
98253...

result:

ok 50000 lines

Test #9:

score: 0
Accepted
time: 117ms
memory: 4440kb

input:

500 50000
703208 823547 632637 178774 648651 458695 96199 358770 115928 927436 857218 361999 105219 439431 173221 420730 210746 277490 347827 223309 801169 990535 254826 891578 171302 588559 520074 848546 936074 152062 84313 777995 487205 35420 33252 911491 338044 15007 545355 157980 564896 752072 4...

output:

33529
91228
176794
266503
371225
485659
610172
737133
871818
1012054
1187727
1383936
1589771
1795652
2007656
2228517
2468727
2712610
2961785
3219731
3499027
3779450
4063079
4347539
4657775
4992805
5335755
5681509
6033314
6388252
6748720
7121845
7495911
7871061
8247465
8625010
9006086
9389592
9793528...

result:

ok 50000 lines

Test #10:

score: 0
Accepted
time: 116ms
memory: 4356kb

input:

500 50000
242856 565385 293999 248736 846080 978802 200015 927271 485007 108798 159645 350738 353068 312679 967787 507335 645006 837349 666737 670595 65293 892786 811248 115947 141849 170196 502710 517577 259465 501057 215175 524776 667409 469241 279758 997997 766812 880321 94837 296922 507701 86701...

output:

119658
350300
636153
948337
1274276
1601194
1936951
2293382
2651739
3018681
3390346
3764093
4140227
4539759
4952779
5382203
5814148
6251115
6707056
7184104
7663241
8144517
8635227
9148208
9662383
10177591
10693998
11227547
11785628
12345934
12913101
13507548
14103275
14704697
15309011
15917851
16533...

result:

ok 50000 lines

Test #11:

score: 0
Accepted
time: 117ms
memory: 4344kb

input:

500 50000
577749 638233 227810 944957 291631 749328 966268 183355 676903 352045 351182 110338 20130 108899 358625 528154 805851 357897 416383 323317 134712 536233 964667 978370 433461 222762 530571 8663 579366 417779 800918 277277 458671 507311 941817 446507 62437 134821 671478 696942 313045 340518 ...

output:

201585
423013
647933
898140
1150659
1403910
1657874
1919618
2185074
2481779
2790469
3111478
3453491
3798406
4168710
4555866
4947268
5346548
5746682
6159199
6578303
6999144
7431801
7893791
8362450
8835736
9332674
9834820
10345970
10859947
11375272
11893083
12414049
12937372
13464706
13999617
14535765...

result:

ok 50000 lines

Test #12:

score: 0
Accepted
time: 125ms
memory: 4432kb

input:

500 50000
846989 677525 266246 800710 872483 385158 331553 825780 520510 36937 968729 400727 719863 641184 442467 924187 937242 883495 498304 652449 453970 931011 845258 327213 715262 986805 286776 457557 633549 13149 562841 480631 832975 498799 583030 300537 765932 115374 379431 506531 29990 747885...

output:

46896
170227
306533
476115
664194
866647
1093472
1331033
1592250
1885105
2187056
2492006
2805528
3123271
3442209
3774854
4115333
4462024
4872223
5310397
5754583
6199081
6648609
7100903
7556668
8039890
8525513
9012905
9503495
9994426
10493485
11009974
11529810
12053166
12580317
13117772
13663544
1421...

result:

ok 50000 lines

Test #13:

score: 0
Accepted
time: 177ms
memory: 4476kb

input:

800 50000
195816 702261 727793 508750 678471 582502 801892 695529 718057 306192 796661 184810 18054 497741 566221 701627 147574 418929 140363 933541 728773 381760 323425 340457 189460 767612 521817 91118 488295 540755 63292 171093 473611 84909 369840 571102 522770 253691 503589 894919 80272 688569 9...

output:

205362
424481
653104
894721
1143070
1414191
1704397
1998203
2297415
2626510
2983010
3391164
3807935
4234249
4677880
5138813
5616666
6110195
6607191
7116780
7668111
8227039
8797038
9381740
9975908
10572845
11176888
11787691
12402069
13020474
13640783
14261114
14883764
15509249
16136846
16777544
17427...

result:

ok 50000 lines

Test #14:

score: 0
Accepted
time: 175ms
memory: 4528kb

input:

800 50000
992267 66353 775849 644788 339258 76097 770374 346947 196692 719860 818563 662674 538036 627664 546272 559063 183921 298922 676404 423968 568994 421368 303746 722081 930729 670115 199947 628395 529731 593838 847108 991579 327521 867112 358715 850121 950732 723377 855286 737272 372767 27544...

output:

156938
379959
641089
947567
1287584
1656867
2047012
2438262
2838562
3247332
3658314
4072524
4487938
4936574
5410687
5991121
6572502
7162491
7759316
8356586
8956193
9556018
10156663
10762202
11372207
11986050
12600256
13229114
13857992
14488615
15120563
15757413
16404281
17067683
17734551
18404911
19...

result:

ok 50000 lines

Test #15:

score: 0
Accepted
time: 175ms
memory: 4544kb

input:

800 50000
816989 408972 998598 98155 170177 351933 767830 29261 875968 902898 243662 192020 431797 883525 805560 987656 540970 358099 319975 642563 929782 183742 579420 909077 721838 415193 163963 883140 172787 339544 911765 318954 21671 96475 348508 991145 264110 724543 573320 602398 523076 185156 ...

output:

44128
97345
159121
222099
391517
567099
744043
944503
1176838
1435444
1727991
2031169
2336482
2654080
2982555
3315485
3653611
4010168
4390153
4781769
5178745
5577971
5978010
6382797
6788548
7195221
7620509
8049223
8489572
8932999
9378040
9836501
10299826
10764315
11236245
11709847
12183644
12664850
...

result:

ok 50000 lines

Test #16:

score: 0
Accepted
time: 178ms
memory: 4504kb

input:

800 50000
55969 526237 998151 49384 122874 235320 148032 763163 638745 859423 444986 854144 304179 396033 643506 887915 614274 333475 166027 544360 149263 325541 369122 143615 32468 574586 958521 226694 108967 647676 103326 731442 929572 367480 278011 759343 28326 528899 996910 875338 459225 369842 ...

output:

67328
172970
314138
471016
636385
825998
1021881
1224529
1465937
1716129
1978096
2240952
2519705
2810753
3138012
3480604
3823783
4187476
4552296
4943803
5341270
5744693
6155336
6570310
6988632
7407078
7836920
8271404
8711879
9153636
9604730
10064874
10528603
11002361
11484724
11988736
12512345
13060...

result:

ok 50000 lines

Test #17:

score: 0
Accepted
time: 172ms
memory: 4524kb

input:

800 50000
602676 124637 728170 410635 155459 757381 455046 709074 486647 865168 199338 362401 117919 999809 862340 603925 838275 466798 380224 118729 866154 764343 746485 719869 842305 321166 546173 6273 806186 719888 44234 49246 558116 38055 744124 661891 504485 675322 686289 551961 222391 995462 3...

output:

117962
242009
387649
537271
766125
1005584
1247416
1511929
1778391
2047773
2329940
2622309
2921488
3225850
3535067
3846074
4162361
4490675
4824932
5172830
5527185
5926988
6329118
6734127
7156053
7586534
8021001
8460592
8900771
9343474
9797177
10258617
10720191
11190595
11690915
12191633
12704560
132...

result:

ok 50000 lines

Extra Test:

score: 0
Extra Test Passed