QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#378621#8573. Slothful Secretaryucup-team3396#AC ✓3347ms69456kbC++142.6kb2024-04-06 13:47:562024-04-06 13:47:56

Judging History

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

  • [2024-04-06 13:47:56]
  • 评测
  • 测评结果:AC
  • 用时:3347ms
  • 内存:69456kb
  • [2024-04-06 13:47:56]
  • 提交

answer

#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define pii pair<ll,ll>
#define rep(i,a,b) for(ll i=(a);i<=(b);++i)
#define per(i,a,b) for(ll i=(a);i>=(b);--i)
using namespace std;
bool Mbe;
inline ll read(){
	ll x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-f;ch=getchar();}
	while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	return x*f;
}
inline void write(ll x){
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);
	putchar(x%10+'0');
}
const ll N=5e5+9;
ll n,q,tr[N<<2],mn[N<<2],tag[N<<2],deg[N];
void Pushup(ll x){
	mn[x]=min(mn[x<<1],mn[x<<1|1]);
	tr[x]=0;
	if(mn[x]==mn[x<<1])tr[x]+=tr[x<<1];
	if(mn[x]==mn[x<<1|1])tr[x]+=tr[x<<1|1];
}
void Build(ll x,ll l,ll r){
	if(l==r){
		mn[x]=0,tr[x]=1;
		return ;
	}
	ll mid=(l+r)>>1;
	Build(x<<1,l,mid);
	Build(x<<1|1,mid+1,r);
	Pushup(x);
}
void Pushtag(ll x,ll k){
	tag[x]+=k,mn[x]+=k;
}
void Pushdown(ll x){
	if(!tag[x])return ;
	Pushtag(x<<1,tag[x]);
	Pushtag(x<<1|1,tag[x]);
	tag[x]=0;
}
void Upd(ll x,ll l,ll r,ll ql,ll qr,ll k){
	if(l>qr||r<ql)return ;
	if(ql<=l&&r<=qr){
		Pushtag(x,k);
		return ;
	}
	ll mid=(l+r)>>1;
	Pushdown(x);
	Upd(x<<1,l,mid,ql,qr,k);
	Upd(x<<1|1,mid+1,r,ql,qr,k);
	Pushup(x);
}
ll Q(ll x,ll l,ll r,ll u){
	if(l>u||r<u)return 0;
	if(l==r)return mn[x];
	ll mid=(l+r)>>1;
	Pushdown(x);
	if(u<=mid)return Q(x<<1,l,mid,u);
	else return Q(x<<1|1,mid+1,r,u);
}
ll Val(ll x){
	ll res=x*(x-1)/2+Q(1,1,n,x)-(x-1)*(x-2)/2-Q(1,1,n,x-1);
	// cout<<x<<" "<<Q(1,1,n,x)<<" "<<Q(1,1,n,x-1)<<endl;
	return res;
}
void Sub(ll x){//找第一个 x
	// cout<<"sub"<<x<<endl;
	ll l=1,r=n,pos=1;
	// rep(i,1,n)cout<<Val(i)<<" ";
	// cout<<endl;
	while(l<=r){
		ll mid=(l+r)>>1;
		if(Val(mid)>=x)r=mid-1,pos=mid;
		else l=mid+1;
	}
	// cout<<pos<<endl;
	Upd(1,1,n,pos,n,-1);
}
void Add(ll x){//找最后一个 x
	// cout<<"add"<<x<<endl;
	// rep(i,1,n)cout<<Val(i)<<" ";
	// cout<<endl;
	ll l=1,r=n,pos=n;
	while(l<=r){
		ll mid=(l+r)>>1;
		if(Val(mid)<=x)l=mid+1,pos=mid;
		else r=mid-1;
	}
	// cout<<pos<<endl;
	Upd(1,1,n,pos,n,1);
}
map<pii,ll>mp;
bool Med;
int main(){
	cerr<<fabs(&Med-&Mbe)/1048576.0<<"MB\n";
	n=read(),q=read();
	Build(1,1,n);
	rep(i,1,n)deg[i]=n-i;
	while(q--){
		ll x=read(),y=read();
		if(x>y)swap(x,y);
		pii p=make_pair(x,y);
		if(mp.find(p)!=mp.end()){
			if(!mp[p]){
				Add(deg[y]),deg[y]++;
				Sub(deg[x]),deg[x]--;
			}
			else {
				Add(deg[x]),deg[x]++;
				Sub(deg[y]),deg[y]--;
			}
		}
		else {
			Add(deg[y]),deg[y]++;
			Sub(deg[x]),deg[x]--;
		}
		mp[p]^=1;
		write(tr[1]),putchar('\n');
	}
	return 0;
}

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

詳細信息

Test #1:

score: 100
Accepted
time: 3146ms
memory: 61596kb

input:

500000 500000
111236 111238
400537 400538
14798 14799
480138 480140
99901 99904
169041 169045
20969 20970
111098 111100
245492 245493
25296 25300
21736 21739
415491 415495
222594 222595
162236 162238
362422 362425
422694 422695
339973 339974
241678 241680
192401 192403
125627 125629
261473 261474
10...

output:

499998
499998
499998
499996
499993
499989
499989
499987
499987
499983
499980
499976
499976
499974
499971
499971
499971
499969
499967
499965
499965
499961
499961
499961
499961
499961
499961
499958
499955
499952
499949
499947
499947
499945
499942
499940
499938
499936
499934
499930
499926
499924
499920...

result:

ok 500000 numbers

Test #2:

score: 0
Accepted
time: 3172ms
memory: 64564kb

input:

500000 500000
275072 275075
426847 426850
409242 409246
146242 146245
383677 383680
306056 306058
399602 399608
166932 166934
484108 484109
164331 164340
223174 223175
36591 36593
312357 312358
396602 396605
196545 196550
332 338
394336 394339
493543 493550
112676 112679
473708 473709
173498 173499
...

output:

499997
499994
499990
499987
499984
499982
499976
499974
499974
499965
499965
499963
499963
499960
499955
499949
499946
499939
499936
499936
499936
499929
499922
499918
499914
499910
499907
499905
499905
499899
499893
499893
499890
499886
499883
499874
499869
499865
499862
499860
499860
499852
499850...

result:

ok 500000 numbers

Test #3:

score: 0
Accepted
time: 3204ms
memory: 68892kb

input:

500000 500000
9358 9363
280765 280774
14184 14192
309352 309374
289909 289950
63904 63945
23205 23208
485479 485500
213562 213597
95121 95127
472503 472516
261103 261145
152164 152192
192187 192193
100859 100865
250753 250776
495389 495397
82904 82918
457456 457474
264512 264545
469251 469271
410031...

output:

499995
499986
499978
499956
499915
499874
499871
499850
499815
499809
499796
499754
499726
499720
499714
499691
499683
499669
499651
499618
499598
499586
499582
499569
499559
499556
499526
499486
499472
499441
499421
499384
499360
499328
499315
499290
499268
499250
499216
499206
499200
499189
499177...

result:

ok 500000 numbers

Test #4:

score: 0
Accepted
time: 3239ms
memory: 67812kb

input:

500000 500000
393804 393881
341931 341944
146471 146497
353319 353366
320924 320973
258901 258910
300647 300667
406215 406263
268132 268158
443911 443957
375154 375195
240330 240393
355920 355939
96446 96464
280616 280632
102147 102189
190829 190858
487717 487782
456713 456788
400648 400657
86226 86...

output:

499923
499910
499884
499837
499788
499779
499759
499711
499685
499639
499598
499535
499516
499498
499482
499440
499411
499346
499271
499262
499212
499189
499121
499083
498999
498951
498867
498796
498746
498662
498616
498550
498522
498522
498480
498477
498475
498387
498368
498323
498284
498276
498273...

result:

ok 500000 numbers

Test #5:

score: 0
Accepted
time: 3297ms
memory: 68040kb

input:

500000 500000
361307 361355
290649 290709
300635 300928
117507 117815
321776 321984
299206 299368
310218 310220
405228 405254
81536 81809
139869 139916
206055 206325
168579 168601
215621 215643
370589 370774
499789 499867
379295 379337
329519 329908
445839 445917
34090 34457
329310 329469
279065 279...

output:

499952
499892
499599
499291
499083
498921
498919
498893
498620
498573
498303
498281
498259
498074
497996
497954
497565
497487
497120
496961
496946
496848
496649
496520
496516
496037
495763
495733
495700
495661
495451
495366
495349
495137
495001
494963
494851
494664
494493
494407
494238
494083
493856...

result:

ok 500000 numbers

Test #6:

score: 0
Accepted
time: 3291ms
memory: 68704kb

input:

500000 500000
60190 60484
464079 464564
251402 251450
200393 200409
128827 128926
104076 104157
226927 226951
155093 155326
404140 404352
339419 339511
150064 150246
242349 242438
338010 338119
326050 326830
466213 466680
413263 413857
3262 3493
360455 360545
290186 290323
442081 442271
279047 27907...

output:

499706
499221
499173
499157
499058
498977
498953
498720
498508
498416
498234
498145
498036
497256
496789
496195
495964
495874
495737
495547
495521
495163
495009
494735
494019
493420
492645
492552
492409
492143
491992
491310
490968
490767
490383
490326
490311
489704
488951
488859
488718
488532
488213...

result:

ok 500000 numbers

Test #7:

score: 0
Accepted
time: 3305ms
memory: 69392kb

input:

500000 500000
352778 354832
445736 446940
42174 43636
198416 198453
361015 361766
140452 144652
211279 211593
317000 318878
53349 53577
125272 126183
451286 453318
467022 469100
142760 144133
80690 83972
456967 458861
341615 343010
321129 324458
325338 328917
318570 319023
335943 339512
377852 37791...

output:

497946
496742
495280
495243
494492
490292
489978
488100
487872
486961
484929
482851
482851
479569
477675
476280
472951
469372
469227
465658
465597
464282
463542
462081
459898
458276
456513
454206
451826
451058
451058
450070
449499
446590
442096
438942
436739
433316
429695
428619
427797
426976
423261...

result:

ok 500000 numbers

Test #8:

score: 0
Accepted
time: 3193ms
memory: 68948kb

input:

500000 500000
15805 15987
142937 142994
33581 33683
181643 181735
306761 306853
99681 99955
278004 278404
288700 288841
465160 465327
490034 490391
145155 145500
19087 19193
287189 287240
307659 307996
26331 26445
721 730
440203 440306
402730 402737
79545 79923
341935 341996
112570 112884
247926 247...

output:

499818
499761
499659
499567
499475
499201
498801
498660
498493
498136
497791
497685
497634
497297
497183
497174
497071
497064
496686
496625
496311
496306
496203
496125
496077
495943
495930
495537
495165
495130
494803
494765
494446
494275
494108
493890
493809
493681
493504
493233
492968
492886
492878...

result:

ok 500000 numbers

Test #9:

score: 0
Accepted
time: 3270ms
memory: 69268kb

input:

500000 500000
398142 398677
360707 360919
410435 410974
331032 331979
367108 367720
136580 136677
41226 41272
416082 416368
453136 453995
444144 444604
447579 447738
93366 93886
76459 76587
438189 438452
472062 472803
302767 302874
384377 384462
382039 382588
426930 426993
112403 112887
125113 12556...

output:

499465
499253
498714
497767
497155
497058
497012
496726
495867
495407
495248
494728
494600
494337
493596
493489
493404
492855
492792
492308
491857
491255
490648
490643
490240
489338
489299
489177
489115
489023
488909
488823
488517
487836
487070
486864
486490
486485
486319
485965
485322
484997
484715...

result:

ok 500000 numbers

Test #10:

score: 0
Accepted
time: 3347ms
memory: 69100kb

input:

500000 500000
301789 303841
73271 73742
398165 398224
383756 383919
183009 183245
6115 7022
163223 163589
445883 447168
300252 303454
373124 374029
163339 164251
41880 44014
145096 146857
110515 113611
140527 143957
435837 438828
399229 399883
416856 416914
157418 158006
5899 8199
83280 84963
360407...

output:

497948
497477
497418
497255
497019
496112
495746
494461
492924
492019
491357
489223
487462
484366
480936
477945
477291
477233
476645
475252
473569
471440
470940
468310
466923
466863
465350
463762
462970
459271
459271
457599
455722
453078
451843
450820
450549
449091
447318
445434
444364
443256
442024...

result:

ok 500000 numbers

Test #11:

score: 0
Accepted
time: 3278ms
memory: 68824kb

input:

500000 500000
288765 289493
400451 409630
132677 135172
381320 382945
186584 188850
250176 256802
425481 426627
100622 104464
205463 206295
223440 228488
274932 279973
154173 159894
233893 235434
252384 254354
231580 239991
405422 405705
463620 468117
10950 16214
394481 395698
176162 179530
432550 4...

output:

499272
490093
487598
485973
483707
477081
475935
472093
471261
466213
461172
455451
453910
453910
447040
447040
442543
437279
436062
432694
428866
426519
422460
419211
413598
411620
411490
408837
403800
398425
393381
392286
390810
385580
384981
383741
382089
379032
379032
376527
376484
372907
367764...

result:

ok 500000 numbers

Test #12:

score: 0
Accepted
time: 3256ms
memory: 68392kb

input:

500000 500000
194909 199207
50526 88484
312160 329427
306438 315663
87755 97252
256257 294895
378226 393855
333681 345654
31012 32662
171272 198245
393164 399183
202812 225817
357292 373374
57765 98353
461703 484643
221164 236785
309071 313778
12873 23402
169821 189518
410729 435262
385022 387291
46...

output:

495702
457744
440477
434755
425987
387349
371720
359747
358097
334460
329132
306127
290045
288944
266004
255036
255036
244507
243056
218523
218523
218523
218523
216856
210688
205836
205836
195295
184300
180379
180379
166608
155220
155220
155220
155220
155220
135593
135593
135593
113435
113435
111192...

result:

ok 500000 numbers

Test #13:

score: 0
Accepted
time: 3269ms
memory: 69240kb

input:

500000 500000
210189 224664
237749 246216
371998 387113
206500 227946
108193 131087
467639 499629
205891 224972
406812 440168
306305 347034
51592 88483
269690 298937
119771 147561
117419 137073
225266 226798
215445 233003
112149 146365
486688 490166
280280 280582
274195 298370
287673 295082
358119 3...

output:

485525
477058
461943
454972
432078
400088
399479
366123
325394
288503
259256
242782
242782
242782
237725
237725
237725
237725
237725
237725
237226
226673
226673
226673
219236
219236
219236
219236
215121
212554
212554
212554
212554
200324
199047
199047
199047
197250
196644
175431
173269
169047
165130...

result:

ok 500000 numbers

Test #14:

score: 0
Accepted
time: 3307ms
memory: 69456kb

input:

500000 500000
101425 143594
403085 471426
200679 278234
425559 450898
313213 381058
466764 483082
318149 340197
56538 59699
56673 98347
214463 261877
452114 471949
4253 9078
55766 89311
36735 79241
422422 450464
345376 396668
16682 25877
223170 266031
16045 95436
116952 168859
309927 336747
59068 97...

output:

457831
389490
311935
311935
244090
232434
232434
229273
190625
190625
190625
185800
185028
165997
165997
150387
141192
141192
129697
104432
101146
101146
94804
94804
94804
94804
91388
91388
91388
91388
91388
70144
70144
70144
70144
68284
68284
68284
68284
68284
68284
68284
54985
54985
54985
53229
53...

result:

ok 500000 numbers

Test #15:

score: 0
Accepted
time: 2990ms
memory: 52952kb

input:

500000 500000
196426 196437
29921 29962
288408 288478
472057 472058
301049 301062
327842 327867
275973 275987
236642 236649
169578 169593
37703 37797
195623 195689
450432 450462
82154 82162
442229 442245
267802 267839
456556 456585
232640 232678
326331 326332
84709 84774
156620 156622
133520 133537
...

output:

499989
499948
499878
499878
499865
499840
499826
499819
499804
499710
499644
499614
499606
499590
499553
499524
499486
499486
499421
499419
499402
499316
499255
499253
499250
499217
499210
499173
499093
499080
499062
499052
499035
498998
498980
498918
498891
498869
498855
498809
498804
498766
498729...

result:

ok 500000 numbers

Test #16:

score: 0
Accepted
time: 2996ms
memory: 53788kb

input:

500000 500000
164785 164913
38530 38640
163574 163798
465795 465951
463370 463404
350555 350560
73606 73914
122693 122835
52125 52152
277501 277706
413094 413178
238216 238474
184537 184959
68031 68055
198144 198442
211155 211400
281160 281248
489417 489499
181756 181982
356742 356749
178020 178485
...

output:

499872
499762
499538
499382
499348
499343
499035
498893
498866
498661
498577
498319
497897
497873
497575
497330
497242
497160
496934
496927
496462
496360
496360
495972
495679
495611
495513
495427
495333
495309
495296
495270
495223
495098
494775
494748
494718
494317
494217
494075
494070
494059
493986...

result:

ok 500000 numbers

Test #17:

score: 0
Accepted
time: 3020ms
memory: 52560kb

input:

500000 500000
193531 193745
112268 112750
228489 228739
406137 406809
429808 429924
186701 186764
297144 297568
151070 151312
19622 19890
44177 44682
492143 492712
18015 18765
458294 458512
345220 345302
309618 309961
125010 125570
91005 91197
196441 196726
399446 399800
212643 212985
236282 236579
...

output:

499786
499304
499054
498382
498266
498203
497779
497537
497269
496764
496195
495445
495227
495145
494802
494242
494050
493765
493411
493069
492772
492185
491524
491447
490596
490254
489773
489731
489481
489342
489078
488991
488654
488191
487724
487691
487522
487300
487248
487150
486829
486769
485857...

result:

ok 500000 numbers

Test #18:

score: 0
Accepted
time: 3004ms
memory: 53208kb

input:

500000 500000
96023 98972
183018 184195
373231 373321
396186 397695
392440 394716
321186 324190
45319 48515
160992 162343
240021 243598
227241 228724
447152 448973
135524 136639
113182 114486
356096 356846
96730 99631
367283 368875
122262 123198
80012 81047
370959 371775
92978 94734
386354 389052
23...

output:

497051
495874
495784
494275
491999
488995
485799
484448
480871
479388
477567
476452
475148
474398
473739
472147
471211
470176
469360
467604
464906
461934
459862
457034
456376
456130
454631
450873
450689
450689
448754
447482
446933
446933
446874
446128
443743
442017
440616
439057
439057
436148
435691...

result:

ok 500000 numbers

Test #19:

score: 0
Accepted
time: 3190ms
memory: 53796kb

input:

500000 500000
400131 404662
306521 308741
372214 372650
281688 284927
150424 154376
416105 418781
36846 39937
96852 98017
157590 157841
31846 32856
224620 224928
301901 304277
335953 337824
356212 356626
273255 273345
210938 211099
124724 124925
315196 317609
136177 137513
291884 293427
392307 39389...

output:

495469
493249
492813
489574
485622
482946
479855
478690
478439
477429
477121
474745
472874
472460
472370
472209
472008
469595
468259
466716
465129
464547
460782
458162
456847
456202
455500
452440
451414
451414
448789
447956
447850
447810
446040
442104
441937
441193
439520
438409
437938
437493
436515...

result:

ok 500000 numbers

Test #20:

score: 0
Accepted
time: 3184ms
memory: 52848kb

input:

500000 500000
300609 305117
192987 195204
230206 238911
130512 133321
224189 227562
42957 47713
470713 472762
433671 433708
106128 107939
137422 138534
224356 228675
73075 76059
22119 23212
310351 310414
456529 459671
184809 187794
210145 218431
121259 125833
251225 255382
464914 467050
95386 95835
...

output:

495492
493275
484570
481761
478388
473632
471583
471546
469735
468623
467510
464526
463433
463370
460228
457243
448957
444383
440226
438090
437641
436160
426747
425179
422464
421408
419536
419200
418741
415871
411060
406784
403746
403660
401152
397781
396161
388690
387030
385898
382815
382815
382815...

result:

ok 500000 numbers

Test #21:

score: 0
Accepted
time: 3223ms
memory: 52204kb

input:

500000 500000
212548 235229
35067 46487
273580 287350
309890 315230
38 23074
261165 275613
364647 382443
473166 480511
20090 24978
460502 492306
131596 131903
57267 85814
305379 337509
313745 330818
251500 280472
453336 499128
390983 392362
313314 319510
251527 292504
11290 15908
454445 490214
31502...

output:

477319
465899
452129
446789
423753
411338
393542
386197
384293
359834
359527
330980
304190
304190
294525
280537
279158
279158
274004
274004
274004
274004
274004
247462
244726
244726
230630
229931
228841
228841
228338
217198
217198
205329
204447
203812
186651
186651
186651
182629
179348
173765
163676...

result:

ok 500000 numbers

Test #22:

score: 0
Accepted
time: 3304ms
memory: 52600kb

input:

500000 500000
174080 187728
9537 30876
261925 269123
60620 87703
105027 132320
321804 336563
90320 95094
16304 46302
486939 487933
117160 125046
126346 129160
101932 124086
475422 476162
151475 160801
404683 428391
426508 430761
490656 493503
103178 141732
121244 143451
46397 48439
152937 169142
111...

output:

486352
465013
457815
430732
403439
388680
383906
368480
367486
367486
367486
364391
363651
354325
330617
328247
325400
315988
314269
312227
303886
303886
288730
288730
263603
262164
251857
250566
217382
216095
184689
184689
178758
176141
169008
169008
168502
168502
168502
165567
165567
165567
161441...

result:

ok 500000 numbers

Test #23:

score: 0
Accepted
time: 3215ms
memory: 53748kb

input:

500000 500000
404552 463434
358636 367021
441536 487879
444102 455057
425351 488674
120182 197810
49279 78697
178563 179529
116214 144389
263729 281485
21026 34144
204355 249512
147039 163977
441590 459860
161597 194405
217051 218778
240441 241003
1226 33487
276786 284136
445471 450339
13162 80616
4...

output:

441118
432733
408288
408288
407493
329865
300447
300447
296479
278723
265605
220448
220448
220448
220448
220448
220448
200648
197997
197997
180943
180943
180943
166726
166726
166726
166726
166726
166726
162552
162552
157635
157635
157635
140581
140581
140581
140581
140581
140581
101265
99530
99530
8...

result:

ok 500000 numbers

Test #24:

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

input:

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

output:

4
2
1
1
2

result:

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

Extra Test:

score: 0
Extra Test Passed