QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#452647#1787. 庆典SimonLJK100 ✓646ms72724kbC++145.3kb2024-06-23 19:35:582024-06-23 19:35:59

Judging History

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

  • [2024-06-23 19:35:59]
  • 评测
  • 测评结果:100
  • 用时:646ms
  • 内存:72724kb
  • [2024-06-23 19:35:58]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ln node<<1
#define rn node<<1|1
#define mid (l+r>>1)
const int N=3e5+99,M=6e5+99;
int n,m,q,k,rt;
struct edge{
    int v,nxt;
}edg[M];
int cntedge,hd[N];
void add(int u,int v){
    cntedge++;
    edg[cntedge]=(edge){v,hd[u]};
    hd[u]=cntedge;
}

int dfn[N],low[N],instack[N],bel[N],cnt[N],scc;
stack<int> sta;
vector<int> to[N];
void tarjan(int u){
    sta.push(u); instack[u]=1;
    dfn[u]=low[u]=++dfn[0];
    int v;
    for(int i=hd[u];i;i=edg[i].nxt){
        v=edg[i].v;
        if(!dfn[v]){
            tarjan(v);
            low[u]=min(low[u],low[v]);
        }
        else if(instack[v])
            low[u]=min(low[u],dfn[v]);
    }
    if(dfn[u]==low[u]){
        ++scc;
        do{
            v=sta.top(); sta.pop();
            bel[v]=scc; cnt[scc]++;
            instack[v]=0;
        }while(v!=u);
    }
}
int in[N],tim[N];
void get_dag(){
    int u,v;
    for(u=1;u<=n;u++){
        for(int i=hd[u];i;i=edg[i].nxt){
            v=edg[i].v;
            if(bel[u]!=bel[v])
                to[bel[u]].push_back(bel[v]),in[bel[v]]++;
        }
    }
    queue<int> que;
    for(int i=1;i<=scc;i++)
        if(!in[i]){
            rt=i;
            que.push(i);
        }
    while(!que.empty()){
        u=que.front(); que.pop();
        tim[u]=++tim[0];
        for(int i=0;i<to[u].size();i++){
            v=to[u][i]; in[v]--;
            if(!in[v]) que.push(v);
        }
    }
    return;
}
bool cmp(int A,int B){
    return tim[A]<tim[B];
}
int vis[N];
void dfs_tree(int u){
    vis[u]=1;
    for(int v:to[u]){
        if(!vis[v]){
            add(u,v);
            dfs_tree(v);
        }
    }
}
void get_tree(){
    memset(hd,0,sizeof(hd)); cntedge=0;
    for(int i=1;i<=scc;i++)
        if(!to[i].empty())
            sort(to[i].begin(),to[i].end(),cmp);
    dfs_tree(rt);
    return;
}


int idfn[N],sz[N],dep[N],son[N],sum[N];
void dfs(int u,int fa){
    sz[u]=1; son[u]=0;
    dep[u]=dep[fa]+1;
    sum[u]=sum[fa]+cnt[u];
    int v;
    for(int i=hd[u];i;i=edg[i].nxt){
        v=edg[i].v;
        if(v!=fa){
            dfs(v,u);
            sz[u]+=sz[v];
            if(sz[v]>sz[son[u]]) son[u]=v;
        }
    }
    return;
}
int ed[N],f[N],gf[N];
void dfs2(int u,int fa,int anc){
    dfn[u]=++dfn[0];
    idfn[dfn[0]]=u;
    f[u]=fa; gf[u]=anc;
    if(son[u])
        dfs2(son[u],u,anc);
    int v;
    for(int i=hd[u];i;i=edg[i].nxt){
        v=edg[i].v;
        if(v!=fa&&v!=son[u])
            dfs2(v,u,v);
    }
    ed[u]=dfn[0];
    return;
}
int lca(int u,int v){
    while(u!=v){
        if(dfn[u]<=dfn[v]&&ed[v]<=ed[u]) return u;
        if(dfn[v]<=dfn[u]&&ed[u]<=ed[v]) return v;
        if(dep[gf[u]]>=dep[gf[v]]) u=f[gf[u]];
        else v=f[gf[v]];
    }
    return u;
}
int au[3],av[3];
vector<int> nd,exnd;
bool cmpp(int A,int B){
	return dfn[A]<dfn[B];
}
int staa[N],stacnt;
vector<int> rev[N];
int nf[N],nval[N];
bool judge(int x,int y){
	return dfn[x]<=dfn[y]&&ed[y]<=ed[x];
}
int viss[N],vist[N];
void dfss(int u){
	viss[u]=1;
	for(int v:to[u])
		if(!viss[v])
			dfss(v);
	return;
}
void dfst(int u){
	vist[u]=1;
	for(int v:rev[u])
		if(!vist[v])
			dfst(v);
	return;
}
void solve(int s,int t){
	int u,v;
	for(int i=0;i<nd.size();i++)
		for(int j=i+1;j<nd.size();j++)
			exnd.push_back(lca(nd[i],nd[j]));
	sort(exnd.begin(),exnd.end());
	exnd.erase(unique(exnd.begin(),exnd.end()),exnd.end());
	sort(exnd.begin(),exnd.end(),cmpp);
	stacnt=0;
	for(int i=0;i<exnd.size();i++){
		u=exnd[i];
		while(stacnt&&!judge(staa[stacnt],u)) stacnt--;
		if(stacnt){
			to[staa[stacnt]].push_back(u);
			rev[u].push_back(staa[stacnt]);
			nf[u]=staa[stacnt];
			nval[u]=sum[u]-sum[nf[u]]-cnt[u];
		}
		staa[++stacnt]=u;
	}
	for(int i=1;i<=k;i++){
		to[au[i]].push_back(av[i]);
		rev[av[i]].push_back(au[i]);
	}
	dfss(s); dfst(t);
	int ans=0;
	for(int i=0;i<exnd.size();i++){
		u=exnd[i];
		vis[u]=(viss[u]&vist[u]);
		if(vis[u]) ans+=cnt[u];
		if(vis[u]&&vis[nf[u]]) ans+=nval[u];
	}
	cout<<ans<<'\n';
	for(int i=0;i<exnd.size();i++){
		u=exnd[i];
		to[u].clear();
		rev[u].clear();
		viss[u]=vist[u]=vis[u]=0;
	}
	return;
}

char ch;
void read(int &re){
	re=0; ch=getchar();
	while(ch<'0'||ch>'9') ch=getchar();
	while(ch>='0'&&ch<='9') re=re*10+ch-'0',ch=getchar();
}
int main(){
//    freopen("celebration.in","r",stdin);
//    freopen("celebration.out","w",stdout);
    std::ios::sync_with_stdio(false);
    cin.tie(0);
	read(n); read(m); read(q); read(k);
    int u,v,s,t;
    for(int i=1;i<=m;i++)
        read(u),read(v),add(u,v);
    for(int i=1;i<=n;i++)
        if(!dfn[i])
            tarjan(i);
    get_dag(); get_tree();
    memset(dfn,0,sizeof(dfn));
    dfs(rt,0); dfs2(rt,0,rt);
    n=scc;
    for(int i=1;i<=n;i++)
    	to[i].clear();
    memset(vis,0,sizeof(vis));
    while(q--){
		read(s); read(t);
		nd.clear(); exnd.clear();
        s=bel[s]; t=bel[t];
        nd.push_back(s); exnd.push_back(s);
        nd.push_back(t); exnd.push_back(t);
        for(int i=1;i<=k;i++){
			read(au[i]); read(av[i]);
            au[i]=bel[au[i]]; av[i]=bel[av[i]];
            nd.push_back(au[i]); exnd.push_back(au[i]);
            nd.push_back(av[i]); exnd.push_back(av[i]);
        }
        solve(s,t);
    }
    return 0;
}

详细

Test #1:

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

input:

5 6 5 0
5 2
3 5
3 2
2 4
2 5
3 1
1 5
2 5
3 2
4 5
4 3

output:

0
2
3
0
0

result:

ok 5 lines

Test #2:

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

input:

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

output:

0
3
0
3
2

result:

ok 5 lines

Test #3:

score: 4
Accepted
time: 3ms
memory: 37876kb

input:

5 6 5 0
5 2
3 4
3 5
1 4
2 5
3 1
1 4
1 2
1 3
2 3
4 5

output:

2
0
0
0
0

result:

ok 5 lines

Test #4:

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

input:

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

output:

3
4
0
0
0

result:

ok 5 lines

Test #5:

score: 4
Accepted
time: 3ms
memory: 37900kb

input:

1000 2000 1000 2
512 94
190 206
510 479
795 645
440 90
993 645
435 549
531 308
833 274
797 455
444 86
738 286
212 644
122 876
729 61
651 500
216 78
997 768
280 324
414 170
225 152
730 530
702 476
995 944
995 624
944 1
316 739
864 212
979 745
262 920
78 855
842 296
399 728
413 736
673 951
508 854
448...

output:

0
0
0
0
0
0
0
0
318
0
0
0
61
100
0
290
42
0
0
0
0
34
0
0
0
0
0
0
0
0
360
0
0
0
305
0
0
228
241
219
0
0
0
0
0
207
0
0
0
0
0
0
0
0
0
0
0
0
106
280
0
0
348
0
0
0
207
0
0
0
0
168
0
0
0
0
0
0
154
0
0
35
277
0
0
256
318
0
165
0
0
0
75
0
53
0
0
0
0
0
0
0
130
0
0
0
0
0
72
43
0
0
0
0
242
0
0
156
0
0
0
334
24...

result:

ok 1000 lines

Test #6:

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

input:

1000 2000 1000 0
209 768
327 26
843 380
390 384
434 957
613 676
139 325
317 930
930 878
118 476
260 705
430 436
304 231
614 941
581 402
775 687
666 46
450 432
689 792
60 988
36 634
505 685
98 12
586 911
175 16
915 668
113 831
96 625
919 12
182 546
237 423
914 694
875 898
119 715
389 961
184 726
605 ...

output:

0
0
135
0
0
0
0
0
0
0
0
0
0
152
0
0
134
0
0
0
0
0
0
0
0
230
0
0
0
0
0
367
0
58
0
277
0
0
0
0
0
0
0
126
121
0
0
103
0
108
0
0
9
0
27
142
222
68
215
197
0
0
0
0
0
0
328
0
0
0
0
0
0
0
0
24
0
169
0
0
0
0
0
0
0
0
0
0
0
99
0
0
69
0
0
0
0
0
311
0
266
0
0
0
0
0
0
0
0
24
0
0
7
0
0
306
188
0
0
0
172
31
0
0
27...

result:

ok 1000 lines

Test #7:

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

input:

1000 2000 1000 1
71 841
56 194
964 415
511 612
21 823
996 878
292 234
1000 570
215 312
249 476
839 502
451 488
444 467
876 271
660 601
137 499
3 855
254 851
175 214
170 922
289 911
927 765
976 838
757 935
586 171
371 109
914 102
613 436
137 6
835 26
959 617
860 897
957 29
499 380
624 336
571 514
894...

output:

0
0
0
287
0
0
33
0
0
143
0
149
86
0
0
0
0
0
0
0
0
0
0
0
0
0
74
0
122
118
0
0
154
0
43
64
0
0
109
0
0
0
0
0
0
0
0
0
234
0
0
0
0
0
0
0
0
134
0
0
0
0
0
0
0
0
0
0
0
0
0
251
5
0
217
79
0
197
0
0
0
0
0
0
344
0
0
0
114
0
0
0
0
0
0
0
132
0
0
106
0
0
154
0
0
0
0
0
12
0
0
197
0
0
0
364
0
0
278
0
0
0
0
214
0
0...

result:

ok 1000 lines

Test #8:

score: 4
Accepted
time: 272ms
memory: 66580kb

input:

300000 299999 300000 0
119860 89604
220032 248899
217470 167415
115209 178541
17744 222012
194933 95132
250403 119590
285723 197533
116433 119033
239556 79221
101542 181227
204869 280362
190725 249874
195300 210446
56483 36796
70849 290323
131912 215370
168307 211689
292879 162090
261890 250137
2542...

output:

0
0
0
0
0
0
0
0
25597
0
0
0
0
0
0
56676
0
0
0
0
0
0
0
0
0
0
0
0
0
25881
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
45569
0
0
0
0
0
0
28040
0
0
0
0
0
4174
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
4882
10903
0
0
0
4074
0
0
0
0
4521
39739
0
0
0
0
0
0
0
0
0
0
17464
0
0
37007
0
0
0
0
16365
1792...

result:

ok 300000 lines

Test #9:

score: 4
Accepted
time: 297ms
memory: 67284kb

input:

300000 299999 300000 0
135987 25485
116943 250558
73197 263779
192918 131715
163234 20995
91792 291082
211725 192197
167168 90575
201580 203499
146305 276328
285882 179947
263555 25091
159431 259200
86494 30655
166566 260194
144295 252054
167730 180410
120666 279563
179924 88339
185420 128741
186006...

output:

0
0
35553
0
0
0
0
0
0
0
0
0
0
0
0
0
0
10860
0
0
0
0
0
47930
0
0
12750
0
0
0
0
0
0
55490
0
0
0
62840
0
0
0
0
0
0
15431
0
0
0
0
0
0
0
32461
0
0
0
0
0
0
0
0
0
1647
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
38095
0
0
0
66049
0
0
0
0
0
0
0
0
47816
0
0
0
0
0
0
0
0
3620
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
37477
0
0
3476...

result:

ok 300000 lines

Test #10:

score: 4
Accepted
time: 466ms
memory: 71852kb

input:

300000 299999 300000 1
50530 25485
74263 250558
216445 263779
229262 131715
122469 20995
71114 291082
59833 192197
198561 90575
175138 203499
137861 276328
97179 179947
246275 25091
255224 259200
247783 30655
166566 260194
129319 252054
199963 180410
89270 279563
113229 88339
105505 128741
186006 71...

output:

0
0
0
39303
0
0
0
0
0
0
0
0
0
1265
0
0
59287
0
0
70758
0
0
0
0
29914
0
0
0
0
0
0
0
0
0
65567
0
0
0
0
0
0
0
2302
0
35076
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
59196
0
71217
0
0
0
0
0
0
0
0
59200
0
60965
0
0
0
0
0
0
0
9311
0
14725
37109
0
0
0
0
0
0
0
0
0
0
0
0
0
23413
0
0
0
7281
0
0
0
0
0
0
0
0
0
0
12384
...

result:

ok 300000 lines

Test #11:

score: 4
Accepted
time: 471ms
memory: 71316kb

input:

300000 299999 300000 1
105315 58927
199143 104095
53281 3297
91007 122976
26836 264381
254351 82623
191864 170300
261557 81791
295811 228552
129002 152417
131420 266283
291964 212472
294722 114168
256263 120622
17062 23132
160434 92207
267709 208547
298638 215865
112278 41520
32935 58444
54839 15354...

output:

0
0
84882
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
39425
0
0
0
0
0
50119
0
7781
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
11018
0
30641
0
0
0
0
0
0
61879
6880
0
0
0
48857
14806
0
0
0
0
0
0
0
0
0
0
31138
0
0
0
0
14725
0
0
0
0
0
0
0
49009
0
0
0
0
0
0
10737
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 300000 lines

Test #12:

score: 4
Accepted
time: 646ms
memory: 72112kb

input:

300000 299999 300000 2
83545 106978
279409 160828
225289 201065
175494 286493
53119 117122
219548 108619
247311 187864
44433 13477
271874 257415
156890 48420
199900 13571
291826 297765
163364 29797
104744 81803
65994 290261
272112 43473
4917 222096
116240 45958
24647 210230
234421 131569
245870 2542...

output:

0
0
66607
74724
70206
75795
59595
59233
45531
61832
77311
83480
81239
40712
31712
55796
82533
88129
21890
91518
55333
64434
89586
55219
68842
75413
57941
56150
90882
74648
88803
66605
55995
7107
69149
83359
57141
98164
72381
84304
76447
45280
87138
67377
83611
50908
74441
40402
60402
65827
56600
420...

result:

ok 300000 lines

Test #13:

score: 4
Accepted
time: 643ms
memory: 72724kb

input:

300000 299999 300000 2
42694 5919
233753 208624
298972 200
145831 246104
170961 196752
53123 84377
243290 84026
175608 170733
86850 267475
20379 22208
217329 285271
174927 231645
195565 183730
102530 11286
249993 296927
237242 135781
26837 264304
159224 160280
145584 22385
204855 16145
299780 112241...

output:

0
15678
18598
33396
71490
87953
25917
89765
17095
20791
87139
57758
69197
53116
54325
58825
76979
56357
61965
39020
64921
82350
58333
77622
60487
77709
77995
45316
34363
85895
76098
47082
86447
83949
99340
87482
87947
48318
19739
73066
67480
45873
36619
87972
36870
50172
57204
58601
51152
77070
8229...

result:

ok 300000 lines

Test #14:

score: 4
Accepted
time: 631ms
memory: 72424kb

input:

300000 299999 300000 2
299429 59788
33414 91452
13199 244967
200868 39408
123801 138227
34708 134628
78825 222495
35926 137265
234751 281096
257045 290776
4439 23234
149097 4282
186997 75561
180075 175948
40401 18811
158096 175767
185235 162834
41396 137905
53367 209942
147963 8968
299866 36207
9976...

output:

0
57218
26090
61233
40579
71427
24119
37438
57748
86052
78359
60295
69216
42932
73881
20550
73060
33958
50769
96326
73515
69212
46543
55436
79205
30448
77768
70707
20660
67480
72940
29204
54144
69984
75441
71634
21971
82659
37181
21572
76164
60715
69775
58721
43155
74043
58223
35245
73721
64284
7126...

result:

ok 300000 lines

Test #15:

score: 4
Accepted
time: 282ms
memory: 59988kb

input:

300000 600000 300000 0
244118 12137
40628 141434
145696 81337
261701 146002
29886 274425
134461 119718
196776 30506
99688 122305
13746 297575
159887 162482
100927 62088
53112 198002
122646 194884
60124 292015
23883 12583
54417 191385
223909 113104
233666 295957
65122 125406
241520 110638
294939 9381...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
12541
14138
0
0
48119
0
0
0
0
0
0
0
0
6004
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
19465
27113
0
0
0
0
0
0
19201
0
0
0
4883
0
0
2758
0
0
0
4292
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
14516
6786
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
3706
0
0
0
0
11044
0
0
18227
0
...

result:

ok 300000 lines

Test #16:

score: 4
Accepted
time: 281ms
memory: 61128kb

input:

300000 600000 300000 0
198085 5828
251591 242313
35019 219742
254963 121360
78053 160021
83358 13018
67984 259528
103610 199630
252240 255815
65283 259374
138308 103082
218631 53361
113703 166116
16675 130610
434 164468
125541 156802
216641 244426
284380 45621
30854 36049
9292 63716
168373 138971
65...

output:

0
0
0
0
0
33972
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
57895
0
0
0
0
0
0
0
0
0
0
0
56932
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
5420
0
0
0
0
3551
0
0
0
25580
0
0
0
0
0
0
0
0
0
0
0
20230
0
15027
0
0
0
0
0
0
0
0
0
0
0
0
0
9429
4968
0
0
11633
0
0
0
0
0
0
0
0
1487
0
0
0
0
0
0
0
0
0
0
0
0
0...

result:

ok 300000 lines

Test #17:

score: 4
Accepted
time: 387ms
memory: 62744kb

input:

300000 600000 300000 1
171792 128517
62873 293432
23500 74076
54541 127483
264886 281654
246000 62220
36218 184976
78088 295694
220871 140242
199695 84962
87580 203054
167391 259036
246905 138200
42622 35735
225318 257860
178161 94257
254000 298812
287649 103764
187010 154132
205522 87233
176035 643...

output:

0
0
58387
0
23304
0
0
0
0
0
25189
0
0
0
0
0
0
0
0
0
24435
0
0
33698
0
0
0
0
0
0
0
0
0
0
0
0
0
0
52426
0
0
0
0
0
0
0
0
0
0
0
0
70821
0
0
0
0
9007
0
0
0
52375
0
0
0
0
26720
0
0
0
0
44809
0
0
0
10964
0
0
0
0
0
0
0
34651
0
34364
0
0
0
0
0
0
23257
0
22009
0
33319
0
0
0
0
0
0
31328
0
0
0
0
0
0
0
0
0
28820...

result:

ok 300000 lines

Test #18:

score: 4
Accepted
time: 414ms
memory: 64088kb

input:

300000 600000 300000 1
226845 283312
262795 69450
70790 279199
297694 221389
105795 205735
220746 111894
45853 235434
269419 121920
137849 122013
138441 26591
281726 112487
100339 281848
211900 201081
291737 50429
291261 116843
297775 188393
159200 23585
226347 109130
200913 267904
136409 147513
448...

output:

0
0
0
0
0
0
0
0
0
0
0
57191
0
0
0
0
0
46636
0
0
0
0
0
0
0
0
0
0
0
0
0
0
32712
0
0
0
0
0
0
0
0
0
50613
0
0
0
0
0
32368
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
13990
0
6061
58255
0
0
0
0
0
0
46926
0
5602
0
0
0
0
0
0
0
0
0
0
0
0
0
10864
0
0
0
0
12758
0
0
0
0
0
0
0
50814
0
0
0
0
0
0
0
0
16269
0
25294
0
0
...

result:

ok 300000 lines

Test #19:

score: 4
Accepted
time: 422ms
memory: 62944kb

input:

300000 600000 300000 1
176875 32781
265958 98428
150310 228234
29801 61801
251074 276731
216522 127975
247977 296068
277362 118264
25947 209879
97856 205876
145499 173835
226133 258612
76548 189495
245052 225985
188691 260436
129665 224803
44822 111641
222544 282697
74508 211766
212358 108236
25084 ...

output:

0
39024
1680
0
0
0
0
35913
0
0
0
0
0
0
0
74023
0
0
0
0
0
0
0
0
0
0
0
0
0
55843
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
38368
0
0
0
0
0
0
0
0
0
0
0
26407
0
0
80746
0
0
0
11471
0
0
712
0
0
0
0
0
0
0
0
65174
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
11100
0
0
0
0
0
0
0
0
26717
0
10931...

result:

ok 300000 lines

Test #20:

score: 4
Accepted
time: 616ms
memory: 65160kb

input:

300000 600000 300000 2
32180 18023
299482 269995
8336 124262
37621 242709
247884 21911
130339 234248
193470 197198
21819 58300
140320 84680
40289 64302
106711 185183
284273 292271
44709 221984
194087 100752
139352 214225
214480 51709
183557 294513
297869 68679
23425 4489
228752 144959
266345 8430
26...

output:

0
0
63102
92033
65023
60607
83946
65426
77616
58693
85581
87949
19461
82290
33709
76560
72253
70690
65892
59336
66657
91399
47734
57080
56541
19449
50840
70831
49043
78918
52274
61022
67004
85762
24811
85362
76402
41515
77249
44016
70376
48979
81794
26956
48317
60400
38905
65779
54698
66538
66474
47...

result:

ok 300000 lines

Test #21:

score: 4
Accepted
time: 572ms
memory: 63940kb

input:

300000 600000 300000 2
180732 103425
2562 142367
193567 230585
252284 290617
198008 106006
116499 35932
191096 179640
119660 127479
52505 190893
145832 45833
238203 42230
17759 268746
191386 48423
35877 63191
293170 179562
223436 205987
29949 24954
18268 57497
224656 291447
226921 286261
188427 2610...

output:

0
23505
67373
59281
68605
37713
51614
80783
54966
66236
86961
56633
83117
81532
92015
76213
26472
63128
83415
87545
19443
60924
76857
88367
60460
76268
92945
56317
51628
55073
35473
43953
92092
89267
87342
75711
59483
89470
72429
47369
42149
75387
57001
70263
78425
31773
36188
56786
43516
38925
7720...

result:

ok 300000 lines

Test #22:

score: 4
Accepted
time: 588ms
memory: 63980kb

input:

300000 600000 300000 2
74142 296514
53177 97746
271451 290456
210796 26274
21651 272096
28710 85535
60794 186984
74214 252781
152653 121168
241132 18782
253608 83873
135737 99357
39269 81396
251844 23789
19468 239125
144830 86868
289323 191539
192912 38646
295137 142971
208203 142655
110043 243519
2...

output:

0
0
41187
17262
85703
22021
67937
40214
35496
59125
62440
15205
75741
59426
72466
68490
97261
52937
34792
43358
18747
73309
34367
92166
22897
77954
59597
91718
64832
38464
84784
72245
87544
64376
52581
27795
56610
79522
58076
86690
88775
58753
53790
88178
68469
16511
70965
75868
65902
91932
79810
85...

result:

ok 300000 lines

Test #23:

score: 4
Accepted
time: 547ms
memory: 64680kb

input:

300000 600000 300000 2
136352 68511
9080 147227
152585 5564
77952 244320
232690 105310
32256 251227
116367 106412
272152 288222
210054 185895
51932 19917
68078 218069
129822 291903
157850 181684
46352 186424
103084 211944
170579 269033
142704 133552
18521 292353
240152 21544
270551 239384
290371 417...

output:

0
15347
53686
85356
84395
57965
75179
59396
93094
62092
75938
78721
66547
69950
56728
46106
91933
21651
92149
26357
97724
65226
94543
85116
41223
69306
54115
72241
45932
86626
34398
92988
85426
31883
59661
81006
80997
91127
66428
59926
49310
46489
49748
38827
62624
28800
51025
57556
90889
71153
9358...

result:

ok 300000 lines

Test #24:

score: 4
Accepted
time: 592ms
memory: 64236kb

input:

300000 600000 300000 2
37878 27983
65891 98771
298019 273825
247111 150813
147892 233627
38224 271653
266506 122817
34397 240692
48028 267152
42431 109120
123150 79146
109297 263470
186170 187577
284930 284357
191267 178407
17838 9643
82893 198311
133741 186574
143289 159843
22697 77644
4700 93151
3...

output:

0
0
59278
65966
44534
58918
40378
63429
95426
32015
47258
79889
26387
81867
77762
62855
87587
66450
83531
39871
89580
33570
59539
61721
79129
34404
75780
46913
88453
84775
27559
39627
50753
43436
35016
79796
83267
66962
14275
80173
54305
65882
78818
17430
31705
54746
84474
56907
79670
47136
46860
64...

result:

ok 300000 lines

Test #25:

score: 4
Accepted
time: 553ms
memory: 65292kb

input:

300000 600000 300000 2
50585 293163
79271 38509
31579 233972
230155 61811
29402 95569
185759 63847
136283 22010
61965 61901
151769 252473
142452 186749
35359 107682
7522 11867
181122 239242
288058 166677
171106 172630
108204 85008
239702 49329
146360 1955
197598 18920
285575 206998
134401 297858
164...

output:

0
0
69906
36487
65265
76073
52873
66600
58086
55751
25637
85689
92204
80251
76988
69239
18556
59994
66123
65826
68385
86552
62139
93013
29057
78680
64109
72384
35752
70697
92694
37263
64062
79565
74752
54356
69154
80406
84693
56759
23801
46544
62180
57287
69580
8006
17077
37812
78440
19910
68743
851...

result:

ok 300000 lines

Extra Test:

score: 0
Extra Test Passed