QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#631187#5144. Set of Intervals999AC ✓33ms8240kbC++141.6kb2024-10-11 22:41:062024-10-11 22:41:07

Judging History

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

  • [2024-10-11 22:41:07]
  • 评测
  • 测评结果:AC
  • 用时:33ms
  • 内存:8240kb
  • [2024-10-11 22:41:06]
  • 提交

answer

#include<bits/stdc++.h>
#define For(a,b,c) for(int a=b;a<=c;++a)
#define Dor(a,b,c) for(int a=b;a>=c;--a)
#define CC(_...) fprintf(stderr,_)
using namespace std;
typedef long long LL;
const int N=200007;
int n,e,ml,sr,L[N],R[N],E[N],D[N],W[N],F[N];
void magic() {
	scanf("%d",&n);
	e=sr=0;
	For(i,1,n) {
		scanf("%d%d",&L[i],&R[i]);
		E[++e]=R[i],E[++e]=L[i]-1;
	}
	if(n==1) {
		puts("1");
		return;
	}
	sort(E+1,E+1+e),e=unique(E+1,E+1+e)-E-1;
	For(i,1,e) D[i]=W[i]=F[i]=0;
	F[e]=E[e];
	For(i,1,n) {
		int l=lower_bound(E+1,E+1+e,L[i]-1)-E;
		int r=lower_bound(E+1,E+1+e,R[i])-E;
		if(r==e) ml=L[i];
		else sr=max(sr,R[i]);
		D[l+1]++,D[r+1]--,W[r]++;
		F[l]=L[i]-1;
	}
	if(W[e]>1) sr=E[e];
	Dor(i,e,1) if(!F[i]) F[i]=F[i+1];
	LL ans=0;
	int p=0;
	For(i,2,e) {
		D[i]+=D[i-1];
		if(!D[i]) {
			if(p>=2&&p<=n-2) {
				ans+=1LL*(E[i]-E[i-1])*(E[i]-E[i-1]-1)/2;
				ans+=1LL*(E[i]-E[i-1])*(E[e]-E[i]);
			}
			else if(p==1&&n>=3) {
				int c=0,l=E[e];
				For(j,1,n) {
					if(L[j]>E[i]) {
						l=min(l,L[j]-1);
						++c;
					}
				}
				if(c>=3) ans+=1LL*(E[i]-E[i-1])*(E[e]-l);
				else {
					int s=0,d=D[i];
					For(j,i+1,e) if(d+=D[j]) s+=E[j]-E[j-1];
					ans+=1LL*(E[i]-E[i-1])*s;
				}
			}
		}
		else {
			if(D[i]>1||p&&i!=e) {
				ans+=1LL*(E[i]-E[i-1])*(E[i]-E[i-1]-1)/2;
				ans+=1LL*(E[i]-E[i-1])*(E[e]-E[i]);
			}
			else {
				int r=E[e];
				if(D[i]==1&&ml<=E[i]) {
					r=sr;
				}
				ans+=1LL*(E[i]-E[i-1])*max(0,r-F[i]);
			}
		}
		p+=W[i];
	}
	printf("%lld\n",ans);
}
int main() {
	int T; scanf("%d",&T);
	while(T--) magic();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4
1
1 1000000000
2
1 1000000000
1 1000000000
4
1 2
3 4
5 6
7 8
4
1 3
2 4
5 8
6 7

output:

1
499999999500000000
26
28

result:

ok 4 number(s): "1 499999999500000000 26 28"

Test #2:

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

input:

10000
1
778216842 910688403
1
513404058 890988011
1
1 1000000000
1
1 1000000000
1
758932694 848837772
1
516433381 715411928
1
1 1000000000
1
1 1000000000
1
1 1000000000
1
1 1000000000
1
1 1000000000
1
652548522 898071173
1
1 1000000000
1
509357508 603420032
1
1 1000000000
1
657294869 887475066
1
1 1...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 10000 numbers

Test #3:

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

input:

10000
2
427286995 863604876
582970459 874563920
2
181948005 565025282
799528580 848659925
2
1 1000000000
716032287 836380611
2
383809946 544540272
520881396 990456979
2
156308569 178412791
731100211 963724967
2
426113388 802990296
556666621 560014605
2
1 1000000000
575838571 811122140
2
255734272 64...

output:

87849603321470913
18821102290156188
113106465274673025
75195165925255965
5141989504048811
1256173734724260
207604390726385765
56483863859672889
37024984393194673
36132096841419954
22573394495301601
143688903920213372
166852999281224709
3932968549941246
63833225117266922
49459548807361176
70057738855...

result:

ok 10000 numbers

Test #4:

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

input:

10000
3
1 1000000000
521067549 666980062
562319713 714009993
3
42407212 75107815
610219669 973789020
873806856 902158965
3
1 1000000000
673648508 809445815
599994567 757240668
3
92939611 410549965
597447135 678622426
676819188 811525072
3
230740729 455081734
606008912 926990742
615223886 822068791
3...

output:

174329051362239765
269965111370246655
187516336041444375
122087055515083130
166464628402586213
303666532800970347
176358932288144970
330593156050995465
59827455776692524
247444999637419584
134334952548458322
199454344726240709
186982464464105447
274043263510447662
200274422590053105
2387307446491590...

result:

ok 10000 numbers

Test #5:

score: 0
Accepted
time: 8ms
memory: 5964kb

input:

10000
4
1 1000000000
10072295 202681835
541668966 608745666
552976904 565764167
4
2825267 24347784
40987434 217972832
805197125 991276445
661928934 813950270
4
134841372 295761427
396522424 401387669
700936283 822533151
684880705 891949933
4
211151840 381825097
582143597 671077771
502785782 73287089...

output:

419468468529738122
472067404581630345
249958855814317444
141269847957056879
462920441405890245
470908383701333985
217198902062578400
491757841228436784
463134981388354119
469535771775776550
456342968477934315
488107381636243122
152242736076698604
221437298614345742
481438730537131050
477662426236416...

result:

ok 10000 numbers

Test #6:

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

input:

10000
5
1 1000000000
58885552 222348761
653224442 875794028
782748888 908948156
729989823 904558984
5
1 1000000000
154439740 255994676
527167448 918981258
945176657 968197828
538331560 799069409
5
115868506 237575430
265858274 458701633
617598986 897974926
614297267 701594502
873895258 994959335
5
1...

output:

488759388365275685
482656974886654995
370448890332099571
398554690679225045
430182531288241947
488613112689238710
304235062526068022
416910021803580597
457140396280870475
498893543411199200
472062417562836406
485068887761019144
325589534389293897
467973652719648760
496887077905699922
365128335262644...

result:

ok 10000 numbers

Test #7:

score: 0
Accepted
time: 20ms
memory: 5964kb

input:

10000
10
1 1000000000
24547944 64880388
67789140 121178659
207427267 253154018
327975514 395852548
794225696 985470871
897125340 903100143
546098441 886489759
687247486 899390666
672418175 769374197
10
50044959 69981735
80659892 93439726
117491835 125380323
205361267 218795090
260506717 353224586
50...

output:

499236490741491944
444774754643748572
487534815697335722
437860398679146608
493764851392449560
497839809506243997
493362488867526719
380657204991041468
489310775223338514
487878652594135815
372923526733073955
490034470294031300
496291749161701722
499638713497195350
498144388514439900
476218778610653...

result:

ok 10000 numbers

Test #8:

score: 0
Accepted
time: 18ms
memory: 5968kb

input:

1000
95
6836231 11615619
19349862 27042647
27915875 29217025
30467554 33705989
37337603 47709456
55789394 59039760
64076492 69527908
70769173 72024498
72636167 78142082
87250860 94829230
100770387 110960822
115822145 116469820
126672078 130065760
132223698 132282796
141575802 144919088
151105400 158...

output:

488626405136142663
489034834328167459
497642574870932063
499931050739717247
490113700336467687
499965785957909789
499490335852597035
496537769842346243
499890670373762747
499974047907579309
499962831355599675
482778483135638407
499964455470451749
499956291919797972
486663281545361201
490372722571087...

result:

ok 1000 numbers

Test #9:

score: 0
Accepted
time: 26ms
memory: 5908kb

input:

100
919
1 1000000000
273141 735787
1574233 1877426
2290913 2525668
3510304 4394752
4645045 5236442
5732675 6733880
7328787 7988896
8146277 9059752
9960074 10380415
11213067 11338808
12319773 13157157
14227572 15293636
16212323 16593558
17350048 17654204
17824315 18347949
18870618 19307262
20195342 2...

output:

499999935088755179
497227670456881127
499999363353683180
499999641891103635
499178848679421303
499999249766200872
499999947340183395
498344009139442664
499147125313911757
499387985267298859
499999463685138390
499169182894933066
499999740777499884
499500842146955936
497964992306076450
499414903487722...

result:

ok 100 numbers

Test #10:

score: 0
Accepted
time: 21ms
memory: 6156kb

input:

10
9345
7340 75556
102954 176734
200091 207235
237831 283843
381026 472468
569040 638941
683102 736032
764789 824661
834001 854529
930691 937230
1016321 1029988
1059101 1100889
1137400 1143430
1170786 1191547
1269461 1361119
1361811 1427653
1471619 1487237
1490814 1593062
1672459 1717664
1781324 182...

output:

499914421680099336
499999991801518430
499985757494859039
499999990745907279
499999980927669915
499999993427484090
499999995523240847
499999984781610194
499999995894084497
499999990882583879

result:

ok 10 numbers

Test #11:

score: 0
Accepted
time: 29ms
memory: 7776kb

input:

1
97233
1791 1932
7482 9086
14132 17426
27002 28161
30208 31417
38391 39877
48288 55735
57883 63377
66757 67149
67866 70649
79616 82150
89131 98729
100600 100740
101315 108346
118475 128703
129874 134938
140584 147101
155559 160983
170511 177493
185582 194387
198540 208241
210739 211922
216648 22179...

output:

499995918491698035

result:

ok 1 number(s): "499995918491698035"

Test #12:

score: 0
Accepted
time: 32ms
memory: 7576kb

input:

1
93361
7257 10755
13590 22205
23327 31579
33157 35013
44029 47874
54719 57035
57462 63149
67628 73018
82024 89887
89922 97570
106992 116116
125027 135461
144492 152672
155578 165335
171912 174415
181771 183832
184800 188986
194780 201925
208170 214446
219996 223757
229388 233307
238813 240785
24740...

output:

499991192513578884

result:

ok 1 number(s): "499991192513578884"

Test #13:

score: 0
Accepted
time: 33ms
memory: 7748kb

input:

1
96785
1 1000000000
9618 11658
20076 26862
28378 28404
29015 36527
37757 47257
56148 66077
67414 74231
82356 84978
87214 90468
97358 101464
102158 110235
119946 130036
135342 138508
147800 156244
163289 166566
167616 172672
182184 183322
185107 187337
191812 197319
205902 214768
216771 217613
22753...

output:

499999999318443960

result:

ok 1 number(s): "499999999318443960"

Test #14:

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

input:

1
92913
1 1000000000
5970 10116
19273 29776
39030 49188
53043 58639
61586 67258
68813 69735
73061 81827
84710 89477
91923 93823
99891 104923
113608 122782
124602 131914
137073 137556
140966 146170
150291 159422
165767 174408
175434 182118
190897 197692
201225 201973
203413 205251
211493 219905
22784...

output:

499999999476930972

result:

ok 1 number(s): "499999999476930972"

Test #15:

score: 0
Accepted
time: 28ms
memory: 7840kb

input:

1
93633
1 1000000000
2502 2979
5781 16003
23760 32112
42538 51411
60479 65023
71818 77009
87428 95936
105489 106776
108043 108238
110813 118833
119551 120313
122848 124014
130416 137761
140243 144251
144629 154870
159363 169019
172326 177710
187803 190799
192485 200151
200250 206392
212267 218066
22...

output:

499999999481744097

result:

ok 1 number(s): "499999999481744097"

Test #16:

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

input:

10000
2
4 8
4 7
2
1 4
4 5
2
1 5
1 4
2
5 10
8 10
2
2 5
2 8
2
1 9
3 7
2
5 6
2 4
2
5 7
1 5
2
5 7
5 6
2
7 10
2 8
2
4 5
5 9
2
1 7
3 7
2
6 8
2 4
2
1 5
2 7
2
3 9
5 9
2
2 6
4 10
2
6 10
9 10
2
5 6
4 9
2
2 7
4 8
2
3 10
4 7
2
6 10
1 7
2
4 10
2 10
2
7 10
3 7
2
1 2
3 6
2
1 8
8 9
2
2 7
3 4
2
3 8
9 10
2
5 9
2 6
2
...

output:

10
7
10
12
18
30
6
14
3
25
9
20
9
20
20
29
7
9
20
22
32
35
19
8
15
9
12
22
6
4
21
16
17
15
26
15
5
34
9
4
19
6
14
11
4
22
9
13
15
36
10
9
25
9
24
33
24
15
5
14
26
12
15
9
3
9
15
9
16
10
6
10
21
3
16
12
22
35
3
22
5
9
12
5
4
11
9
38
6
12
15
33
13
11
14
4
21
15
9
6
13
8
6
22
22
22
6
38
35
12
20
28
11
...

result:

ok 10000 numbers

Test #17:

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

input:

10000
3
5 10
1 7
4 8
3
5 10
1 6
4 7
3
5 9
7 9
2 7
3
5 9
4 5
8 9
3
5 9
2 10
3 8
3
2 8
6 7
6 8
3
1 7
6 8
2 5
3
1 5
2 4
8 10
3
3 5
1 8
1 4
3
2 5
8 9
9 10
3
1 10
5 7
8 9
3
1 4
1 9
6 7
3
8 10
1 10
4 7
3
8 9
1 10
6 7
3
3 4
4 7
4 10
3
4 5
7 8
5 9
3
5 10
7 10
3 7
3
7 9
6 7
2 10
3
2 10
2 9
4 9
3
7 10
3 8
2 9...

output:

41
39
25
15
35
15
28
35
25
21
35
35
42
30
25
15
27
26
36
36
30
35
33
28
30
27
35
30
29
25
22
9
42
28
20
12
24
25
39
20
20
21
25
5
45
35
32
21
20
36
44
33
36
17
27
20
26
33
35
45
21
12
17
28
21
33
32
20
27
34
36
36
32
25
22
27
18
29
14
14
28
28
15
44
33
42
10
36
28
45
41
33
15
42
21
24
35
28
25
10
18...

result:

ok 10000 numbers

Test #18:

score: 0
Accepted
time: 8ms
memory: 7868kb

input:

10000
3
678754780 866367513
219494481 314412722
710462699 899083979
3
180764291 638727171
170616982 266091689
71751664 998380043
3
249617805 327902952
94670264 747185752
485807266 913416471
3
295193048 305622049
573230125 995714574
199061963 586451303
3
87325364 309555899
439323045 493948661
4759940...

output:

124925748789179855
324200611796219055
309351980107803837
228958886711133811
59949140001379081
138184534512319542
228427087876251146
299210766156051514
140526981930412079
268903025738721501
430488921823521081
304554456835962093
210378846720651453
224694334753697940
295363919241079088
2643357342812390...

result:

ok 10000 numbers

Test #19:

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

input:

10000
4
3 5
3 7
1 9
8 9
4
1 10
1 7
2 5
3 4
4
4 5
3 7
7 8
5 10
4
5 10
3 10
2 5
3 10
4
7 9
2 9
2 9
2 6
4
7 9
6 8
3 9
6 8
4
3 4
4 6
5 7
8 9
4
6 7
4 7
2 3
2 7
4
8 10
1 9
7 9
5 9
4
8 10
7 8
8 9
1 10
4
3 7
3 9
2 5
7 10
4
7 10
1 10
3 9
2 9
4
2 8
7 8
6 10
5 9
4
1 4
2 10
4 8
8 10
4
3 10
3 6
3 8
2 8
4
3 6
5 7...

output:

35
42
27
36
28
18
20
15
39
30
36
45
33
45
35
27
20
28
33
45
45
21
45
42
39
35
28
42
39
33
35
44
28
28
20
36
39
41
42
35
25
35
44
28
28
45
10
33
36
15
36
18
44
28
28
35
36
36
21
21
35
25
33
36
15
45
33
27
36
35
21
21
44
22
45
28
42
39
45
33
15
21
18
35
28
27
21
45
45
39
28
28
35
44
21
18
45
36
42
45
...

result:

ok 10000 numbers

Test #20:

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

input:

10000
4
364876699 943883568
211878131 218105444
666091667 690371056
462351814 855085062
4
296942398 742884636
782970981 965487181
424160779 877245243
142968933 431024558
4
42236182 653369149
184425380 575358060
220449177 825094563
359276136 812110376
4
241655856 976531972
402786041 647974707
3712968...

output:

252269112146740410
322520900905810543
296240444250019377
265405592303308611
444579110221154394
264271303191680400
370377607984687870
220876868189691699
254805869152877540
273138663516851815
279218305156928064
262589803812759582
257466423704471142
159500720540716703
209446830245531600
298513832610100...

result:

ok 10000 numbers

Test #21:

score: 0
Accepted
time: 6ms
memory: 6012kb

input:

10000
5
8 10
6 10
5 6
1 8
3 8
5
6 7
2 5
6 10
3 9
2 10
5
4 8
4 7
3 4
5 7
2 7
5
1 9
3 9
4 5
5 10
1 5
5
1 2
4 10
5 7
5 10
1 4
5
1 9
2 7
2 10
4 8
5 10
5
4 9
3 5
1 10
4 6
7 10
5
1 6
1 10
3 4
5 10
5 9
5
3 4
5 6
4 8
3 4
6 10
5
4 10
3 5
1 9
1 6
3 4
5
1 6
1 3
3 6
5 8
2 7
5
3 8
7 10
2 7
5 7
5 8
5
7 8
1 3
6 7
...

output:

44
36
21
45
45
45
44
45
27
45
28
35
28
35
42
45
43
45
36
45
45
28
36
36
36
45
42
45
36
44
36
45
44
21
20
36
27
36
32
36
45
35
25
45
45
44
28
35
35
45
20
45
36
35
28
45
45
44
35
36
42
35
36
45
42
42
36
45
20
45
45
36
35
35
35
36
42
36
42
28
28
35
39
36
27
42
45
25
45
45
36
36
28
45
45
34
28
45
39
36
...

result:

ok 10000 numbers

Test #22:

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

input:

10000
5
204322772 673655551
487178247 782088089
519614508 731165063
126092550 668942190
508056997 973548699
5
31637322 865435680
43414154 576330639
120713149 337308213
32786599 382523841
805615300 950672348
5
184808832 437970581
12892421 99184952
836774956 895070569
126891606 199622946
230921246 839...

output:

337702396389657899
418679384805438347
381096098878920536
429316523795885030
422915211708231375
280884090186905251
345241852850000427
165129312269847927
309484190266934544
429661984440133181
165008300765814149
420974114138260779
373385802031398986
259988070403439210
183367341160102613
346278266287211...

result:

ok 10000 numbers

Test #23:

score: 0
Accepted
time: 16ms
memory: 5964kb

input:

10000
10
5 6
7 9
1 9
2 7
6 9
2 6
6 8
5 6
2 6
7 8
10
7 10
1 7
4 10
5 7
1 7
2 4
4 5
9 10
6 10
9 10
10
2 7
4 6
3 7
3 8
2 5
1 7
2 5
5 7
3 5
5 10
10
2 5
4 10
7 10
4 8
5 7
2 4
2 9
1 10
1 2
9 10
10
8 9
5 8
1 10
4 10
1 6
2 4
2 7
4 7
3 8
6 9
10
9 10
1 7
1 8
1 5
2 9
5 7
6 7
7 9
4 10
2 3
10
6 9
7 8
7 9
3 5
1 4...

output:

36
45
44
45
45
45
36
45
45
45
45
45
45
45
36
36
45
45
45
28
45
45
45
45
45
45
45
45
36
45
44
45
45
45
45
44
36
45
45
45
36
36
45
45
28
45
45
44
45
45
45
45
45
44
45
45
45
45
36
45
45
44
45
36
45
45
45
45
45
45
45
45
45
45
45
36
45
45
36
45
45
36
44
45
45
45
36
45
44
45
45
45
45
45
45
45
45
28
45
45
...

result:

ok 10000 numbers

Test #24:

score: 0
Accepted
time: 18ms
memory: 5908kb

input:

10000
10
5 14
8 20
12 19
7 18
1 11
9 13
17 18
3 17
4 17
19 20
10
12 15
6 19
16 20
8 17
14 16
7 19
4 11
2 10
7 14
11 12
10
3 16
8 9
10 13
8 20
5 15
6 15
8 12
11 16
2 10
1 11
10
4 16
12 13
5 10
7 20
8 14
12 19
4 19
4 17
3 15
1 15
10
1 10
15 20
4 15
7 16
10 15
7 8
4 9
1 5
3 10
6 16
10
15 20
3 6
1 16
3 ...

output:

189
170
184
189
184
190
190
189
189
171
171
152
187
171
130
120
190
189
187
170
187
190
171
171
190
171
187
170
170
187
184
190
170
190
184
190
168
189
190
171
189
105
168
171
190
153
187
153
183
153
170
136
135
190
153
170
171
190
171
189
91
171
189
189
153
190
189
136
171
153
190
171
136
190
170
1...

result:

ok 10000 numbers

Test #25:

score: 0
Accepted
time: 19ms
memory: 5884kb

input:

10000
10
473576772 896807335
585829505 783590694
47056665 387887035
516640029 586477451
65676886 929248657
273658742 943715378
23218668 130659732
701038046 922307855
383281529 435620736
9713662 949500070
10
333775821 916691232
106151826 852024043
240069717 442347009
243644312 645913395
596125150 711...

output:

441413200585843683
321745258521990641
369577230770037954
344922862354031479
420319395966512205
446119853921812676
413385958195791033
294068151868725280
331508893996010816
303975213590472582
380927785127370878
399411243888794654
314673894148636872
469734826417650555
457283910015558089
484711775203782...

result:

ok 10000 numbers