QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#292227#7661. Japanese Lotteryhy233AC ✓857ms244764kbC++141.5kb2023-12-27 21:15:542023-12-27 21:15:55

Judging History

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

  • [2023-12-27 21:15:55]
  • 评测
  • 测评结果:AC
  • 用时:857ms
  • 内存:244764kb
  • [2023-12-27 21:15:54]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=2000005;
// const ll mod=998244353;
inline int rd()
{
	int x=0; bool f=1;
	char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar())
		if(ch=='-') f=0;
	for(;ch>='0'&&ch<='9';ch=getchar())
		x=x*10+(ch^48);
	return f?x:-x;
}
int n,m,q;
vector<int> tr[N<<2];
vector<int> bg;
#define mid ((l+r)>>1)
inline void build(int l,int r,int p)
{
	tr[p]=bg;
	if(l==r) return;
	build(l,mid,p<<1);
	build(mid+1,r,p<<1|1);
}
vector<int> merge(vector<int> u,vector<int> v)
{
	vector<int> ans;
	for(int i=0;i<n;i++)
		ans.push_back(v[u[i]]);
	return ans;
}
inline void chg(int l,int r,int p,int x,const vector<int> &v)
{
	if(l==r)
	{
		tr[p]=v;
		return;
	}
	if(x<=mid)
		chg(l,mid,p<<1,x,v);
	else
		chg(mid+1,r,p<<1|1,x,v);
	tr[p]=merge(tr[p<<1],tr[p<<1|1]);
	// cout<<l<<' '<<r<<' ';
	// for(int i=0;i<n;i++)
	// 	cout<<tr[p][i]<<' ';cout<<endl;
}
int f[N];
int fnd(int x)
{ return f[x]==x?x:f[x]=fnd(f[x]); }
bool vis[N];
int main()
{
	n=rd(),m=rd(),q=rd();
	for(int i=0;i<n;i++)
		bg.push_back(i);
	build(1,m,1);
	while(q--)
	{
		int y=rd(),xl=rd()-1,xr=rd()-1;
		if(vis[y])
		{
			vis[y]=0;
			chg(1,m,1,y,bg);
		}
		else
		{
			vis[y]=1;
			vector<int> fk=bg;
			swap(fk[xl],fk[xr]);
			chg(1,m,1,y,fk);
		}
		for(int i=0;i<n;i++)
			f[i]=i;
		for(int i=0;i<n;i++)
			if(fnd(i)!=fnd(tr[1][i]))
				f[fnd(i)]=fnd(tr[1][i]);
		int ans=n;
		for(int i=0;i<n;i++)
			if(f[i]==i)
				ans--;
		cout<<ans<<endl;
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 17ms
memory: 193116kb

input:

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

output:

1
2
1
0
1
2
1

result:

ok 7 lines

Test #2:

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

input:

5 9 12
1 3 4
2 1 2
3 2 3
4 4 5
5 2 1
6 4 3
7 2 3
8 4 3
9 4 5
6 4 3
7 2 3
1 3 4

output:

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

result:

ok 12 lines

Test #3:

score: 0
Accepted
time: 275ms
memory: 193324kb

input:

20 60 200000
49 11 10
18 6 7
24 4 5
56 10 9
14 19 18
44 2 3
4 3 4
24 4 5
30 4 5
56 10 9
44 2 3
50 10 9
43 6 7
50 9 10
18 7 6
13 16 17
57 16 15
52 7 6
55 7 8
10 18 19
47 17 16
11 11 12
33 17 18
7 11 10
57 15 16
45 9 8
47 17 16
56 17 16
10 18 19
19 5 4
21 9 8
53 10 11
22 8 9
4 4 3
13 16 17
7 11 10
4 8...

output:

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

result:

ok 200000 lines

Test #4:

score: 0
Accepted
time: 380ms
memory: 193956kb

input:

20 400 200000
84 15 16
93 20 19
8 4 5
334 11 10
265 14 13
30 16 15
23 18 19
122 1 2
367 10 9
17 17 16
240 4 5
86 6 7
368 6 5
33 17 16
271 19 20
243 18 19
71 9 8
182 16 15
42 1 2
300 14 13
259 17 16
35 6 7
269 8 7
279 8 9
360 20 19
84 15 16
84 8 7
204 9 10
50 4 5
23 18 19
335 7 8
391 8 7
353 2 3
304 ...

output:

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

result:

ok 200000 lines

Test #5:

score: 0
Accepted
time: 712ms
memory: 219744kb

input:

20 100000 200000
84187 5 4
81775 15 16
35852 2 3
43675 14 15
37167 10 11
28631 9 10
44662 10 9
68558 11 10
63694 11 10
51521 14 15
7418 20 19
7871 16 15
73663 9 8
54430 12 11
86737 11 10
234 5 6
3675 5 4
81807 6 5
46365 18 17
85278 4 3
83185 18 17
37617 4 3
22217 10 9
55279 11 10
4864 3 4
14664 4 5
...

output:

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

result:

ok 200000 lines

Test #6:

score: 0
Accepted
time: 753ms
memory: 218568kb

input:

20 100000 200000
40254 13 12
43097 3 2
51140 2 3
361 10 11
38355 10 9
24292 5 4
78434 17 18
83046 5 6
30372 16 17
29752 16 15
465 14 15
51028 6 5
56823 4 3
16137 2 1
6086 6 5
68895 4 3
99901 6 7
59411 15 14
80531 12 11
48387 12 11
18031 8 7
62565 7 8
43946 1 2
22091 8 7
94502 12 11
92202 10 9
19028 ...

output:

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

result:

ok 200000 lines

Test #7:

score: 0
Accepted
time: 763ms
memory: 218716kb

input:

20 100000 200000
96456 3 4
14229 6 5
28460 7 6
63794 8 7
38040 18 17
76605 10 9
60637 10 9
28600 6 5
16761 2 1
57006 18 17
7974 2 1
25118 8 7
33654 5 6
73468 7 6
37986 2 3
71752 10 11
2025 20 19
34790 9 10
28222 11 10
76172 18 17
78374 11 12
19618 5 6
27451 9 10
97316 17 16
88086 5 4
52185 3 2
1848 ...

output:

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

result:

ok 200000 lines

Test #8:

score: 0
Accepted
time: 857ms
memory: 242448kb

input:

20 200000 200000
172830 14 15
145499 4 5
121702 11 12
163484 4 5
152838 19 18
107244 3 2
84072 19 20
184634 13 14
116717 3 2
85597 2 1
33220 15 16
42087 18 19
146098 20 19
158127 17 18
5564 11 10
139454 13 14
104883 5 4
15585 20 19
12017 4 3
191118 16 17
50882 11 10
193754 3 2
94893 8 7
198039 10 11...

output:

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

result:

ok 200000 lines

Test #9:

score: 0
Accepted
time: 699ms
memory: 238692kb

input:

20 200000 200000
37255 12 13
173520 20 19
171711 10 11
170534 4 5
188420 4 5
178109 13 12
161738 8 7
46406 16 15
15403 12 13
36236 15 16
184131 14 15
2224 20 19
14232 8 9
193647 9 10
32178 7 8
156588 13 12
27693 15 14
199725 13 14
20541 11 12
42484 2 3
158565 6 5
35098 6 5
19280 8 7
32963 16 15
1832...

output:

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

result:

ok 200000 lines

Test #10:

score: 0
Accepted
time: 732ms
memory: 236696kb

input:

20 200000 200000
197148 3 2
582 16 17
41009 18 17
32765 10 9
184076 10 11
31781 15 16
190437 13 14
156461 5 6
41861 19 20
191238 12 13
30823 5 6
191965 11 10
2156 6 7
153376 11 10
196640 6 7
26980 14 15
11584 16 17
4235 4 5
191086 9 10
176925 15 16
178923 6 5
182757 5 4
44084 5 6
20361 8 9
47394 10 ...

output:

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

result:

ok 200000 lines

Test #11:

score: 0
Accepted
time: 749ms
memory: 239028kb

input:

20 200000 200000
180789 4 5
35390 7 8
41300 3 4
176065 5 6
166749 5 6
2315 9 10
181603 20 19
167830 12 13
184750 3 4
8082 8 9
196150 5 4
153925 2 3
44039 15 16
160016 16 17
186290 9 10
181864 17 16
194136 18 17
163921 9 8
36191 3 4
158737 15 14
5928 11 12
46919 12 11
26484 13 12
31363 18 19
20924 4 ...

output:

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

result:

ok 200000 lines

Test #12:

score: 0
Accepted
time: 48ms
memory: 194468kb

input:

6 20 32767
1 1 2
2 2 3
1 1 2
3 3 4
1 1 2
2 2 3
1 1 2
4 4 5
1 1 2
2 2 3
1 1 2
3 3 4
1 1 2
2 2 3
1 1 2
5 5 6
1 1 2
2 2 3
1 1 2
3 3 4
1 1 2
2 2 3
1 1 2
4 4 5
1 1 2
2 2 3
1 1 2
3 3 4
1 1 2
2 2 3
1 1 2
6 1 2
1 1 2
2 2 3
1 1 2
3 3 4
1 1 2
2 2 3
1 1 2
4 4 5
1 1 2
2 2 3
1 1 2
3 3 4
1 1 2
2 2 3
1 1 2
5 5 6
1...

output:

1
2
1
2
3
2
1
2
3
4
3
2
3
2
1
2
3
4
3
4
5
4
3
2
3
4
3
2
3
2
1
2
1
2
3
4
3
2
3
4
3
4
5
4
3
2
3
2
1
2
3
4
3
2
3
2
1
2
3
2
1
0
1
2
1
2
1
2
3
2
3
4
3
4
3
2
3
2
3
4
3
4
3
4
5
4
5
4
3
4
3
2
3
2
3
2
3
2
1
2
3
4
3
4
5
4
3
2
3
4
3
2
3
2
1
2
3
4
3
2
3
2
1
0
1
2
1
2
3
2
1
2
3
2
1
2
3
4
3
2
3
4
3
4
5
4
3
4
5
4
...

result:

ok 32767 lines

Test #13:

score: 0
Accepted
time: 43ms
memory: 194288kb

input:

7 25 28333
6 6 7
11 5 6
6 6 7
11 5 6
6 6 7
5 5 6
11 5 6
5 5 6
5 5 6
15 4 5
11 5 6
6 6 7
5 5 6
6 6 7
15 4 5
11 5 6
10 4 5
6 6 7
11 5 6
10 4 5
6 6 7
5 5 6
4 4 5
11 5 6
10 4 5
5 5 6
4 4 5
10 4 5
5 5 6
4 4 5
15 4 5
6 6 7
5 5 6
4 4 5
11 5 6
6 6 7
5 5 6
11 5 6
10 4 5
6 6 7
5 5 6
11 5 6
10 4 5
6 6 7
5 5 6
...

output:

1
2
1
0
1
2
1
2
1
2
3
2
1
2
1
2
3
2
1
0
1
2
3
2
3
2
3
2
1
2
1
0
1
2
1
2
3
2
3
2
1
0
1
2
3
2
3
2
3
2
3
2
1
2
3
2
3
2
3
2
1
2
3
2
3
4
3
4
3
2
1
2
3
2
1
2
3
2
3
2
1
2
3
4
3
2
3
2
1
2
3
4
3
2
1
0
1
2
3
4
3
4
3
4
3
4
3
2
1
2
3
2
3
2
3
2
3
2
3
4
3
2
3
4
3
2
1
2
1
2
3
2
3
4
3
4
3
2
3
2
3
4
3
4
3
4
3
4
3
2
...

result:

ok 28333 lines

Test #14:

score: 0
Accepted
time: 388ms
memory: 195084kb

input:

20 200 199960
189 2 3
187 3 4
186 2 3
180 5 6
179 4 5
178 3 4
175 6 7
174 5 6
173 4 5
172 3 4
171 2 3
170 1 2
169 7 8
168 6 7
167 5 6
166 4 5
165 3 4
164 2 3
162 8 9
161 7 8
160 6 7
159 5 6
158 4 5
154 9 10
153 8 9
152 7 8
151 6 7
150 5 6
149 4 5
148 3 4
145 10 11
144 9 10
143 8 9
142 7 8
141 6 7
14...

output:

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

result:

ok 199960 lines

Test #15:

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

input:

3 2 2
1 2 1
2 2 3

output:

1
2

result:

ok 2 lines

Test #16:

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

input:

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

output:

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

result:

ok 38 lines

Test #17:

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

input:

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

output:

1
2
3
4
3
4
3
4
3
2

result:

ok 10 lines

Test #18:

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

input:

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

output:

1
0
1
2
1
2
3
4
3
2

result:

ok 10 lines

Test #19:

score: 0
Accepted
time: 15ms
memory: 193692kb

input:

5 10 20
1 1 2
2 2 3
3 3 4
4 4 5
5 1 2
6 2 3
7 3 4
8 1 2
9 2 3
10 1 2
6 2 3
2 2 3
8 1 2
9 2 3
1 1 2
3 3 4
4 4 5
10 1 2
7 3 4
5 1 2

output:

1
2
3
4
3
4
3
4
3
2
1
2
3
2
1
2
1
2
1
0

result:

ok 20 lines

Test #20:

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

input:

5 10 20
6 2 3
2 2 3
8 1 2
9 2 3
1 1 2
3 3 4
4 4 5
10 1 2
7 3 4
5 1 2
1 1 2
2 2 3
3 3 4
4 4 5
5 1 2
6 2 3
7 3 4
8 1 2
9 2 3
10 1 2

output:

1
0
1
2
1
2
3
4
3
2
3
4
3
2
3
2
1
2
1
0

result:

ok 20 lines

Test #21:

score: 0
Accepted
time: 23ms
memory: 193728kb

input:

5 30 30
1 1 2
2 2 3
3 3 4
4 4 5
5 1 2
6 2 3
7 3 4
8 1 2
9 2 3
10 1 2
11 4 5
12 3 4
11 4 5
13 4 5
12 3 4
15 2 3
14 1 2
16 3 4
17 2 3
15 2 3
21 1 2
22 2 3
23 3 4
24 4 5
25 1 2
26 2 3
27 3 4
28 1 2
29 2 3
30 1 2

output:

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

result:

ok 30 lines

Test #22:

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

input:

20 40 38
17 17 18
8 8 9
14 14 15
19 19 20
21 1 2
22 2 3
34 14 15
6 6 7
16 16 17
38 18 19
23 3 4
33 13 14
7 7 8
31 11 12
9 9 10
10 10 11
11 11 12
1 1 2
35 15 16
32 12 13
2 2 3
28 8 9
29 9 10
30 10 11
18 18 19
3 3 4
39 19 20
15 15 16
36 16 17
4 4 5
5 5 6
12 12 13
13 13 14
26 6 7
27 7 8
37 17 18
24 4 5...

output:

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

result:

ok 38 lines

Test #23:

score: 0
Accepted
time: 792ms
memory: 243772kb

input:

20 200000 200000
1 17 16
201 16 17
401 10 9
601 14 15
801 9 8
1001 19 20
1201 3 2
1401 2 3
1601 10 9
1801 6 7
2001 19 20
2201 6 7
2401 4 5
2601 2 1
2801 16 17
3001 10 9
3201 8 7
3401 18 19
3601 2 3
3801 4 5
4001 5 6
4201 19 18
4401 11 12
4601 9 8
4801 14 13
5001 3 2
5201 18 19
5401 15 16
5601 14 15
...

output:

1
0
1
2
3
4
5
4
3
4
3
2
3
4
5
6
7
8
9
8
9
8
9
8
9
8
9
10
9
8
9
10
9
10
9
10
11
10
11
10
9
10
11
12
13
12
13
12
13
14
15
14
13
12
13
12
13
12
11
12
13
14
15
14
13
14
13
14
15
16
15
14
13
12
13
12
13
14
13
14
13
12
11
10
11
10
11
12
11
12
11
12
11
12
11
12
11
12
13
12
13
14
13
14
13
12
13
12
13
14
13
...

result:

ok 200000 lines

Test #24:

score: 0
Accepted
time: 763ms
memory: 243944kb

input:

20 200000 200000
1 13 14
401 9 10
801 19 18
1201 3 4
1601 18 19
2001 15 14
2401 10 9
2801 2 1
3201 8 9
3601 13 12
4001 14 13
4401 3 4
4801 19 20
5201 15 14
5601 12 13
6001 2 3
6401 17 16
6801 1 2
7201 8 7
7601 14 13
8001 14 15
8401 7 8
8801 18 19
9201 5 4
9601 13 12
10001 20 19
10401 9 8
10801 5 4
1...

output:

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

result:

ok 200000 lines

Test #25:

score: 0
Accepted
time: 758ms
memory: 244340kb

input:

20 200000 200000
1 8 7
601 16 15
1201 3 2
1801 1 2
2401 4 5
3001 7 8
3601 11 10
4201 4 5
4801 17 18
5401 6 5
6001 13 14
6601 16 15
7201 9 8
7801 13 12
8401 16 17
9001 2 3
9601 12 11
10201 10 9
10801 2 3
11401 3 4
12001 13 14
12601 14 13
13201 10 9
13801 9 10
14401 12 13
15001 7 6
15601 16 17
16201 1...

output:

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

result:

ok 200000 lines

Test #26:

score: 0
Accepted
time: 702ms
memory: 243476kb

input:

20 200000 200000
1 15 16
801 7 8
1601 19 18
2401 5 4
3201 7 6
4001 1 2
4801 13 12
5601 16 17
6401 10 11
7201 16 15
8001 9 10
8801 18 17
9601 17 18
10401 3 4
11201 2 3
12001 16 15
12801 19 20
13601 18 17
14401 5 4
15201 9 10
16001 8 7
16801 19 18
17601 19 20
18401 13 14
19201 16 15
20001 17 16
20801 ...

output:

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

result:

ok 200000 lines

Test #27:

score: 0
Accepted
time: 725ms
memory: 243924kb

input:

20 200000 200000
1 10 9
1001 14 13
2001 17 18
3001 13 12
4001 13 14
5001 2 1
6001 11 12
7001 8 7
8001 3 2
9001 2 1
10001 3 4
11001 3 2
12001 4 5
13001 18 17
14001 8 7
15001 7 6
16001 11 10
17001 15 16
18001 14 15
19001 2 3
20001 4 3
21001 15 16
22001 15 16
23001 2 3
24001 13 14
25001 5 4
26001 19 20...

output:

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

result:

ok 200000 lines

Test #28:

score: 0
Accepted
time: 832ms
memory: 244764kb

input:

20 200000 200000
1 16 17
1201 18 19
2401 5 6
3601 13 12
4801 9 10
6001 11 12
7201 16 17
8401 12 13
9601 6 7
10801 17 16
12001 2 1
13201 2 3
14401 2 3
15601 13 14
16801 6 7
18001 16 17
19201 11 10
20401 11 10
21601 13 14
22801 12 13
24001 11 12
25201 19 20
26401 12 13
27601 15 16
28801 6 7
30001 9 8
...

output:

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

result:

ok 200000 lines

Test #29:

score: 0
Accepted
time: 828ms
memory: 243264kb

input:

20 200000 200000
1 3 2
1401 18 17
2801 8 7
4201 14 15
5601 7 6
7001 8 7
8401 9 8
9801 6 7
11201 3 4
12601 14 13
14001 19 20
15401 3 2
16801 17 16
18201 10 9
19601 17 18
21001 9 8
22401 7 6
23801 18 19
25201 12 11
26601 7 8
28001 14 15
29401 10 11
30801 14 15
32201 14 13
33601 4 5
35001 9 10
36401 10...

output:

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

result:

ok 200000 lines

Test #30:

score: 0
Accepted
time: 741ms
memory: 243476kb

input:

20 200000 200000
1 13 12
1601 9 8
3201 14 15
4801 16 15
6401 1 2
8001 14 15
9601 2 1
11201 13 12
12801 7 8
14401 4 3
16001 15 16
17601 5 4
19201 4 3
20801 5 6
22401 2 3
24001 12 11
25601 8 7
27201 8 7
28801 5 6
30401 4 5
32001 15 16
33601 10 11
35201 6 5
36801 9 10
38401 7 8
40001 10 11
41601 14 13
...

output:

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

result:

ok 200000 lines