QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#563436#4206. Event Hoppinghansiyuan20 60ms29816kbC++141.4kb2024-09-14 11:58:022024-09-14 11:58:07

Judging History

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

  • [2024-09-14 11:58:07]
  • 评测
  • 测评结果:20
  • 用时:60ms
  • 内存:29816kb
  • [2024-09-14 11:58:02]
  • 提交

answer

#include <bits/stdc++.h>
#define pii pair<int,int>
using namespace std;
const int N=1e5+5;
int n,m;
int L[N],R[N],pos[N];
int f0[N][20],g0[N][20];
int f[N][20];
struct nd{int l,r,id;} eve[N];
bool cmp(nd x,nd y){return x.r<y.r;}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%d%d",&L[i],&R[i]);
		eve[i] = {L[i],R[i],i};
	}
	sort(eve+1,eve+n+1,cmp);
	for(int i=1;i<=n;i++){
		pos[eve[i].id] = i;
		f0[i][0] = eve[i].l;
		g0[i][0] = i;
	}
	for(int j=1;j<=17;j++)
		for(int i=1;i+(1<<j)-1<=n;i++){
			if(f0[i][j-1] < f0[i+(1<<j-1)][j-1])
				f0[i][j]=f0[i][j-1], g0[i][j]=g0[i][j-1];
			else
				f0[i][j]=f0[i+(1<<j-1)][j-1], g0[i][j]=g0[i+(1<<j-1)][j-1];
		}
	for(int i=1;i<=n;i++){
		int l=1,r=i;
		while(l<r){
			int mid = (l+r)>>1;
			if(eve[mid].r>=eve[i].l) r=mid;
			else l=mid+1;
		}
		int t = log2(i-l+1);
		if(f0[l][t] < f0[i-(1<<t)+1][t]) f[i][0]=g0[l][t];
		else f[i][0]=g0[i-(1<<t)+1][t];
	}
	for(int j=1;j<=17;j++)
		for(int i=1;i<=n;i++)
			f[i][j] = f[f[i][j-1]][j-1];
	while(m--){
		int s,t;
		scanf("%d%d",&s,&t);
		if(R[s]>R[t]) {puts("impossible"); continue;}
		else if(s==t) {puts("0"); continue;}
		else if(R[s]>=L[t]) {puts("1"); continue;}
		int ans=2;
		int x = pos[t];
		for(int j=17;j>=0;j--)
			if(eve[f[x][j]].l>R[s]){
				ans += (1<<j);
				x = f[x][j];
			}
		if(ans>n) puts("impossible");
		else printf("%d\n",ans);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 10
Accepted
time: 59ms
memory: 29656kb

input:

100000 100000
825913690 825916363
333322014 333324481
302015784 302018251
841002775 841005448
810249910 810252583
803554045 803556718
379590599 379593066
413477311 413479778
304105333 304107800
856802878 856805551
355907399 355909866
365590374 365592841
813775597 813778270
816058339 816061012
383873...

output:

1
impossible
1
impossible
impossible
impossible
31336
impossible
impossible
impossible
impossible
27166
16274
impossible
impossible
impossible
impossible
impossible
impossible
21353
17890
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
67...

result:

ok 100000 lines

Test #2:

score: 10
Accepted
time: 57ms
memory: 29672kb

input:

100000 100000
389680865 389680885
532001242 532004287
460483812 460491583
691010527 691018298
489353103 489356770
593534107 593537042
509433341 509441112
846177578 846179089
586840272 586848043
834393248 834401019
474044207 474051978
614427322 614435093
574678657 574686428
557256443 557262524
502657...

output:

80801
80800
80800
80799
80799
80799
80798
80798
80798
80798
80797
80797
80797
80797
impossible
80796
80796
80796
80796
impossible
80797
80795
80795
80795
80795
impossible
80796
80796
80794
80794
80794
80794
impossible
80795
80795
80795
80794
80793
80793
80793
impossible
80794
80794
80794
80794
80793...

result:

ok 100000 lines

Test #3:

score: 10
Accepted
time: 46ms
memory: 29572kb

input:

100000 100000
1 2
1 2
5 6
5 6
9 10
9 10
13 14
13 14
17 18
17 18
21 22
21 22
25 26
25 26
29 30
29 30
33 34
33 34
37 38
37 38
41 42
41 42
45 46
45 46
49 50
49 50
53 54
53 54
57 58
57 58
61 62
61 62
65 66
65 66
69 70
69 70
73 74
73 74
77 78
77 78
81 82
81 82
85 86
85 86
89 90
89 90
93 94
93 94
97 98
97...

output:

impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
imp...

result:

ok 100000 lines

Test #4:

score: 10
Accepted
time: 53ms
memory: 29756kb

input:

100000 100000
407280099 407284136
197925316 197929353
463232919 463236956
248771331 248775368
314921613 314925650
454125447 454129484
215159269 215163306
376796712 376800749
343418796 343422833
126014235 126018272
315022538 315026575
242069911 242073948
479849211 479853248
414950399 414954436
254079...

output:

99999
99998
99998
99997
99997
99997
99996
99996
99996
99996
99995
99995
99995
99995
99995
99994
99994
99994
99994
99994
99994
99993
99993
99993
99993
99993
99993
99993
99992
99992
99992
99992
99992
99992
99992
99992
99991
99991
99991
99991
99991
99991
99991
99991
99991
99990
99990
99990
99990
99990
...

result:

ok 100000 lines

Test #5:

score: 10
Accepted
time: 60ms
memory: 29700kb

input:

100000 100000
861047815 861052922
578273225 578278332
622183211 622188318
822908739 822913846
546318726 546323833
461573168 461578275
480101364 480106471
456455954 456461061
575234560 575239667
464851862 464856969
897159412 897164519
722826860 722831967
755036709 755041816
811213709 811218816
445680...

output:

99999
99997
99995
99993
99991
99989
99987
99985
99983
99981
99979
99977
99975
99973
99971
99969
99967
99965
99963
99961
99959
99957
99955
99953
99951
99949
99947
99945
99943
99941
99939
99937
99935
99933
99931
99929
99927
99925
99923
99921
99919
99917
99915
99913
99911
99909
99907
99905
99903
99901
...

result:

ok 100000 lines

Test #6:

score: 10
Accepted
time: 52ms
memory: 29484kb

input:

100000 100000
107067593 107068563
375121029 375132523
244489164 244489510
371625987 371628227
63502583 63505678
622119714 622149239
792197805 792202711
692512281 692515198
196552919 196554193
677923903 677926489
680041239 680046357
697562945 697565212
206418851 206420890
410143641 410145269
63943786...

output:

impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
imp...

result:

ok 100000 lines

Test #7:

score: 10
Accepted
time: 0ms
memory: 12120kb

input:

8 5
1 2
3 4
1 5
6 7
5 10
10 20
15 20
999999999 1000000000
1 6
1 7
2 4
3 3
5 8

output:

3
4
impossible
0
impossible

result:

ok 5 lines

Test #8:

score: 10
Accepted
time: 53ms
memory: 29756kb

input:

100000 100000
432053319 432056406
486393780 486396867
318945639 318948726
557737437 557740524
505903620 505906707
312861162 312864249
530084091 530087178
378401259 378404346
590749815 590752902
384158514 384161601
397824663 397827750
305937021 305940108
418238994 418242081
311718972 311722059
421174...

output:

99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
...

result:

ok 100000 lines

Test #9:

score: 10
Accepted
time: 55ms
memory: 29772kb

input:

100000 100000
460767811 460773658
363280780 363286627
318744181 318750028
587618476 587624323
349815139 349820986
654104713 654110560
522640765 522646612
667874398 667880245
722245651 722251498
442864297 442870144
522664153 522670000
660805375 660811222
710639356 710645203
484196740 484202587
355358...

output:

77828
77828
77829
77828
77829
77827
77827
77829
77827
77826
77826
77828
77827
77826
77825
77825
77827
77826
77826
77825
impossible
77824
77826
77825
77825
77825
impossible
77824
77824
77825
77824
77824
77824
impossible
77824
77823
77823
77825
77823
77823
77823
impossible
77824
77823
77822
77823
7782...

result:

ok 100000 lines

Test #10:

score: 0
Wrong Answer
time: 51ms
memory: 29556kb

input:

100000 100000
639515864 639521231
667143094 667144538
647258206 647258690
462233258 462234230
475801547 475802613
524127311 524128428
543287190 543289381
535841282 535843238
585211823 585213845
734658645 734658899
537776171 537783441
730349191 730354503
616233528 616234443
679161417 679162801
660817...

output:

1
1
impossible
1
impossible
impossible
1
impossible
impossible
impossible
1
impossible
impossible
impossible
impossible
1
impossible
impossible
impossible
impossible
impossible
1
impossible
impossible
impossible
impossible
impossible
impossible
1
impossible
impossible
impossible
impossible
impossibl...

result:

wrong answer 3rd lines differ - expected: '2', found: 'impossible'

Subtask #2:

score: 0
Wrong Answer

Test #13:

score: 10
Accepted
time: 2ms
memory: 12196kb

input:

1000 100
67878298 387720407
270457472 922959000
286470357 618323410
260791474 282940414
301337446 553875076
478221503 724555102
380447228 437131400
191801427 465825895
366088873 431222136
49483883 103442781
699926238 720636919
253150351 291688158
411085513 727726933
444078045 496386017
420626857 822...

output:

1
2
2
impossible
1
2
1
2
impossible
2
2
impossible
impossible
impossible
1
impossible
impossible
impossible
impossible
impossible
2
impossible
2
impossible
1
1
impossible
1
1
1
1
impossible
2
impossible
2
impossible
1
1
impossible
impossible
impossible
1
2
impossible
impossible
1
2
impossible
imposs...

result:

ok 100 lines

Test #14:

score: 10
Accepted
time: 2ms
memory: 12104kb

input:

1000 100
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 100...

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

result:

ok 100 lines

Test #15:

score: 10
Accepted
time: 1ms
memory: 12236kb

input:

1000 100
219652137 219887840
411750082 411985785
295784206 296019909
323361457 323597160
263257192 263492895
228373148 228608851
311812010 312047713
189246450 189482153
197024649 197260352
214230968 214466671
209045502 209281205
282113432 282349135
277870778 278106481
394308060 394543763
318175991 3...

output:

999
998
998
997
997
997
996
996
996
996
995
995
995
995
995
994
994
994
994
994
994
993
993
993
993
993
993
993
992
992
992
992
992
992
992
992
991
991
991
991
991
991
991
991
991
990
990
990
990
990
990
990
990
990
990
989
989
989
989
989
989
989
989
989
989
989
988
988
988
988
988
988
988
988
988
...

result:

ok 100 lines

Test #16:

score: 10
Accepted
time: 1ms
memory: 7964kb

input:

1000 100
146460236 650840147
213248988 712234443
271625877 765585418
268035474 762542588
155957999 659365570
108300122 614352264
161735587 665204546
244432982 734605513
84404294 596250403
472975048 964576612
128756912 628710941
130473656 631636782
324178293 813816145
197620586 692901130
353485130 84...

output:

impossible
1
impossible
impossible
1
impossible
impossible
impossible
1
1
impossible
1
impossible
1
impossible
impossible
1
1
impossible
impossible
1
impossible
1
1
1
impossible
impossible
impossible
impossible
1
1
1
impossible
impossible
impossible
impossible
1
1
impossible
impossible
1
1
1
1
impos...

result:

ok 100 lines

Test #17:

score: 10
Accepted
time: 0ms
memory: 12216kb

input:

1000 100
734527256 734722851
176171640 176781511
73713312 74323183
347545391 348155262
741959866 742155461
727094646 727290241
304244550 304854421
256064741 256674612
692278736 692474331
678391491 678587086
757020681 757216276
324370293 324980164
327419648 328029519
720248821 720444416
253015386 253...

output:

1
impossible
1
impossible
246
334
impossible
impossible
impossible
477
impossible
379
impossible
impossible
393
196
impossible
271
122
impossible
impossible
impossible
impossible
impossible
207
impossible
impossible
190
impossible
impossible
impossible
impossible
impossible
impossible
impossible
imp...

result:

ok 100 lines

Test #18:

score: 10
Accepted
time: 1ms
memory: 8160kb

input:

1000 100
549 550
689 690
273 274
760 761
414 415
639 640
420 421
592 593
308 309
55 56
952 953
181 182
2 3
476 477
262 263
329 330
261 262
875 876
78 79
711 712
771 772
871 872
328 329
585 586
185 186
471 472
191 192
611 612
758 759
538 539
24 25
518 519
903 904
748 749
547 548
435 436
81 82
459 460...

output:

impossible
impossible
impossible
554
impossible
impossible
impossible
661
712
333
impossible
impossible
impossible
impossible
impossible
impossible
329
impossible
101
416
impossible
268
impossible
676
impossible
131
impossible
impossible
impossible
337
impossible
417
impossible
231
impossible
146
im...

result:

ok 100 lines

Test #19:

score: 0
Wrong Answer
time: 1ms
memory: 8244kb

input:

1000 100
41916637 42739142
57513660 58326077
21867551 172652993
148410501 243619298
80759769 81439087
1165860 77201426
122988614 155997027
100181236 100563028
185001902 185375949
176810589 177691863
141890410 142849915
92309958 240703409
40538462 236387490
22164234 22167602
144201862 144991292
19678...

output:

impossible
1
2
impossible
impossible
impossible
impossible
1
1
3
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
1
impossible
impossible
impossible
impossible
impossible
1
impossible
impossible
2
impossible
2
impossible
1
impossible
impos...

result:

wrong answer 1st lines differ - expected: '2', found: 'impossible'

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Skipped

Dependency #2:

0%

Subtask #5:

score: 20
Accepted

Test #35:

score: 20
Accepted
time: 45ms
memory: 29816kb

input:

100000 100000
903318459 905410836
903528407 905653109
925180437 927048927
473524826 475597377
362562616 364539688
644980844 646918450
242583398 244653279
506338025 508361063
481496693 483530832
970053326 972147109
794840350 796900045
130664210 132709680
634100524 636336820
844429264 846504591
652483...

output:

500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
...

result:

ok 100000 lines

Test #36:

score: 20
Accepted
time: 55ms
memory: 29692kb

input:

100000 100000
280978238 281996879
128582305 129520369
326480847 327450886
613575910 614525870
773187456 774194521
499427531 500501109
206817453 207828231
147432355 148457712
276397611 277442951
238269352 239211898
864332415 865500617
189404293 190348043
898692256 899607594
395766418 396755456
306101...

output:

impossible
434
impossible
248
338
332
390
impossible
607
771
246
impossible
421
impossible
628
117
549
impossible
impossible
impossible
382
impossible
495
impossible
impossible
357
impossible
522
impossible
54
impossible
impossible
impossible
464
impossible
impossible
225
255
484
60
86
244
579
363
7...

result:

ok 100000 lines

Test #37:

score: 20
Accepted
time: 41ms
memory: 29760kb

input:

100000 100000
315328227 565342348
172493343 423278396
47077854 218308141
77736924 280882803
578420376 829121844
456477365 706164084
572351871 823109648
47238838 218708768
818302749 971917023
250574858 500783122
101021436 327649552
386731775 636229046
560750614 811328057
649806442 888787931
89426598 ...

output:

4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
...

result:

ok 100000 lines

Test #38:

score: 20
Accepted
time: 50ms
memory: 29816kb

input:

100000 100000
532703099 533766917
18747285 19717390
259741440 260161102
33247104 34339796
221460611 222216066
101759380 103356345
868641980 869660917
400488522 402221013
626943992 628192337
732367406 733994895
796371835 798306228
496636511 498600178
946211536 947345154
866952254 868236697
743150932 ...

output:

impossible
367
impossible
impossible
105
3
impossible
12
impossible
impossible
8
impossible
108
impossible
impossible
impossible
126
impossible
impossible
impossible
impossible
impossible
251
impossible
impossible
impossible
impossible
impossible
277
54
impossible
impossible
50
impossible
34
impossi...

result:

ok 100000 lines

Test #39:

score: 20
Accepted
time: 52ms
memory: 29604kb

input:

100000 100000
92218679 95179758
317492416 320745639
733100351 736164573
961855441 965128977
837782167 840987990
17497768 20657218
448274654 451383491
900836773 903892815
285698089 288672515
717206068 720360660
350272947 353502098
539452749 542535367
320153387 323421078
549859328 552774077
407596307 ...

output:

317
317
317
317
317
317
317
317
317
317
317
317
317
317
317
317
317
317
317
317
317
317
317
317
317
317
317
317
317
317
317
317
317
317
317
317
317
317
317
317
317
317
317
317
317
317
317
317
317
317
317
317
317
317
317
317
317
317
317
317
317
317
317
317
317
317
317
317
317
317
317
317
317
317
317
...

result:

ok 100000 lines

Test #40:

score: 20
Accepted
time: 60ms
memory: 29736kb

input:

100000 100000
744013029 744524903
471220871 471690214
120307805 120799735
926899213 927378946
753737949 754240556
361494837 361945312
133903676 134394731
330399973 330949740
34749028 35247553
430334132 430795521
362526758 363012637
266295097 266798513
702502851 703011578
848053622 848544848
78244603...

output:

impossible
685
impossible
1091
162
impossible
impossible
impossible
321
345
impossible
impossible
369
impossible
impossible
impossible
945
404
impossible
impossible
151
349
impossible
923
impossible
1194
654
impossible
impossible
impossible
333
89
975
1373
impossible
203
282
537
impossible
579
impos...

result:

ok 100000 lines

Subtask #6:

score: 0
Skipped

Dependency #1:

0%