QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#74331#5441. Quartz CollectionchenshiAC ✓139ms25788kbC++1.4kb2023-01-31 17:55:542023-01-31 17:55:57

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-01-31 17:55:57]
  • 评测
  • 测评结果:AC
  • 用时:139ms
  • 内存:25788kb
  • [2023-01-31 17:55:54]
  • 提交

answer

#include<cstdio>
using namespace std;
const int E=1e5,o=5e5;
int n,m,a[o],b[o],c1[o],c2[o];long long ans,s1[o][4],s2[o][2];
void modify1(int id,int pos,int val,int l=0,int r=E){
	if(l==r){
		c1[id]+=val;
		for(int i=0,j=c1[id]/4,k=c1[id]%4;i<4;++i) s1[id][i]=(j+(i<k))*1ll*pos;
		return;
	}
	int md=l+r>>1;
	if(pos<=md) modify1(id<<1,pos,val,l,md);
	else modify1((id<<1)|1,pos,val,md+1,r);
	c1[id]=c1[id<<1]+c1[(id<<1)|1];
	for(int i=0,j=c1[id<<1]%4;i<4;++i) s1[id][i]=s1[id<<1][i]+s1[(id<<1)|1][(i+4-j)%4];
}
void modify2(int id,int pos,int val,int l=0,int r=E){
	if(l==r){
		c2[id]+=val;
		for(int i=0,j=c2[id]/2,k=c2[id]%2;i<2;++i) s2[id][i]=(j+(i<k))*1ll*pos;
		return;
	}
	int md=l+r>>1;
	if(pos<=md) modify2(id<<1,pos,val,l,md);
	else modify2((id<<1)|1,pos,val,md+1,r);
	c2[id]=c2[id<<1]+c2[(id<<1)|1];
	for(int i=0,j=c2[id<<1]%2;i<2;++i) s2[id][i]=s2[id<<1][i]+s2[(id<<1)|1][(i+2-j)%2];
}
inline void ins(int a,int b,int coef){
	if(a<b) modify1(1,a-b+E,coef);
	else modify2(1,a-b,coef);
	ans+=b*coef;
}
inline void slv(){
	long long res=ans+s1[1][0]+s1[1][3]-E*1ll*(c1[1]/4*2+!!(c1[1]%4));
	if(c1[1]&1) res+=s2[1][1];
	else res+=s2[1][0];
	printf("%lld\n",res);
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i) scanf("%d%d",&a[i],&b[i]),ins(a[i],b[i],1);
	slv();
	for(int t,x,y;m--;slv()) scanf("%d%d%d",&t,&x,&y),ins(a[t],b[t],-1),ins(a[t]=x,b[t]=y,1);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

13
14
15
14
10
13

result:

ok 6 numbers

Test #2:

score: 0
Accepted
time: 0ms
memory: 5736kb

input:

1 1
1 1
1 1 1

output:

1
1

result:

ok 2 number(s): "1 1"

Test #3:

score: 0
Accepted
time: 0ms
memory: 18012kb

input:

100 100
6 7
100 8
5 61
5 75
59 65
51 47
83 37
34 54
87 46
4 26
21 87
12 97
86 68
60 11
62 76
14 83
29 31
91 62
57 80
47 75
85 97
62 77
91 86
14 25
48 77
83 65
39 61
78 77
45 46
90 74
100 91
86 98
55 5
84 42
91 69
100 4
74 98
60 37
75 44
41 12
15 34
36 1
99 16
7 87
36 26
79 42
41 84
17 98
72 16
38 55...

output:

5109
5065
5060
5007
4975
4993
4950
4928
4922
4930
4948
4915
4885
4863
4898
4864
4837
4787
4793
4774
4730
4708
4659
4617
4546
4618
4654
4687
4677
4685
4714
4733
4728
4701
4660
4631
4628
4682
4743
4777
4764
4772
4754
4759
4715
4744
4672
4687
4700
4649
4611
4543
4523
4554
4605
4585
4532
4520
4489
4505
...

result:

ok 101 numbers

Test #4:

score: 0
Accepted
time: 0ms
memory: 20056kb

input:

1000 1000
411 789
753 186
495 203
417 324
490 424
195 480
314 23
663 218
12 747
124 390
134 38
218 536
291 840
174 908
474 767
313 167
575 9
857 427
313 27
959 935
258 70
472 957
747 228
205 939
293 303
626 802
712 283
658 346
208 383
889 204
99 640
801 966
828 742
534 11
259 734
226 129
843 350
50 ...

output:

490601
490340
490353
490689
490697
490600
490571
491078
491388
491507
491729
491809
491984
492228
492161
492171
492384
492276
492693
492547
492372
492580
492350
492795
492635
492941
492936
492797
492359
492108
492670
492589
492570
492700
492910
492401
492274
492263
491905
491692
492032
492168
492350...

result:

ok 1001 numbers

Test #5:

score: 0
Accepted
time: 3ms
memory: 22016kb

input:

5000 1000
72520 61541
4609 95655
27768 67682
48763 4836
63868 3082
44496 5022
70138 88832
25864 48681
5212 79532
1134 60190
84561 98392
91027 55707
72938 83316
60044 93249
82269 88819
83951 6069
35302 29132
1882 68479
3489 45817
79436 37261
88849 763
23786 62641
89532 32244
85372 46815
6765 56651
27...

output:

249456797
249463957
249477751
249431759
249421636
249444892
249421159
249434259
249445362
249448397
249505520
249532943
249538838
249493562
249475570
249507883
249503390
249512573
249524766
249475431
249511948
249496484
249455533
249428931
249385128
249380512
249370595
249390331
249422343
249398748
...

result:

ok 1001 numbers

Test #6:

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

input:

4990 1000
28197 37778
70449 79157
73746 9790
57859 34774
60067 24125
4809 99133
51444 84059
21094 41904
63475 27833
23189 61130
3203 19272
87649 64152
92473 74674
85227 38234
55074 55761
80744 89480
23995 39894
49024 88746
57815 10851
10032 29151
9757 78417
77993 19383
39272 26155
39279 69209
64005 ...

output:

250090553
250118970
250123190
250148475
250125939
250104267
250093819
250095617
250069068
250084722
250077812
250113699
250078954
250113860
250175483
250182518
250204543
250223709
250264020
250312567
250359944
250405159
250405818
250426052
250472672
250505450
250530824
250554819
250565666
250535021
...

result:

ok 1001 numbers

Test #7:

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

input:

4991 1000
39678 1249
54437 46017
45224 70229
17603 34864
29604 94448
85430 12263
55898 14782
85335 5653
87061 43854
64868 7691
89219 13493
36702 86976
59640 93900
95498 13230
31210 90574
51152 91506
21366 27131
6431 61743
75930 9336
44487 87340
70841 92525
2237 10001
35034 39269
15226 49198
30121 79...

output:

251570351
251589172
251538274
251520847
251547567
251518079
251492735
251519194
251505737
251483325
251462868
251443905
251469527
251466065
251440294
251390410
251368713
251377575
251395027
251339405
251359785
251351536
251300033
251339703
251323391
251335851
251351155
251372302
251421798
251435651
...

result:

ok 1001 numbers

Test #8:

score: 0
Accepted
time: 2ms
memory: 20548kb

input:

4992 1000
18454 5936
5721 80172
82110 63373
77346 34954
88742 64771
33347 84178
3457 12800
58088 93594
34839 51363
39251 21548
32131 7715
94267 68584
26806 70022
14280 98625
74643 59979
13048 58940
75633 14369
63838 45140
61340 75117
68541 45528
56117 72040
93777 67915
20397 60895
34278 96484
37454 ...

output:

249618219
249654234
249683165
249682436
249677245
249628244
249704005
249718772
249748178
249768835
249796157
249823793
249843763
249886481
249909282
249917273
249905042
249881567
249839421
249856597
249875790
249876920
249906243
249961596
249989304
249974693
250004114
250012548
249987610
249979537
...

result:

ok 1001 numbers

Test #9:

score: 0
Accepted
time: 4ms
memory: 20568kb

input:

4993 1000
88719 77920
22413 47032
86292 23812
80194 35044
58279 59286
81264 31900
7911 43522
22329 57342
82616 26169
80931 68109
75043 69232
86424 82897
26676 89248
91846 8212
50779 18984
16161 93669
73004 1607
29756 85433
55263 16706
2996 79525
49904 86148
85317 58533
16160 41305
53330 19577
3570 8...

output:

246937375
246902933
246853357
246792693
246780301
246751075
246825290
246808981
246757941
246700396
246689981
246659903
246680998
246686398
246683731
246711512
246674588
246685355
246694572
246685122
246702201
246726695
246773376
246786648
246799704
246842226
246836993
246822308
246882236
246863694
...

result:

ok 1001 numbers

Test #10:

score: 0
Accepted
time: 0ms
memory: 24968kb

input:

4994 1000
67496 74095
73697 13891
57771 51548
7233 67839
84712 29609
53373 3815
55469 41540
19273 53795
38906 33678
79506 81966
61060 63453
35477 40313
26547 75771
77925 50503
94211 53796
78057 28399
3079 21548
19867 34238
40673 15191
37450 70418
10988 41471
9561 92255
68819 87122
96574 66862
35094 ...

output:

250146657
250191612
250195029
250208340
250228083
250219002
250250939
250219227
250218163
250182743
250167412
250166327
250166020
250164878
250209768
250195909
250220011
250240657
250222778
250205951
250238241
250204887
250258586
250265300
250301197
250314111
250293524
250350986
250335842
250379917
...

result:

ok 1001 numbers

Test #11:

score: 0
Accepted
time: 0ms
memory: 24224kb

input:

4995 1000
46273 46078
14581 48047
94657 44692
66977 67929
54249 91420
1290 84241
35731 72262
59322 41735
86684 16995
21185 95823
71268 24970
93042 87329
2225 19189
88195 60090
70348 55905
48465 63129
65858 76082
77274 74530
58788 13676
4608 4414
4775 55579
33805 82873
97285 236
15626 22659
42427 614...

output:

249123929
249093890
249059513
249098346
249091966
249074062
249112865
249070493
249136701
249170937
249165833
249145343
249113654
249135553
249132265
249084428
249044429
249077502
249092360
249059652
249050111
249036494
249017935
249049640
249058877
249093975
249096337
249071045
249068168
249051003
...

result:

ok 1001 numbers

Test #12:

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

input:

4996 1000
16538 42254
98569 82202
98839 5131
26721 43827
80683 94447
49207 88859
74778 2984
56267 5484
34461 24505
95568 42384
81476 19191
17903 44746
2095 38415
74274 10893
13780 90718
43065 30563
63229 63319
10488 90631
52710 46753
39063 62603
65859 2390
92641 73491
49944 80646
34677 37240
8543 87...

output:

248960238
248974054
248942836
248973067
249005101
249032200
249070300
249023442
249014743
249040593
248989635
249009916
249027265
249058576
249072632
249119208
249134856
249110250
249119365
249101880
249118578
249135024
249129082
249112553
249097813
249099441
249075722
249122221
249167209
249124563
...

result:

ok 1001 numbers

Test #13:

score: 0
Accepted
time: 0ms
memory: 24380kb

input:

4997 1000
95314 14237
82557 92165
70317 98275
62272 76621
50220 56258
29828 36582
55040 1002
53212 69232
25343 32014
69952 56241
196 46116
34252 59058
69261 57641
84544 20480
89916 84315
13473 32588
93304 83261
67895 30924
38121 21046
73517 20792
51135 49202
16885 31405
78411 26463
10625 17230
15875...

output:

248626297
248613939
248567045
248594344
248588529
248587231
248571746
248596543
248570088
248573785
248581628
248586152
248578111
248555444
248557689
248551497
248566226
248600610
248636341
248624337
248597114
248596593
248618465
248659598
248710238
248648153
248637681
248620564
248636262
248652238
...

result:

ok 1001 numbers

Test #14:

score: 0
Accepted
time: 3ms
memory: 24208kb

input:

4998 1000
41387 10412
66545 59025
7204 34522
89312 76712
76653 26581
77745 84304
59494 31724
93260 89877
73121 6819
44335 2802
10405 7634
91817 81882
69132 1059
70623 30067
645 19128
75369 22
23378 70498
58006 47025
56235 19531
40676 54789
12218 96014
41129 22023
31069 15385
96973 7619
81992 40146
8...

output:

248167056
248170683
248161396
248134284
248108135
248131832
248080090
248110775
248064774
248033559
248022206
248052437
248031002
248079532
248091063
248135564
248167430
248219697
248262214
248272959
248273463
248270090
248273632
248257206
248234046
248274987
248277803
248294237
248340004
248353679
...

result:

ok 1001 numbers

Test #15:

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

input:

4999 1000
44356 15100
83237 93180
11386 94962
49056 44098
3086 96904
49854 56219
7052 29742
90205 53625
53603 22840
10206 16659
20613 1855
16677 63491
69002 87581
48189 48166
76781 53940
78481 58944
20749 90440
91220 87317
17454 52608
99322 12977
73302 42825
99965 55745
83728 28499
48729 87608
89324...

output:

249659526
249669312
249691503
249687933
249735478
249694821
249641458
249636823
249619568
249661165
249717066
249762849
249817230
249843562
249865872
249832944
249833793
249831858
249838575
249825250
249783234
249793875
249829814
249789169
249771971
249736711
249750218
249710441
249729641
249701702
...

result:

ok 1001 numbers

Test #16:

score: 0
Accepted
time: 113ms
memory: 25788kb

input:

99990 100000
8407 13171
34685 59100
61849 69684
27699 69734
15978 26396
67189 48485
92204 59033
29990 22522
58882 34685
80298 84456
15797 82715
78860 25748
96625 15087
36123 619
67877 30227
59945 31836
7463 67915
7979 11738
95566 22650
71867 9819
21942 63371
77017 37019
57183 61513
79366 34554
78286...

output:

4991148739
4991089812
4991092875
4991120515
4991145017
4991141793
4991205241
4991214514
4991163152
4991137504
4991164614
4991194001
4991228078
4991239695
4991215421
4991172464
4991178820
4991195692
4991251464
4991234240
4991239700
4991233576
4991249090
4991300781
4991320002
4991316854
4991320339
499...

result:

ok 100001 numbers

Test #17:

score: 0
Accepted
time: 110ms
memory: 21960kb

input:

99991 100000
80391 64455
68840 63282
54992 29427
3597 39271
86301 74313
39104 20236
55630 31786
26442 70300
99095 9068
26859 94664
42722 31768
1685 25619
15851 58061
78414 11348
94178 24828
94675 94615
94700 1130
80976 5660
37155 57105
38568 70903
1457 87615
67635 32782
37593 13269
59355 33374
71183...

output:

5003682418
5003702158
5003689127
5003702786
5003689752
5003693329
5003702527
5003684675
5003648134
5003642089
5003641027
5003599559
5003541024
5003554512
5003551905
5003544455
5003560362
5003556101
5003570156
5003616070
5003626265
5003632872
5003650209
5003628373
5003661680
5003640506
5003638550
500...

result:

ok 100001 numbers

Test #18:

score: 0
Accepted
time: 133ms
memory: 24700kb

input:

99992 100000
76566 48443
35699 168
15432 32275
36392 65704
80816 22230
86826 498
53648 96027
90191 93886
82413 50747
40716 80680
4239 56629
15997 68593
35077 44140
96514 87484
96287 95236
62108 91986
49234 58536
21268 91071
35640 24263
96757 56178
91373 11858
25549 85441
83411 56512
82448 8003
31375...

output:

4998691389
4998689927
4998700745
4998702081
4998712887
4998740305
4998712174
4998737286
4998735662
4998756123
4998755525
4998766962
4998777373
4998748110
4998819947
4998809353
4998751222
4998698282
4998647563
4998640489
4998652736
4998617877
4998640628
4998667344
4998705688
4998765005
4998737906
499...

result:

ok 100001 numbers

Test #19:

score: 0
Accepted
time: 120ms
memory: 22232kb

input:

99993 100000
81253 65135
45663 71647
8575 92019
36482 35241
51139 94339
58741 39544
51666 92971
78131 41664
89922 49322
87277 90888
98460 81490
73414 68463
78495 21706
6101 30916
31100 57132
64134 22061
69176 48647
37369 9185
1421 58718
54946 49966
70888 94886
16167 13908
96525 75564
29733 6823
2427...

output:

4996661413
4996680642
4996662107
4996652755
4996676909
4996687855
4996625959
4996635163
4996643281
4996693902
4996651957
4996640362
4996663270
4996636052
4996638447
4996629215
4996646024
4996659979
4996648170
4996601367
4996576313
4996575172
4996564428
4996592192
4996600453
4996580210
4996610982
499...

result:

ok 100001 numbers

Test #20:

score: 0
Accepted
time: 120ms
memory: 24292kb

input:

99994 100000
44725 40611
79818 75829
69015 51762
36572 61675
21462 42256
71871 19806
82388 33020
41880 89441
97431 23706
1134 33801
92681 30543
87726 68333
97721 7784
15688 7053
57400 60244
31568 52136
56413 81862
77662 70404
43010 93172
88942 78345
84996 19130
74081 66566
85446 94616
52826 81451
84...

output:

5004161248
5004140726
5004170104
5004126140
5004113937
5004104535
5004059041
5004090766
5004127214
5004116322
5004166595
5004146637
5004174871
5004161610
5004132031
5004146361
5004124209
5004167166
5004201073
5004185801
5004230520
5004262064
5004215885
5004197662
5004187872
5004192375
5004205509
500...

result:

ok 100001 numbers

Test #21:

score: 0
Accepted
time: 129ms
memory: 23516kb

input:

99995 100000
16708 57303
46678 12715
5262 11506
69366 31212
15977 90173
43786 91557
80406 29965
38332 13027
72236 65385
47695 19817
54199 55404
2038 68204
84243 50759
57979 50485
92213 22140
33594 49507
43651 71972
93763 88518
41495 60331
47131 72133
64512 43374
7803 95033
98560 70564
112 80272
1006...

output:

4996089673
4996042531
4996104096
4996113972
4996117759
4996122194
4996121881
4996102490
4996072841
4996050832
4996051567
4996040766
4996069154
4996084454
4996101451
4996107072
4996081604
4996089153
4996057986
4996094535
4996089473
4996128255
4996160922
4996187003
4996200745
4996220186
4996285719
499...

result:

ok 100001 numbers

Test #22:

score: 0
Accepted
time: 129ms
memory: 24836kb

input:

99996 100000
21395 41291
80833 16897
65702 14354
69457 90349
86300 38090
91508 71819
11128 70014
26273 93509
55554 39768
61552 30025
48420 80265
92159 35370
27661 28325
76078 26621
94322 92548
1027 79582
30888 29379
34055 82441
39980 94785
5320 33217
78619 2210
98421 47692
44378 89616
47397 54900
70...

output:

4998163594
4998206490
4998167194
4998155727
4998178840
4998130983
4998118810
4998141052
4998129697
4998168420
4998146324
4998190690
4998180957
4998156908
4998198162
4998228337
4998227734
4998265383
4998221221
4998175691
4998140027
4998181649
4998152999
4998140349
4998126386
4998097007
4998072873
499...

result:

ok 100001 numbers

Test #23:

score: 0
Accepted
time: 130ms
memory: 24580kb

input:

99997 100000
84867 25279
47693 88376
26142 74097
36843 59886
80815 86007
63422 43569
41850 34255
90021 41287
63063 81447
75409 40233
42641 29318
73767 35240
46888 14404
85665 70054
96431 87149
68461 9657
18126 62594
82860 67851
73057 53431
39316 51196
25431 26454
56335 76158
57491 8667
3194 86424
63...

output:

5003164121
5003194321
5003242191
5003253178
5003197982
5003208541
5003200355
5003150812
5003170867
5003145138
5003114453
5003117907
5003128130
5003133409
5003092314
5003125397
5003104777
5003083769
5003096789
5003082383
5003108052
5003100983
5003144295
5003149408
5003116116
5003122743
5003130917
500...

result:

ok 100001 numbers

Test #24:

score: 0
Accepted
time: 139ms
memory: 20948kb

input:

99998 100000
89554 9267
14552 25262
19285 33841
45445 86320
18434 58117
11145 23831
39868 31199
53770 32168
70572 80022
46162 91658
4158 86883
96591 35111
90306 24674
27956 46190
55436 57557
94679 39731
81171 52704
23153 85966
47350 20590
30209 12280
72242 50698
46953 28817
37901 84615
17775 52541
2...

output:

5017002479
5017009870
5017037801
5017046625
5017075822
5017090048
5017107824
5017138832
5017104460
5017085284
5017068299
5017118178
5017110842
5017067923
5017063262
5017090059
5017139667
5017172237
5017146787
5017128763
5017159974
5017183919
5017203188
5017219703
5017267829
5017267695
5017289845
501...

result:

ok 100001 numbers

Test #25:

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

input:

99999 100000
85729 93256
48708 29444
79725 93585
45535 55857
45653 6034
91571 95582
70590 71248
50222 79946
10786 21702
60019 1866
98379 79040
10904 2277
9532 10752
13351 56919
57544 19453
62112 69806
1113 85919
6550 47184
45834 55044
64206 73363
19054 9534
4867 24580
83719 70963
73573 59873
92047 4...

output:

4999191241
4999181445
4999202206
4999159224
4999204651
4999197791
4999182676
4999142024
4999119931
4999092938
4999093131
4999087582
4999073421
4999078388
4999058825
4999065835
4999039690
4998964644
4998991515
4999037784
4999013856
4999007167
4998980918
4998987114
4998965439
4998987143
4999032960
499...

result:

ok 100001 numbers

Test #26:

score: 0
Accepted
time: 122ms
memory: 23036kb

input:

100000 100000
4504 71406
42976 15993
95768 68246
55117 56353
93191 1080
30542 39427
11305 5044
3431 39470
96578 10603
15393 5945
98878 47366
22536 8701
46442 30223
35020 21462
64824 23702
3841 97477
81696 27085
4511 88753
33753 59085
2978 58497
12740 58991
41803 75299
16290 51924
93949 52841
99033 6...

output:

4996260099
4996268532
4996248317
4996209301
4996174062
4996180699
4996131727
4996094838
4996154074
4996154438
4996153862
4996193301
4996213289
4996202783
4996186213
4996162664
4996191105
4996179561
4996199127
4996236946
4996234712
4996238703
4996194594
4996169929
4996157811
4996155449
4996165442
499...

result:

ok 100001 numbers