QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#80139#5410. 树特卡克林Crysfly100 ✓3478ms44004kbC++174.1kb2023-02-22 16:04:472023-02-22 16:04:48

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-22 16:04:48]
  • 评测
  • 测评结果:100
  • 用时:3478ms
  • 内存:44004kb
  • [2023-02-22 16:04:47]
  • 提交

answer

#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
using namespace std;
inline int read()
{
	char c=getchar();int x=0;bool f=0;
	for(;!isdigit(c);c=getchar())f^=!(c^45);
	for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
	if(f)x=-x;return x;
}

#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;

#define maxn 200005
#define inf 0x3f3f3f3f

int n,m;

const int V=(1<<17);
struct bit{
	int tr[1<<18|5],sum;
	void ins(int x){
		++sum;
		int p=x|V;
		while(p)++tr[p],p>>=1;
	}
	void del(int x){
		--sum;
		int p=x|V;
		while(p)--tr[p],p>>=1; 
	}
	void out(){
		For(i,0,7)cout<<tr[i]<<" ";puts("");
	}
	int kth(int k){
		int p=1;
		For(i,1,17){
			if(k<=tr[p<<1])p<<=1;
			else k-=tr[p<<1],p=p<<1|1;
		}
		return p^V;
	}
}T;

#define ls(x) ch[x][0]
#define rs(x) ch[x][1]
int fa[maxn],ch[maxn][2],sz[maxn],si[maxn],mx[maxn],val[maxn];
bool rev[maxn];

struct myset{
	priority_queue<pii>q1,q2;
	void insert(pii o){q1.push(o);}
	void erase(pii o){q2.push(o);}
	pii top(){
		while(q2.size() && q1.top()==q2.top())q1.pop(),q2.pop();
		return q1.top();
	}
	int size(){return q1.size()-q2.size();}
}s[maxn];
// (size,max)

bool nrt(int p){return ls(fa[p])==p||rs(fa[p])==p;}
bool dir(int p){return rs(fa[p])==p;}
void up(int p){
	mx[p]=max(p,max(mx[ls(p)],mx[rs(p)]));
	sz[p]=sz[ls(p)]+sz[rs(p)]+1+si[p];
	val[p]=val[ls(p)]^val[rs(p)]^p;
}
void pr(int x){
	rev[x]^=1;
	swap(ls(x),rs(x));
}
void down(int x){
	if(rev[x]){
		if(ls(x))pr(ls(x));
		if(rs(x))pr(rs(x));
		rev[x]=0;
	}
}
void downall(int p){
	if(nrt(p))downall(fa[p]);
	down(p);
}
void rot(int x){
	int y=fa[x],z=fa[y],k=dir(x),s=ch[x][!k];
	fa[x]=z; if(nrt(y)) ch[z][dir(y)]=x;
	fa[y]=x; ch[x][!k]=y;
	if(s)fa[s]=y; ch[y][k]=s; up(y),up(x);
}
void splay(int x){
	if(!x)return;
	downall(x);
	while(nrt(x)){
		int y=fa[x];
		if(nrt(y))rot(dir(x)==dir(y)?y:x);
		rot(x);
	}
}

int findrt(int x){
	splay(x);
	if(!fa[x]){
		down(x);
		while(ls(x))down(x=ls(x));
		return x;
	}
	return findrt(fa[x]);
}

int st[maxn],tp,k;
void find(int x,int tmp){
//	cout<<"find "<<x<<" "<<k<<" "<<tmp<<"\n";
	down(x);
	if(sz[rs(x)]+tmp>=(1<<k)) find(rs(x),tmp);
	tmp+=sz[rs(x)]+si[x]+1;
//	cout<<"tmp "<<x<<" "<<tmp<<"\n";
	if(tmp>=(1<<k)){
		st[++tp]=x;
		while(tmp>=(1<<k))++k;
	}
	if(sz[ls(x)]+tmp>=(1<<k)) find(ls(x),tmp);
}

void make(int x,int y){
//	cout<<"make "<<x<<" "<<y<<"\n";
	T.del(val[x]);
	if(rs(x)){
		si[x]+=sz[rs(x)];
		s[x].insert(mkp(sz[rs(x)],mx[rs(x)]));
		T.ins(val[rs(x)]);
	}
	splay(y);
	if(rs(x)=y){
		si[x]-=sz[y];
		s[x].erase(mkp(sz[y],mx[y]));
		T.del(val[y]);
	}
	up(x),T.ins(val[x]);
}

void check(int x){
//	cout<<"check "<<x<<"\n";
	splay(x);
	if(s[x].size()){
		pii it=s[x].top();
		if(it>mkp(sz[rs(x)],mx[rs(x)])) make(x,it.se);
	}
}

void acc(int x){
//	cout<<"acc "<<x<<"\n";
	tp=0;
	for(int y=0;x;x=fa[y=x]) splay(x),st[++tp]=x;
	Rep(i,tp,1){
		splay(st[i]);
		make(st[i],st[i-1]);
	}
}

void calcall(int x){
//	cout<<"calcall "<<x<<"\n";
	tp=0,k=0; find(x,0);
//	For(i,1,tp)cout<<st[i]<<" ";puts(" st");
	For(i,1,tp){
		int u=st[i];
		check(u);
	}
}

void mkrt(int x){
	acc(x),splay(x),pr(x);
	calcall(x);
	splay(x);
}

void cut(int x,int y){
	splay(x); int szx=sz[rs(x)]+1+si[x];
	splay(y); int szy=sz[rs(y)]+1+si[y];
	if(szx<szy)swap(x,y),swap(szx,szy);
	acc(x),splay(y);
	si[x]-=sz[y],fa[y]=0,s[x].erase(mkp(sz[y],mx[y])),up(x);
	calcall(x);
}

void link(int x,int y){
	mkrt(y),acc(x);
	fa[y]=x,si[x]+=sz[y],s[x].insert(mkp(sz[y],mx[y])),up(x);
//	puts("linked");
	calcall(x);
}

signed main()
{
	n=read(),m=read();
	For(i,1,n)T.ins(i),up(i);
//	link(1,2);
//	mkrt(2);
//	T.out();
//	For(i,1,3)cout<<fa[i]<<" "<<ls(i)<<" "<<rs(i)<<" "<<val[i]<<" "<<rev[i]<<"\n";
//	exit(0);
	For(_,1,m){
		int op=read(),u=read(),v=read(),k=read();
		if(op==1)link(u,v);
		else cut(u,v);
	//	T.out();
		printf("%d\n",T.kth((k-1)%T.sum+1));
	}
	return 0;
}

详细

Subtask #1:

score: 5
Accepted

Test #1:

score: 5
Accepted
time: 1ms
memory: 17156kb

input:

10 50
1 4 5 8
1 2 10 6
1 7 10 1
1 2 5 7
1 1 5 1
1 8 3 1
1 5 3 3
1 1 9 3
0 10 2 8
1 10 1 6
0 1 10 1
0 4 5 9
1 8 4 9
0 3 5 3
0 10 7 6
1 1 4 1
0 4 8 3
1 5 6 2
1 10 7 1
1 2 7 1
0 2 7 8
0 4 1 10
1 7 2 6
1 2 4 2
1 2 3 4
0 5 6 7
1 8 6 1
0 2 7 7
1 10 3 1
0 3 8 5
0 2 4 7
1 4 10 9
0 1 9 8
0 2 3 1
1 10 8 4
1 1...

output:

9
8
1
1
3
4
9
9
4
9
2
6
11
9
15
6
6
2
2
4
2
9
4
6
10
6
4
13
1
4
1
14
14
3
7
4
7
3
9
8
4
7
8
4
3
3
7
7
5
2

result:

ok 50 numbers

Subtask #2:

score: 5
Accepted

Dependency #1:

100%
Accepted

Test #2:

score: 5
Accepted
time: 1ms
memory: 18184kb

input:

100 500
1 38 34 84
1 71 2 8
1 22 1 89
1 70 2 7
1 100 15 69
1 97 86 77
1 84 39 47
1 21 43 73
1 100 1 64
1 69 99 42
1 19 8 25
1 29 70 91
1 38 1 45
1 92 63 5
1 54 83 94
1 5 12 41
1 73 91 90
1 100 32 10
1 43 38 2
1 73 96 65
1 67 94 26
1 21 31 65
1 22 37 42
1 85 37 12
1 3 46 84
1 69 88 28
1 92 82 87
1 54...

output:

85
8
92
7
74
81
51
79
68
47
28
4
52
7
10
49
9
14
4
77
30
77
50
16
9
36
13
14
30
13
4
10
52
7
34
41
63
60
29
14
62
78
74
40
42
27
51
24
6
24
66
33
27
40
48
76
24
13
14
112
40
33
44
41
47
68
80
33
49
112
76
99
45
65
90
22
51
30
33
59
65
22
50
22
50
63
67
51
58
50
45
3
75
41
74
64
1
7
51
10
42
22
76
49...

result:

ok 500 numbers

Subtask #3:

score: 10
Accepted

Dependency #2:

100%
Accepted

Test #3:

score: 10
Accepted
time: 9ms
memory: 18700kb

input:

1000 5000
1 481 556 393
1 197 951 694
1 844 89 877
1 996 276 422
1 936 284 893
1 606 205 37
1 908 355 156
1 580 338 612
1 889 574 90
1 835 998 105
1 795 673 814
1 286 226 514
1 393 557 950
1 548 913 346
1 714 779 585
1 509 140 1000
1 85 564 274
1 576 820 932
1 246 536 8
1 361 356 299
1 430 364 650
1...

output:

393
697
881
425
896
37
157
623
91
106
819
520
962
352
595
16
280
948
8
307
666
567
563
103
151
5
384
680
260
88
449
313
932
965
62
722
663
823
798
704
527
409
926
463
611
290
99
675
749
6
486
721
550
42
268
994
125
243
158
524
586
934
947
716
108
478
300
759
931
754
992
263
261
784
13
631
229
724
14...

result:

ok 5000 numbers

Subtask #4:

score: 10
Accepted

Test #4:

score: 10
Accepted
time: 341ms
memory: 31700kb

input:

100000 99999
1 1 2 44734
1 2 3 61340
1 1 4 68331
1 2 5 86313
1 4 6 26991
1 4 7 72397
1 3 8 24098
1 5 9 31437
1 5 10 82367
1 5 11 20958
1 11 12 38919
1 12 13 87596
1 2 14 41335
1 1 15 78828
1 14 16 73861
1 9 17 81368
1 1 18 40205
1 9 19 60737
1 4 20 9347
1 5 21 84645
1 18 22 20063
1 15 23 98769
1 15 ...

output:

44735
61342
68333
86315
26994
72400
24102
31442
82372
20963
38925
87603
41342
78835
73869
81377
40214
60746
9356
84654
20073
98780
78096
84936
68247
59462
13246
58069
42163
54594
13293
42645
26853
5004
97006
66947
80024
951
20786
52358
56517
76013
46338
9103
21979
20761
46128
72450
88242
9521
60767
...

result:

ok 99999 numbers

Subtask #5:

score: 10
Accepted

Test #5:

score: 10
Accepted
time: 426ms
memory: 34696kb

input:

100000 99999
1 2 1 30000
1 3 2 76304
1 4 1 35053
1 5 4 38046
1 6 4 43843
1 7 1 64206
1 8 6 52957
1 9 3 42768
1 10 8 6520
1 11 5 43975
1 12 1 64810
1 13 12 64219
1 14 10 78432
1 15 4 62142
1 16 15 235
1 17 3 77806
1 18 17 58130
1 19 5 47941
1 20 14 19568
1 21 7 99780
1 22 17 39362
1 23 4 10525
1 24 1...

output:

30001
76306
35056
38050
43847
64210
52962
42774
6527
43983
64818
64228
78442
62152
246
77817
58142
47953
19581
99794
39376
10539
60403
89304
59521
30009
47189
78769
8444
80436
45397
27687
37175
16360
59044
53960
89899
8332
14084
21922
75850
25515
25098
68678
86109
75488
75879
10223
80048
70404
21913...

result:

ok 99999 numbers

Subtask #6:

score: 20
Accepted

Dependency #3:

100%
Accepted

Test #6:

score: 20
Accepted
time: 2127ms
memory: 43820kb

input:

100000 500000
1 80697 84881 19262
1 95888 80521 10177
1 94305 51186 64430
1 98326 42972 48338
1 12913 26290 94592
1 72437 16368 33161
1 90564 19898 47803
1 72637 75741 79240
1 36415 11660 46397
1 96674 79314 69371
1 5150 54843 2612
1 33519 46498 64905
1 83708 94254 81506
1 51872 64932 91946
1 63852 ...

output:

19262
10177
64429
48337
94596
33161
47805
79242
46399
69373
2612
64909
81512
91956
23328
77077
51755
60147
21156
73862
37883
3541
75252
16667
79090
17015
8464
13951
30540
87627
56430
33759
99460
18806
34544
27730
23888
78785
60056
28296
65149
42767
64112
56512
52968
79488
32043
53322
73047
27093
288...

result:

ok 500000 numbers

Test #7:

score: 0
Accepted
time: 2278ms
memory: 41616kb

input:

100000 500000
1 87372 1693 46778
1 29919 74282 22125
1 45947 87786 73762
1 18407 34425 64466
1 6469 37440 38107
1 97905 31691 12995
1 34941 64965 39434
1 16683 29223 70840
1 40669 31120 91976
1 40091 45641 26394
1 67085 44954 56324
1 68516 91000 86264
1 16645 55788 45558
1 6695 7242 36734
1 31789 14...

output:

46779
22126
73765
64470
38112
12997
39440
70847
91985
26396
56335
86276
45567
36741
45652
56960
8538
52943
61821
30461
28198
3241
12830
25612
23638
40922
57029
4275
7230
55511
2303
3138
6502
7641
42450
36138
36219
30839
26462
95913
95375
16927
52074
18360
82156
4656
66132
72878
34259
77157
69745
109...

result:

ok 500000 numbers

Test #8:

score: 0
Accepted
time: 2267ms
memory: 42880kb

input:

100000 500000
1 69237 88796 73156
1 25561 69256 36918
1 95956 63290 77570
1 75843 24317 16314
1 48334 19399 60167
1 50355 13517 61421
1 11729 8231 43628
1 28165 69141 72262
1 33918 78029 25619
1 88685 14500 87724
1 78046 14967 87573
1 15601 9876 52219
1 12581 43374 8257
1 33460 51101 99986
1 5781 19...

output:

73156
36918
77573
16314
60170
61426
43632
72271
25623
87737
87587
52230
8256
111795
1218
7360
11165
22497
82159
52306
10781
47821
47176
80768
72426
98346
83467
62242
12060
60639
42905
93044
518
91161
88498
2929
13190
49970
56018
53107
83624
76003
96088
17831
10383
24071
79193
61649
60481
28937
87081...

result:

ok 500000 numbers

Test #9:

score: 0
Accepted
time: 2337ms
memory: 41936kb

input:

100000 500000
1 46881 77586 88326
1 19812 19659 55433
1 64896 2276 22853
1 69608 12317 80540
1 19928 54657 24844
1 81242 72835 70875
1 76309 84387 17429
1 36059 63955 78802
1 46225 75485 11956
1 9542 90345 13487
1 31860 38028 39139
1 13551 98764 20735
1 43080 26619 43703
1 87091 39530 57319
1 39777 ...

output:

88328
55435
22855
80546
24848
70880
17429
78810
11955
13488
39143
20740
43710
57329
92260
98090
18237
12951
64016
6745
24961
92785
19002
67382
83440
21383
21629
82076
60070
89665
97510
19292
73293
21528
3158
80156
18226
29931
86340
61337
11127
47455
97724
56950
11695
64682
65552
7189
83674
6496
3497...

result:

ok 500000 numbers

Test #10:

score: 0
Accepted
time: 2149ms
memory: 44004kb

input:

100000 500000
1 35650 6880 50231
1 99505 13687 58595
1 36065 58519 33182
1 56833 50047 32071
1 92979 70048 7436
1 89623 95592 16411
1 64226 79493 19466
1 97995 9636 19132
1 12378 2096 35338
1 69860 19979 52109
1 52452 24984 50968
1 62006 14969 55269
1 35362 26610 95310
1 64854 22673 70018
1 1110 192...

output:

50232
58597
33183
32071
7437
16411
19466
19133
35338
52112
50971
55273
95322
70029
95856
7165
50256
74606
92182
10793
89479
36287
91234
30662
78214
68786
63748
33114
56218
19027
98699
73548
33265
77876
29224
45392
36132
52861
78767
86199
74216
8020
23606
46436
40374
29617
30665
1133
70060
31019
6291...

result:

ok 500000 numbers

Subtask #7:

score: 40
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Dependency #5:

100%
Accepted

Dependency #6:

100%
Accepted

Test #11:

score: 40
Accepted
time: 2453ms
memory: 36724kb

input:

65025 500000
1 27041 52533 58295
1 52533 9544 28161
1 9544 51224 29971
1 51224 54951 56707
1 54951 63558 63875
1 63558 63157 45088
1 63157 62530 26928
1 62530 62458 17687
1 62458 5393 49961
1 5393 28000 18457
1 28000 29607 20242
1 29607 41535 19796
1 41535 20470 31129
1 20470 24564 53568
1 24564 470...

output:

58296
28163
29972
56711
63880
45089
26928
17688
49963
18459
20244
19797
31134
53577
26962
2466
32876
50618
51326
10078
2640
31551
42490
23093
15743
46245
698
9719
62964
61366
12393
58107
47713
28665
29088
7083
44962
55521
32106
44565
11170
55742
41549
60072
9659
35088
63215
24106
1446
26563
12600
33...

result:

ok 500000 numbers

Test #12:

score: 0
Accepted
time: 2749ms
memory: 41772kb

input:

65505 500000
1 44550 54880 25279
1 54880 38760 5399
1 38760 55451 36998
1 55451 56555 60298
1 56555 21648 5164
1 21648 35419 684
1 35419 23180 27431
1 23180 63615 57408
1 44550 19858 4934
1 44550 49705 23327
1 44550 55830 34831
1 44550 17933 35054
1 44550 55286 37389
1 44550 58469 13522
1 44550 6282...

output:

25279
5399
36997
60302
5164
684
27433
57415
4934
23329
34833
35056
37392
13522
49054
43743
38646
57329
16398
36551
56054
33903
28599
28385
58159
29564
61329
11045
17165
26647
51222
52897
51430
31395
1265
6196
55188
29208
6722
17485
18735
60900
33911
48775
45701
20557
10335
25434
53071
17458
28901
57...

result:

ok 500000 numbers

Test #13:

score: 0
Accepted
time: 1984ms
memory: 31884kb

input:

57345 500000
1 31235 47127 52281
1 47127 41559 11657
1 41559 29858 39451
1 29858 11183 25386
1 11183 24769 54529
1 24769 29484 25713
1 29484 23449 36418
1 23449 55112 51390
1 55112 57096 49797
1 57096 36563 50845
1 36563 52797 38063
1 52797 25229 32409
1 25229 56364 13036
1 56364 51239 20748
1 51239...

output:

52282
11657
39452
25386
54534
25714
36423
51397
49804
50854
38069
32415
13037
20748
27672
33608
48241
10882
7720
23482
11483
51583
14931
43272
15904
56072
7275
54595
26281
44522
3626
15
44019
35928
15359
33243
27657
28425
28382
28885
51352
18474
56351
57227
21742
48230
56749
344
22692
4992
15506
330...

result:

ok 500000 numbers

Test #14:

score: 0
Accepted
time: 2255ms
memory: 35448kb

input:

100000 500000
1 46997 49078 94426
1 83778 46997 48279
1 78595 83778 77238
1 68114 78595 86044
1 86898 78595 59078
1 45773 68114 53426
1 65096 45773 72209
1 93441 65096 30231
1 77445 45773 72942
1 97192 65096 86119
1 86362 93441 28648
1 92873 86362 19454
1 81096 86362 21226
1 79163 92873 97743
1 9703...

output:

94427
48280
77239
86049
59080
53429
72214
30230
72946
86125
28648
19454
21225
97753
49987
81412
66893
63288
39611
35721
65605
94476
2880
44069
33184
77694
37490
93204
98523
8477
12920
84741
15344
89890
2502
10954
73798
92636
97926
10908
7276
43264
54983
27225
27180
40588
21077
36387
88553
24792
6795...

result:

ok 500000 numbers

Test #15:

score: 0
Accepted
time: 2686ms
memory: 35420kb

input:

100000 500000
1 87313 95120 87274
1 89463 87313 10343
1 63664 89463 20600
1 97040 63664 92748
1 43452 63664 36625
1 64237 63664 33423
1 95307 97040 77195
1 34004 43452 20052
1 80552 64237 62198
1 41951 95307 94597
1 98148 80552 89864
1 90858 80552 12777
1 58810 41951 48961
1 89842 58810 58875
1 8224...

output:

87273
10343
20600
92750
36625
33423
77196
20051
62197
94603
89870
12776
48962
58878
49345
54534
34661
32403
46087
3892
65175
86188
35139
8811
76366
45055
77445
95857
36016
67191
20900
37188
55303
65805
54345
71438
65325
88367
92811
53906
49398
74093
98593
33891
28041
30817
97881
28420
6177
46372
131...

result:

ok 500000 numbers

Test #16:

score: 0
Accepted
time: 2530ms
memory: 34076kb

input:

100000 500000
1 25838 82519 98486
1 98536 25838 89907
1 85863 98536 92548
1 33227 85863 73181
1 87018 98536 17523
1 82907 85863 1320
1 77516 82907 11965
1 98949 82907 41644
1 78338 82907 27374
1 74806 98949 80997
1 51222 98949 25249
1 92184 78338 89862
1 94122 51222 82447
1 93856 51222 53235
1 96070...

output:

98487
89908
92551
73183
17523
1320
11965
41645
27375
80998
25249
89866
82448
53235
87876
54795
17999
51757
47469
40522
352
23618
66320
68317
13280
43503
95953
10117
21072
36786
30214
96882
79964
60708
65841
78671
54095
75907
57089
38820
9299
94956
20037
1732
21844
98822
83479
84785
94046
84264
16188...

result:

ok 500000 numbers

Test #17:

score: 0
Accepted
time: 2549ms
memory: 35916kb

input:

100000 500000
1 85538 89974 37776
1 57438 85538 27384
1 89662 57438 51286
1 73451 89662 78129
1 57668 73451 9577
1 84493 57668 33649
1 68647 84493 28862
1 88907 68647 75756
1 28513 84493 16901
1 29880 88907 29290
1 65265 88907 79099
1 32294 29880 39073
1 23257 29880 14874
1 63666 32294 89959
1 97581...

output:

37775
27384
51286
78130
9577
33649
28861
75760
16901
29290
79104
39075
14874
89970
16434
91876
50788
99322
98634
24248
61525
93148
57381
84948
23772
72035
33951
89010
12617
71975
66266
49181
51947
67074
14326
40355
93729
28114
30960
16576
40925
25475
79982
92337
35837
14443
15136
30112
29720
56328
5...

result:

ok 500000 numbers

Test #18:

score: 0
Accepted
time: 2589ms
memory: 39024kb

input:

65409 500000
1 23879 63674 38154
1 63674 38526 55176
1 38526 23447 48306
1 23447 63471 25171
1 63471 50945 20359
1 50945 19191 61975
1 19191 40317 63537
1 40317 17361 137
1 17361 39269 23659
1 39269 60642 57806
1 60642 35985 40906
1 35985 61062 26071
1 61062 41423 28586
1 41423 7891 46209
1 7891 586...

output:

38155
55177
48308
25173
20359
61979
63543
137
23661
57813
40913
26075
28590
46218
16414
378
14773
7752
39358
22075
59577
59135
30276
40040
48993
36294
10553
38728
31084
55633
11466
52659
50038
40062
32897
41044
61513
5804
17513
350
55838
20228
30004
28956
19629
57540
20598
19896
52185
16160
25706
60...

result:

ok 500000 numbers

Test #19:

score: 0
Accepted
time: 2324ms
memory: 33100kb

input:

63489 500000
1 61116 57081 26485
1 57081 27460 45128
1 27460 21479 32972
1 21479 47052 46200
1 47052 62411 57202
1 62411 9786 49297
1 9786 318 37374
1 318 12182 42530
1 12182 63409 9942
1 63409 32185 1962
1 32185 2208 5444
1 2208 60575 27347
1 60575 41229 14696
1 41229 31464 52595
1 31464 12602 4287...

output:

26484
45128
32973
46202
57205
49300
37377
42534
9944
1963
5446
27351
14700
52605
42883
33997
51939
40084
2514
41086
13843
24991
38622
58967
63187
6256
2041
15498
39899
50895
61960
47958
2879
26274
12187
47044
36264
1290
6486
13097
26330
23586
3275
10154
15009
22652
11689
58805
55368
57520
52596
2310...

result:

ok 500000 numbers

Test #20:

score: 0
Accepted
time: 2538ms
memory: 34564kb

input:

65025 500000
1 60064 31066 32425
1 31066 29549 28982
1 29549 30121 24870
1 30121 64863 59765
1 64863 7245 16117
1 7245 53860 28450
1 53860 20633 1845
1 20633 50976 55459
1 50976 28011 6503
1 28011 32581 18501
1 32581 36512 57285
1 36512 42043 45512
1 42043 8618 19650
1 8618 29227 36267
1 29227 44213...

output:

32426
28982
24870
59767
16118
28451
1845
55465
6503
18501
57294
45520
19651
36275
49425
56518
49802
14520
28914
21838
30402
24860
47037
40956
45934
31783
28124
25204
25203
48806
46458
31953
58156
61125
51681
4780
49281
38266
537
57223
59715
55541
4438
1039
44498
27040
862
39655
46752
37909
35054
343...

result:

ok 500000 numbers

Test #21:

score: 0
Accepted
time: 1088ms
memory: 30488kb

input:

100000 500000
1 30344 95591 24450
1 55302 95591 5952
1 80070 30344 36450
1 62784 55302 13485
1 82525 55302 36629
1 88791 30344 56438
1 97383 55302 3778
1 69792 62784 81694
1 94055 62784 51550
1 86611 95591 98064
1 71632 82525 56654
1 47081 80070 32771
1 79712 69792 42804
1 73645 79712 80634
1 53942 ...

output:

24450
5952
36451
13484
36630
56440
3778
81698
51551
98069
56655
32771
42803
80642
39543
20173
64257
58018
72291
41159
84477
23954
92829
86951
24726
73713
74233
53761
38308
79607
31138
25444
67511
29631
22564
8469
84784
82980
51750
20660
95154
1584
3558
31756
70387
78502
39998
29621
82618
20573
60966...

result:

ok 500000 numbers

Test #22:

score: 0
Accepted
time: 1555ms
memory: 34296kb

input:

100000 500000
1 34055 54715 35000
1 53560 34055 4959
1 75107 54715 17146
1 94442 75107 5456
1 68193 75107 57483
1 68097 94442 48917
1 74946 68097 33856
1 89065 34055 32135
1 4414 53560 72260
1 77241 74946 5448
1 79225 53560 28166
1 75263 77241 99250
1 70194 68097 56459
1 90266 4414 7337
1 98497 7526...

output:

35000
4959
17146
5456
57485
48918
33856
32135
72264
5449
28166
99260
56462
7338
144
34049
77248
47391
96677
62709
39145
66993
96945
77532
77168
16816
58741
18981
70395
32393
20003
14650
8096
85502
7417
94593
50345
92673
37039
6658
42803
81790
53892
53927
33225
10156
25847
12440
95296
80898
79710
899...

result:

ok 500000 numbers

Test #23:

score: 0
Accepted
time: 2017ms
memory: 39464kb

input:

100000 500000
1 22995 30781 27724
1 87981 30781 40248
1 66402 30781 59778
1 37888 22995 52862
1 70930 37888 19086
1 88744 30781 17836
1 87445 70930 3604
1 79205 30781 58798
1 98934 70930 59677
1 50655 79205 8871
1 88225 79205 7368
1 66033 66402 91100
1 12530 79205 43686
1 95126 22995 8372
1 99939 98...

output:

27724
40250
59778
52865
19086
17836
3604
58801
59680
8871
7368
91106
43689
8370
21483
39855
27372
39998
56226
88785
79494
30808
49374
30792
18384
2163
38775
74455
927
40714
14828
44873
85662
35925
41612
65780
23106
45203
87824
39379
46039
57613
28955
23625
47759
2741
85304
75264
69265
93841
11553
80...

result:

ok 500000 numbers

Test #24:

score: 0
Accepted
time: 696ms
memory: 30948kb

input:

100000 500000
1 94198 85627 39290
1 99535 85627 75974
1 90260 94198 81980
1 82236 94198 23300
1 64392 94198 13536
1 95946 90260 71794
1 24406 90260 16176
1 97855 64392 26233
1 5883 82236 87128
1 79629 85627 54185
1 3495 24406 14217
1 93851 82236 85697
1 34636 90260 48768
1 87848 99535 84710
1 22051 ...

output:

39289
75974
81979
23300
13536
71794
16176
26233
87130
54186
14219
85700
48768
84713
27577
53141
50916
84653
33987
91538
46545
25903
75094
1552
88760
40974
49359
91305
85136
5501
23282
46463
86072
66693
6279
65938
25691
3078
95802
83571
82389
71826
405
88850
44015
74420
81424
62822
32186
91998
1433
3...

result:

ok 500000 numbers

Test #25:

score: 0
Accepted
time: 2414ms
memory: 30080kb

input:

100000 500000
1 65510 83020 42891
1 65510 96459 17594
1 65510 22728 89791
1 65510 89693 62754
1 65510 15859 95464
1 65510 4176 74678
1 65510 93664 98309
1 65510 90623 50586
1 65510 41696 50377
1 41696 47083 96719
1 47083 61380 20228
1 47083 2426 41149
1 47083 63845 82244
1 47083 60672 81694
1 47083 ...

output:

42891
17594
89792
62754
95465
74679
98311
50586
50377
96721
20227
41148
82247
81697
84119
45757
76675
43835
63740
97555
60869
78982
30395
13386
90849
48230
86611
2024
45903
26880
78100
70082
38807
84806
91089
54423
24693
68439
2037
11653
481
26823
19729
26993
21614
60495
68521
38385
34909
12994
6813...

result:

ok 500000 numbers

Test #26:

score: 0
Accepted
time: 1378ms
memory: 27344kb

input:

100000 500000
1 95343 1041 34529
1 95343 56462 17985
1 95343 19898 6662
1 95343 26632 53524
1 95343 31092 29203
1 95343 94321 98872
1 95343 82944 89204
1 95343 59606 83404
1 95343 97918 82621
1 95343 89619 20331
1 95343 69461 88198
1 95343 9238 22416
1 95343 33194 26423
1 95343 78007 75944
1 95343 9...

output:

34530
17985
6662
53524
29203
98873
89203
83403
82620
20330
88197
22415
26422
75943
21305
24635
22214
2632
33284
7142
38809
24477
66400
29138
16493
23267
40900
12218
42619
91177
22127
67510
51789
98525
74602
60292
28508
75873
99601
35282
42560
19941
48789
16472
5079
26122
82186
99077
89467
84372
3010...

result:

ok 500000 numbers

Test #27:

score: 0
Accepted
time: 930ms
memory: 26952kb

input:

100000 500000
1 69525 95891 58393
1 69525 31752 66525
1 69525 87234 89645
1 69525 86702 85385
1 69525 72776 39485
1 69525 80150 891
1 69525 57927 92779
1 69525 27732 47699
1 69525 67689 15738
1 69525 56739 65767
1 69525 34035 81391
1 69525 92990 4596
1 69525 72515 21919
1 69525 60838 51585
1 69525 9...

output:

58392
66524
89645
85385
39484
891
92779
47698
15738
65766
81391
4596
21919
51584
90587
62720
7115
23866
41055
29869
60301
89073
72940
17753
26623
30386
1887
26109
75501
53638
4516
79344
96021
60289
43226
72951
43583
55994
87435
59344
63314
57343
80008
27707
22492
42873
91000
95539
75741
40392
18133
...

result:

ok 500000 numbers

Test #28:

score: 0
Accepted
time: 1876ms
memory: 28364kb

input:

100000 500000
1 81534 27522 13799
1 81534 72120 2155
1 81534 55677 7883
1 81534 88869 35294
1 81534 86952 60123
1 81534 78811 78477
1 81534 94238 50407
1 81534 58352 5178
1 81534 73594 97920
1 81534 81410 81272
1 81534 96875 85353
1 81534 96325 68867
1 81534 88708 67507
1 81534 44631 33728
1 81534 9...

output:

13799
2155
7883
35293
60122
78476
50406
5178
97921
81271
85353
68866
67506
33727
56509
72497
63762
66240
21179
76249
30269
17194
60802
91300
89659
4883
54061
53409
75863
47852
72076
10884
20174
46420
2495
96486
38022
12027
74790
6092
69418
66731
74507
16416
43150
36559
7203
83183
99789
40406
43170
9...

result:

ok 500000 numbers

Test #29:

score: 0
Accepted
time: 1979ms
memory: 29368kb

input:

100000 500000
1 94096 76532 70956
1 94096 83084 54078
1 94096 79237 73885
1 94096 87332 54680
1 94096 78284 86420
1 94096 89767 27286
1 94096 98937 59703
1 94096 70656 31507
1 94096 83838 81602
1 94096 93443 27247
1 94096 27614 20751
1 94096 86073 56232
1 94096 76940 70338
1 94096 82688 13012
1 9409...

output:

70955
54077
73884
54679
86419
27285
59703
31507
81601
27247
20751
56232
70337
13012
48108
76051
78331
32959
1829
73614
49478
33046
96974
36080
53514
26700
3507
49533
86113
38934
48043
73285
83280
90275
39805
88740
29301
17685
516
75725
77669
16203
48128
7598
80167
77189
58416
29328
29017
46810
9260
...

result:

ok 500000 numbers

Test #30:

score: 0
Accepted
time: 3478ms
memory: 32188kb

input:

100000 500000
1 91232 90527 70274
1 91232 82329 3668
1 82329 3443 37145
1 3443 52806 36912
1 3443 23063 93246
1 23063 50752 47513
1 50752 95807 3627
1 50752 4007 72233
1 4007 89291 78710
1 89291 87656 78045
1 89291 77129 85253
1 77129 84388 39576
1 84388 34444 11103
1 84388 5037 68711
1 5037 6998 86...

output:

70273
3667
37145
36913
93249
47514
3628
72236
78714
78048
85257
39579
11105
68715
86160
19376
3172
89515
17041
31423
38047
31567
94404
56921
39896
47841
52355
47259
82557
69483
7946
49199
59192
36310
55879
65498
25024
55184
58908
21050
81072
85989
57655
51198
46491
67191
1927
56124
11258
94104
46996...

result:

ok 500000 numbers