QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#144248#4924. 蜘蛛爬树1kri35 3592ms152596kbC++146.6kb2023-08-21 16:01:252023-08-21 16:02:39

Judging History

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

  • [2023-08-21 16:02:39]
  • 评测
  • 测评结果:35
  • 用时:3592ms
  • 内存:152596kb
  • [2023-08-21 16:01:25]
  • 提交

answer

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#define ll long long
#define inf 5000000000000000000ll
using namespace std;
ll read(){
	ll x=0;
	char ch=getchar();
	while(ch<'0'||ch>'9')ch=getchar();
	while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	return x;
}
void write(ll x){
	if (x<10){
		putchar(x+'0');
		return;
	}
	write(x/10);
	putchar(x%10+'0');
	return;
}
int n,m,q;
int u[400005],v[400005],first[200005],nxt[400005];
ll a[200005],w[400005];
struct node{
	int id,c,s,t,l;
}d[200005];
bool cmp_c(node a,node b){
	return a.c<b.c;
}
int fa[200005],sz[200005],son[200005];
ll depth[200005];
void dfs1(int now,int f,ll d){
	fa[now]=f,depth[now]=d;
	sz[now]=1;
	son[now]=0;
	for (int i=first[now];i;i=nxt[i])
		if (v[i]!=f){
			dfs1(v[i],now,d+w[i]);
			sz[now]+=sz[v[i]];
			if (son[now]==0||sz[v[i]]>sz[son[now]])son[now]=v[i];
		}
	return;
}
int top[200005],idx,dfn[200005],nfd[200005],dfo[200005];
void dfs2(int now,int f,int t){
	top[now]=t;
	dfn[now]=++idx;
	nfd[idx]=now;
	if (son[now]!=0)dfs2(son[now],now,t);
	for (int i=first[now];i;i=nxt[i])
		if (v[i]!=f&&v[i]!=son[now])dfs2(v[i],now,v[i]);
	dfo[now]=idx;
	return;
}
int lca(int a,int b){
	while(top[a]!=top[b]){
		if (depth[top[a]]<depth[top[b]])swap(a,b);
		a=fa[top[a]];
	}
	if (depth[a]>depth[b])swap(a,b);
	return a;
}
ll dis(int a,int b){
	return depth[a]+depth[b]-2*depth[lca(a,b)];
}
ll ans[200005];
struct Vec{
	ll x,y;
	Vec operator -(const Vec &b)const{
		Vec ans;
		ans.x=x-b.x;
		ans.y=y-b.y;
		return ans;
	}
	bool operator <(const Vec &b)const{
		return (__int128)y*b.x<(__int128)b.y*x;
	}
};
bool cmp_x(Vec a,Vec b){
	return a.x<b.x;
}
Vec make_Vec(ll x,ll y){
	Vec ans;
	ans.x=x,ans.y=y;
	return ans;
}
void ins(vector<Vec> &a,Vec t){
	int l=(int)a.size();
	if (l==0){
		a.push_back(t);
		return;
	}
	if (t.x==a[l-1].x){
		if (t.y>a[l-1].y)return;
		a.pop_back(),l--;
	}
	while(l>1&&((t-a[l-1])<(a[l-1]-a[l-2])))a.pop_back(),l--;
	a.push_back(t);
	return;
}
namespace Case1{
	vector<node> awa[200005];
	int book[200005];
	int sz[200005],sum,rt;
	void get_rt(int now,int fa){
		sz[now]=1;
		int mx=0;
		for (int i=first[now];i;i=nxt[i])
			if (v[i]!=fa&&book[v[i]]==0){
				get_rt(v[i],now);
				sz[now]+=sz[v[i]];
				mx=max(mx,sz[v[i]]);
			}
		mx=max(mx,sum-sz[now]);
		if (2*mx<=sum)rt=now;
		return;
	}
	ll depth[200005];
	vector<Vec> qwq,conv;
	vector<node> ovo;
	void dfs2(int now,int fa,ll d){
		depth[now]=d;
		qwq.push_back(make_Vec(-a[now],2*d));
		for (int i=0;i<(int)awa[now].size();i++)ovo.push_back(awa[now][i]);
		for (int i=first[now];i;i=nxt[i])
			if (v[i]!=fa&&book[v[i]]==0)dfs2(v[i],now,d+w[i]);
		return;
	}
	void dfs1(int now){
		qwq.clear(),ovo.clear();
		dfs2(now,0,0);
		sort(qwq.begin(),qwq.end(),cmp_x);
		conv.clear();
		for (int i=0;i<(int)qwq.size();i++)ins(conv,qwq[i]);
		sort(ovo.begin(),ovo.end(),cmp_c);
		int len=(int)conv.size();
		int p=0;
		for (int i=0;i<(int)ovo.size();i++){
			int id=ovo[i].id,c=ovo[i].c,l=ovo[i].l;
			while(p+1<len&&(conv[p+1]-conv[p])<make_Vec(1,c))p++;
			ans[id]=min(ans[id],2*depth[l]+conv[p].y-conv[p].x*c);
		}
		book[now]=1;
		get_rt(now,0);
		for (int i=first[now];i;i=nxt[i]){
			if (book[v[i]]==1)continue;
			sum=sz[v[i]],rt=0;
			get_rt(v[i],now);
			dfs1(rt);
		}
		return;
	}
	void work(){
		for (int i=1;i<=q;i++)awa[d[i].l].push_back(d[i]);
		dfs1(1);
		return;
	}
}
namespace Case2{
	vector<Vec> tree[524288];
	int p[524288];
	void pushup(int now){
		int pl=0,pr=0;
		while(pl<(int)tree[now*2].size()&&pr<(int)tree[now*2+1].size()){
			if (tree[now*2][pl].x<tree[now*2+1][pr].x)ins(tree[now],tree[now*2][pl]),pl++;
			else ins(tree[now],tree[now*2+1][pr]),pr++;
		}
		while(pl<(int)tree[now*2].size())ins(tree[now],tree[now*2][pl]),pl++;
		while(pr<(int)tree[now*2+1].size())ins(tree[now],tree[now*2+1][pr]),pr++;
		return;
	}
	void build(int now,int nowl,int nowr){
		tree[now].clear();
		p[now]=0;
		if (nowl==nowr){
			int id=nfd[nowl];
			tree[now].push_back(make_Vec(-a[id],2*depth[id]));
			return;
		}
		int mid=(nowl+nowr)/2;
		build(now*2,nowl,mid);
		build(now*2+1,mid+1,nowr);
		pushup(now);
		return;
	}
	ll ask(int now,int nowl,int nowr,int lt,int rt,int c){
		if (nowl>=lt&&nowr<=rt){
			while(p[now]+1<(int)tree[now].size()&&(tree[now][p[now]+1]-tree[now][p[now]])<make_Vec(1,c))p[now]++;
			return tree[now][p[now]].y-tree[now][p[now]].x*c;
		}
		int mid=(nowl+nowr)/2;
		ll s=inf;
		if (mid>=lt)s=min(s,ask(now*2,nowl,mid,lt,rt,c));
		if (mid+1<=rt)s=min(s,ask(now*2+1,mid+1,nowr,lt,rt,c));
		return s;
	}
	void work(){
		build(1,1,n);
		for (int i=1;i<=q;i++){
			int x=d[i].s;
			while(x!=0&&depth[x]>depth[d[i].l]){
				ans[d[i].id]=min(ans[d[i].id],ask(1,1,n,dfn[x],dfo[x],d[i].c)-2*depth[x]);
				x=fa[top[x]];
			}
			x=d[i].t;
			while(x!=0&&depth[x]>depth[d[i].l]){
				ans[d[i].id]=min(ans[d[i].id],ask(1,1,n,dfn[x],dfo[x],d[i].c)-2*depth[x]);
				x=fa[top[x]];
			}
		}
		return;
	}
}
namespace Case3{
	vector<pair<ll,ll>> qwq[200005];
	ll ask(int c,int l,int r){
		ll ans=inf;
		for (int i=l;i<=r;i++)
			for (int j=0;j<(int)qwq[i].size();j++)
				ans=min(ans,qwq[i][j].second+qwq[i][j].first*c);
		return ans;
	}
	void work(){
		for (int i=1;i<=n;i++){
			int x=i;
			while(x!=0){
				qwq[dfn[x]].push_back(make_pair(a[i],2*(depth[i]-depth[x])));
				x=fa[top[x]];
			}
		}
		for (int i=1;i<=q;i++){
			int x=d[i].s;
			while(x!=0&&depth[x]>depth[d[i].l]){
				ans[d[i].id]=min(ans[d[i].id],ask(d[i].c,max(dfn[top[x]],dfn[d[i].l]),dfn[x]));
				x=fa[top[x]];
			}
			x=d[i].t;
			while(x!=0&&depth[x]>depth[d[i].l]){
				ans[d[i].id]=min(ans[d[i].id],ask(d[i].c,max(dfn[top[x]],dfn[d[i].l]),dfn[x]));
				x=fa[top[x]];
			}
		}
		return;
	}
}
int main(){
	n=read(),m=read(),q=read();
	for (int i=1;i<=n;i++)a[i]=read();
	for (int i=1;i<n;i++){
		u[i]=read(),v[i]=read(),w[i]=read();
		nxt[i]=first[u[i]],first[u[i]]=i;
		u[i+n]=v[i],v[i+n]=u[i],w[i+n]=w[i];
		nxt[i+n]=first[u[i+n]],first[u[i+n]]=i+n;
	}
	dfs1(1,0,0);
	dfs2(1,0,1);
	for (int i=1;i<=q;i++){
		d[i].id=i;
		ll x=read(),y=read();
		d[i].s=x%n,d[i].t=y%n;
		if (d[i].s==0)d[i].s=n;
		if (d[i].t==0)d[i].t=n;
		d[i].l=lca(d[i].s,d[i].t);
		if (x<y)swap(x,y);
		d[i].c=(x-1)/n-(y-1)/n;
	}
	for (int i=1;i<=q;i++)ans[i]=inf;
	sort(d+1,d+1+q,cmp_c);
	Case1::work();
	Case2::work();
	Case3::work();
	for (int i=1;i<=q;i++)ans[d[i].id]+=depth[d[i].s]+depth[d[i].t]-2*depth[d[i].l];
	for (int i=1;i<=q;i++)write(ans[i]),putchar('\n');
	return 0;
}

詳細信息

Subtask #1:

score: 3
Accepted

Test #1:

score: 3
Accepted
time: 6ms
memory: 45844kb

input:

97 99 1000
763118300 558295517 80676328 362318619 473105413 468927175 311496507 936935430 176032966 304576040 308583326 681580095 549392233 518152994 829474320 751189715 542810029 587869244 878512027 530678371 832766129 535259635 799122942 596982955 884696876 605325753 495661541 506105495 561218313 ...

output:

6130845802041
10806758605627
3440559556796
5426989115608
4458875959622
1566659300400
7908007295597
1846030561682
5112206409383
6968388472340
4706970599850
5270158948178
4633066810868
3176122148295
2331646415266
961435137842
14353365296423
9675072605938
4256954122467
7333255321628
8376795894537
12319...

result:

ok 1000 lines

Test #2:

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

input:

96 100 1000
31199641 534644486 57980198 794620020 322548308 524438614 467991232 68617179 243820212 229414440 471419229 316085673 271698528 136252783 926625435 615138376 200446739 551914057 483498389 879166147 512229523 45850421 337184110 799426876 46405170 427929494 235848997 861270528 291868400 616...

output:

2436336301732
4467388472930
6498834342013
6450642313333
4049880787954
7509100670176
5831628235154
4150554274586
3112250048344
202594784082
2974050754796
8714737807242
7727115169865
1321297431165
3071603311467
4662413775237
5469193332429
2306749862693
6240860740176
1297819731517
5602374629655
5876108...

result:

ok 1000 lines

Test #3:

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

input:

96 100 1000
557703101 38662752 91559144 406758463 248251717 279124287 667387330 272252891 892434115 281731667 162886140 786660171 350559478 909940602 476034354 78826379 748607300 381191755 708777514 223906483 954905399 405424569 356033791 565979037 5787205 21241249 399771402 280058652 527147793 5875...

output:

80606469890
86777173467
35481695596
11498756054
87983213070
37171191055
33172639202
31451029430
105454750479
31626589074
105218154775
46986908645
14488184465
20368758481
41150521804
57639739744
45269689956
24620398400
51392609182
44732144926
72097558763
13572235163
78364419227
40255815091
1195379951...

result:

ok 1000 lines

Test #4:

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

input:

96 96 1000
651436202 969634688 411838043 313319930 906863003 709869271 467187062 352351954 116039480 172098032 933097773 469945118 162439715 767382758 713254949 387661957 387494696 343642279 730353853 607472395 431993920 231539946 570437226 454446439 941394569 230535263 758579901 173778951 636556431...

output:

81136576805
65057090263
57308140599
70187240654
42682272024
83341639885
53487742661
53219947761
14656518493
18143524741
27930061212
75815621849
67528908552
39936561353
44548681818
122544815339
64143328818
13510734748
16412423500
108236922255
83503599273
53331146110
59331932211
93957710008
3825533077...

result:

ok 1000 lines

Test #5:

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

input:

100 97 1000
9442498 799978686 853182282 938513473 647407813 233204982 473300672 884708491 641608620 453797741 412704210 204494322 711344505 287815571 401113141 110034416 590478367 831110886 255614524 234577289 759353531 774504637 366342991 154214800 692604750 308540773 768713312 121270668 425512518 ...

output:

5006945326
9445360831
13045856109
4494648380
6833826505
3769548416
11380661054
5754815524
8246147623
4801077020
5798520769
1392753490
6948207422
12106173499
6097834765
4210216111
3541517785
5402770609
8790748574
10564152311
2826265999
5688050930
7790838243
2760570076
4835335024
5099967138
3178901350...

result:

ok 1000 lines

Test #6:

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

input:

100 100 1000
72360333 314738290 34206178 541145218 174183915 396182816 34673830 913434757 537587312 731274646 498514633 251108131 102959912 646618466 457048174 475505598 769612876 452196872 718739596 624410437 9031420 286458655 569299852 299007318 306647081 98662275 920437282 210801779 674405507 219...

output:

3655918495
8154487755
14137574021
9267685665
7011313073
12013474026
11488238672
8912382325
14741526855
17840835926
8748441239
7607949288
7949030269
10402650219
7895349896
9942798476
19632481428
6001424701
5150011606
14328944041
7536672479
10941755235
8915887826
11121022173
5570869661
5489621389
7171...

result:

ok 1000 lines

Test #7:

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

input:

100 100 1000
671289501 901524700 187943785 477991411 752983691 647246158 953320691 934684418 412368667 925367409 762075316 358848462 963075530 457549089 783006165 5363230 270806670 315603863 281313188 630063184 613102269 512390085 496057389 735900160 98801654 915737591 295267905 169463128 895274860 ...

output:

109982431024
38431175833
69772178732
48480356522
11451380583
20622728312
34853416584
49223376377
50708590192
23464488129
66396102290
49072787090
63071461232
100259758746
39605337609
43518034110
69171797185
76120124501
31732771736
43824267429
50401683487
18812219611
17592704047
40305088337
8902132735...

result:

ok 1000 lines

Test #8:

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

input:

100 100 1000
97012332 782222818 959933898 427265795 145416034 1879121 649904335 612684991 536487830 163534103 503165874 529288026 317196350 758782134 932469419 45296081 275446181 306725071 736168208 601979715 145679830 269223691 287672389 93736686 102440922 49242307 14300820 7040380 666185124 780231...

output:

43197564487
61281841688
44768770079
49385322040
35679440075
61129947858
71570620926
54095812113
65913522420
61326476305
50331061951
39723327870
52634647963
37572255373
44983995360
20296010788
65756945356
16562779626
52036714858
19671474013
46849723315
81935125579
28823217661
58491548742
63997977890
...

result:

ok 1000 lines

Test #9:

score: 0
Accepted
time: 0ms
memory: 41888kb

input:

1 2 5
1000000000
1 1
1 2
2 1
2 2
1 1

output:

0
1000000000
1000000000
0
0

result:

ok 5 lines

Test #10:

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

input:

2 1 5
2 1
1 2 1000000000000
1 1
1 2
2 2
1 1
2 1

output:

0
1000000000000
0
0
1000000000000

result:

ok 5 lines

Subtask #2:

score: 5
Accepted

Dependency #1:

100%
Accepted

Test #11:

score: 5
Accepted
time: 24ms
memory: 46280kb

input:

4968 1000000000 4947
35398 17280 28501 30106 20289 12704 8742 38872 40600 32757 4709 49509 18925 8232 12657 5856 35298 16182 34878 29788 22757 3667 6147 33251 10280 21807 9932 43760 25234 21837 2000 42316 42227 30480 48217 18842 12065 3569 33962 10434 9965 6816 46030 14352 7696 39388 37027 2641 4927...

output:

27171080853044
16475800995047
47858729923137
38839226619025
68829717991555
66238455750161
69391451769289
61015426629738
34984939995941
46894448125681
66492516637760
84920329286569
37539473678478
26863746705396
24228771920185
20757319444368
62547461012321
29240639472051
33274823206812
29763531850641
...

result:

ok 4947 lines

Test #12:

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

input:

4981 1000000000 4953
151742 15587 142065 128832 78714 10584 76914 106299 31568 52704 188707 28416 12984 61582 32999 186530 140703 147751 47543 175894 7752 191829 63929 114837 92045 50348 9699 45344 118713 116457 164914 29571 114745 130797 196228 187265 10152 1229 3383 97088 55723 174984 127564 39677...

output:

39175214953945
26200723643487
46943276265557
28283755650448
27784497704623
47477663513975
25153955655196
34658568119723
36390677477885
33283868432417
45462962712646
12634898326814
12553555762696
29763136584312
59969070638872
32014006456467
32113426391414
28135433219086
47248493737483
56523379856914
...

result:

ok 4953 lines

Test #13:

score: 0
Accepted
time: 24ms
memory: 44420kb

input:

5000 1000000000 5000
7709 49516 81404 252939 337304 22843 327351 119119 469819 411352 375305 439834 224988 108405 27787 377575 382742 28074 255120 112472 244686 267973 224537 126626 101857 58364 298859 89790 474293 329321 441367 108105 278126 181944 246403 415680 273376 409094 169364 339149 196519 3...

output:

224644098442606
54861440986602
467147774410064
30362267317869
296379104994566
473075396075640
122083966788904
272566888272189
216858876719405
215746767255802
347849462280931
520897037387102
19480747175957
76784800656757
227716313122157
66425147109923
371507621482925
352677699283994
15598007683275
59...

result:

ok 5000 lines

Test #14:

score: 0
Accepted
time: 41ms
memory: 51328kb

input:

5000 1000000000 5000
253265 289565 480218 817881 388719 980412 67414 134135 762536 232380 406531 204614 200869 487447 967573 799195 802628 529421 333062 23170 711366 781842 202481 635401 256687 178162 589701 440119 691724 314358 566777 600174 401029 556684 811778 442351 501890 561627 65781 824606 38...

output:

229741484116980
164175833276967
99443665231144
54979925948709
767846577154984
82615685235989
491961122361479
258830345532802
337194117311972
330754218569722
208052850590856
109736272716532
772091540293926
46512912591879
222739255582971
104104517451050
155728909685296
619218590510841
329616510853980
...

result:

ok 5000 lines

Test #15:

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

input:

5000 1000000000 5000
9165442 10032926 9324284 18687554 9961685 9532269 9821667 10084498 8903944 10118365 9775765 19733471 25638562 9383006 8825736 10428746 9066921 9401601 11694769 9998610 8896431 9186888 9834954 10583130 9321162 8943766 18203176 9463949 9187659 9612570 15398089 9597271 9774891 1006...

output:

3346954835952024
9683326417379824
3034185194974329
5653331361714484
4883637125911652
4144529883528686
1550288375157255
4849179484656607
7780090186793507
8760876193430258
2791370216037543
7961795785990098
3625625101008354
830776458752577
1201598422493424
5284514192781053
4673390841578381
221202738816...

result:

ok 5000 lines

Test #16:

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

input:

5000 1000000000 5000
10328285 10154180 9849852 9978950 9899905 10007975 9932544 9993918 9897530 10042306 9913325 9834599 10081669 9949843 12994559 10008823 9910840 11562770 9903505 10076660 9980716 9890836 9934511 12177770 9904174 9911365 10195395 9827430 9905113 10026600 9830577 9852209 10069231 99...

output:

1647385331743507
5524865815859729
3059643445230206
9470053705989838
9178562810279320
7549445324071426
2027312277087798
8273023856964174
9615573793436228
8112830816194948
8931306355319079
5885476349335756
1381279438337504
8765067046522175
2086999576794297
4002632440712670
7924144870658890
79357254043...

result:

ok 5000 lines

Test #17:

score: 0
Accepted
time: 24ms
memory: 49472kb

input:

5000 1000000000 5000
2513000 70283 123233 147800 2407113 6750 548577 2496501 1589521 382060 1078641 28843 12885 979911 249118 399277 335551 1496141 1161882 94180 1562518 1846018 2023612 688097 1505606 37597 1714464 2071436 2225125 2437519 1190287 1307370 1559871 443072 285850 1245177 429584 1750366 ...

output:

416853386301
245456106087
329277735132
507750960639
544942162618
258694401397
376595479438
395068151898
515513005035
523563370330
378130973019
272463853221
335748583419
223192323740
328497513286
436111548238
380723617773
389134126388
418340678864
415228727699
338316467895
344020792244
444955157605
5...

result:

ok 5000 lines

Test #18:

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

input:

1 2 5
1000000000
1 1
1 2
2 1
2 2
1 1

output:

0
1000000000
1000000000
0
0

result:

ok 5 lines

Test #19:

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

input:

2 1 5
2 1
1 2 1000000000000
1 1
1 2
2 2
1 1
2 1

output:

0
1000000000000
0
0
1000000000000

result:

ok 5 lines

Subtask #3:

score: 0
Time Limit Exceeded

Test #20:

score: 0
Time Limit Exceeded

input:

200000 20 200000
679416469 548913625 468159997 137709609 883140368 682558021 473174374 400192350 124143873 825920417 372498686 851213321 822264481 78195915 5427143 453304163 233551905 810910186 810046144 52603791 282167184 385032797 81387991 747194790 917579656 585184539 12659388 249218417 158295502...

output:


result:


Subtask #4:

score: 0
Time Limit Exceeded

Test #28:

score: 0
Time Limit Exceeded

input:

200000 1000000000 200000
28270302 472359923 262785485 923929785 393684160 761485431 72038469 116384740 426631758 437934930 610834083 455314140 734276543 903544756 220163018 756113376 732404264 947339315 109784905 625451008 794076307 818852312 758007217 124450858 674924509 311761991 507260538 7032362...

output:


result:


Subtask #5:

score: 9
Accepted

Test #36:

score: 9
Accepted
time: 346ms
memory: 94888kb

input:

199918 1000000000 199903
1496 2382 3896 3664 1177 1627 2821 4200 3074 3783 2069 4403 629 2610 4991 4074 3033 2798 4333 3501 3667 3064 663 2821 2818 458 2950 4020 2665 3578 63 4855 4941 3492 2423 4510 1489 1018 4829 1912 3133 3174 309 287 2909 4102 4296 4526 3170 3683 4960 4863 4738 2927 2405 3600 44...

output:

1352416884531
1380463318391
923920163167
1525224977139
1405019709299
869269749781
715671043328
876194052054
1358007874327
127994985855
1230162209719
1532026808855
611656467332
1023855959729
414792924571
1316679734677
827308370883
1265411315424
821484360433
1051517948640
837509712760
582943943131
457...

result:

ok 199903 lines

Test #37:

score: 0
Accepted
time: 390ms
memory: 94472kb

input:

200000 1000 200000
809770918 700177243 142627650 840666719 799717263 288840787 130614153 965150450 584417569 833256629 453961603 553430999 842122932 156970995 233405993 462368588 449589390 97217337 576814616 526506175 16887352 919946415 588340411 47310125 508028561 746882745 289969878 38349443 85588...

output:

1585694392495
706038536805
586801212025
729763504879
1121912701709
602929530934
1384874490966
932809860298
1786651350814
1173133997984
642188971333
1847564817170
874110129257
1634207197990
1165001912684
860420326934
364758620851
736767366986
901294347345
1499330839732
451636930949
1002710230684
1556...

result:

ok 200000 lines

Test #38:

score: 0
Accepted
time: 417ms
memory: 110900kb

input:

200000 1000000000 200000
399998482 399998882 643012112 481981456 399998451 475990021 399997292 399997409 399996369 399998092 399998185 399998416 399998701 399997027 399996347 1000000000 411997672 399996237 399997188 402404134 399996973 399998072 459327897 399997196 399997360 606704265 399997369 3999...

output:

56425935917250335
348929904541748910
43150321666095229
218746357373815571
108846332361563136
211578526026780722
142755080047590213
244555928973138123
59355666550218703
274305014995294225
171177308635990844
94566903236734112
84270300399685207
317423517245573254
902979060499211
14514565807335715
18696...

result:

ok 200000 lines

Test #39:

score: 0
Accepted
time: 408ms
memory: 151980kb

input:

199989 1000000000 199949
5101893 2534711 252776 33497 4575476 620658 35790 1061631 1362697 834917 2062598 2789238 2540552 2557066 725856 2407848 4266144 1731334 653868 4676650 235573 2010805 1576557 922173 617762 1140093 387911 618359 2084018 2717580 9938 4014950 411349 3801906 341206 665844 2556003...

output:

376419619600
353028349944
783455928283
427146243318
508001272847
231025894377
614377184831
496116219491
384142701402
337878147372
528478063399
414595122323
604998898988
244135680083
319848781263
358386785447
481117281935
464006706964
356458898506
260105342030
610113746365
259007651455
414991108424
2...

result:

ok 199949 lines

Test #40:

score: 0
Accepted
time: 326ms
memory: 152596kb

input:

200000 1000000000 200000
1101540 573488 61066 1014872 39283 626062 84341 591377 109026 505272 1339 74452 729192 49315 521939 959958 249731 940337 56264 1071790 609623 239862 57448 809987 464526 111430 226312 124386 673550 421690 211347 45875 138962 705453 739456 464892 44238 52980 905593 205558 5198...

output:

655436303263
616441802310
638361564730
586321577191
519122088245
660130086237
389806954608
241891011597
423594953230
510963332372
630353140994
627262451077
339051346548
308888235187
550167732447
354951509166
308776095000
597351022439
625625736560
772346222022
549689478477
667370706484
319926160326
2...

result:

ok 200000 lines

Test #41:

score: 0
Accepted
time: 0ms
memory: 41112kb

input:

1 2 5
1000000000
1 1
1 2
2 1
2 2
1 1

output:

0
1000000000
1000000000
0
0

result:

ok 5 lines

Test #42:

score: 0
Accepted
time: 1ms
memory: 43448kb

input:

2 1 5
2 1
1 2 1000000000000
1 1
1 2
2 2
1 1
2 1

output:

0
1000000000000
0
0
1000000000000

result:

ok 5 lines

Subtask #6:

score: 0
Time Limit Exceeded

Test #43:

score: 0
Time Limit Exceeded

input:

200000 1000000000 200000
81882094 47220813 43282454 17633207 52769165 4830673 31396360 64793163 9174729 36727563 71268262 24662923 40146030 1430053 62926106 30042905 1330107 81817720 98841078 87766129 51155045 23216268 79896310 66625868 87854925 42976560 86542933 28336449 34932261 19698851 584453 90...

output:


result:


Subtask #7:

score: 18
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Test #63:

score: 18
Accepted
time: 1281ms
memory: 62704kb

input:

49968 1000000000 49902
4944156 4815511 9240823 7764082 994590 2019985 2016609 9208180 4884222 2671715 5813918 8082427 5690017 4750252 6475214 2447878 7680249 8636430 6031922 1028528 2689700 1920015 8635882 5610090 9361349 7547902 5838245 7362790 240533 4193002 8850309 9498339 6763561 8096700 8938068...

output:

147810152409397
230645425302306
160441304695433
238455725485197
151518420272795
89423905495676
264381463305791
26003135435070
141049604858403
296733080938929
124815908476291
103612265239190
294621330837151
37345286479070
173931506215139
338013536841813
141749423526071
176332685271868
100579949751669...

result:

ok 49902 lines

Test #64:

score: 0
Accepted
time: 3592ms
memory: 59988kb

input:

49992 1000000000 49940
2003853 7162895 5073437 4687230 8733918 4891966 9585850 2787024 4490309 8951710 3084011 2017075 6331315 9471938 4634613 7380596 9393089 7480628 8641884 7499894 7617210 7320006 2963810 8874914 1239543 2201128 367683 493261 8804646 2002828 2587756 2537102 5825294 2635981 2317652...

output:

1192124558433116
1981653758398286
131492379503681
1828718161216319
1958322264535191
2718288833339193
5545525628339003
1258671741508850
2038470552100596
158125886432957
7090062507557303
3100175107739547
4892661001763203
1058226003141961
6196281372191372
5857262064868095
5606420153949008
2324906833451...

result:

ok 49940 lines

Test #65:

score: 0
Accepted
time: 3145ms
memory: 64864kb

input:

49998 1000000000 50000
86612478 86619871 86616593 86625839 125331781 89547617 86609503 91605216 108492497 86619067 108490056 102573028 100123774 86612275 108490617 100411209 86619293 108059385 86615859 86615581 86618876 102515951 86618273 108491746 86615096 86608662 86619989 95461459 108495689 10849...

output:

46588007956780978
16912616922030347
68816440058802851
59859890761572687
4324584371603449
41150830836227761
98964682918220242
16463790885070539
26923559929848641
34741982419511508
44081880582162509
16699955791334029
77486763689299350
47644447361354873
20590488138222942
42624882630816855
1943676197576...

result:

ok 50000 lines

Test #66:

score: 0
Accepted
time: 3454ms
memory: 69624kb

input:

49998 1000000000 50000
147276 726692 85428 364478 261162 131999 5975 127116 255850 168671 8771 625319 250764 85078 20478 322021 673710 731815 271166 76570 89 641922 488850 545498 442407 235502 589490 10461 342766 204843 115760 21241 507284 353955 225355 238664 774748 121955 46987 283156 534477 11003...

output:

405732964288
389815059145
366883155022
480576233423
340957673244
276886953621
266040314535
315483568795
377498543215
287967570570
173379088116
425184427202
483249470808
316165910245
232288690777
326506749047
382101599711
319831809610
351707633713
302302658790
329611681562
313791814464
555167428970
1...

result:

ok 50000 lines

Test #67:

score: 0
Accepted
time: 2000ms
memory: 66380kb

input:

50000 1000000000 50000
101262401 100536143 100365435 100184486 100243584 100284228 100198552 100169888 100093151 100108707 100205110 100169179 100143527 100103752 100198232 100161905 100137347 100040613 100060084 100062817 100081982 100106460 100093383 100082173 1000000000 1000000000 100066792 10004...

output:

47901860626149350
52232382847914312
90218649968616572
42631382542909940
36647005348668799
19354952802130848
97004968886549839
72457296305191529
29345838211855395
98177404260939908
68428525460081338
52198364330694788
77047427420663132
90114074853245639
16497709368555684
52426747053589783
459259106355...

result:

ok 50000 lines

Test #68:

score: 0
Accepted
time: 1907ms
memory: 77736kb

input:

50000 1000000000 50000
524803 524795 524761 524776 524784 524341 524752 524739 524406 524723 524693 524102 519665 524065 524676 524710 524647 523226 523524 524248 524386 524653 524588 523964 523483 493454 504537 523362 524045 524572 524540 524663 524639 524320 523998 516523 521071 522484 523255 5212...

output:

520801563887
424710496333
564668062064
519086118087
236559320312
321406462613
379662255710
561248644898
429089082728
278382083590
414240297257
420461694620
287355108541
650311376394
659818333322
375016109570
554437046804
290748686350
502354098558
290351680545
639284778784
619269650687
283577630955
5...

result:

ok 50000 lines

Test #69:

score: 0
Accepted
time: 1933ms
memory: 60772kb

input:

49967 100000000 49939
701117221 588646986 250635677 490819080 359508742 82912689 975640737 148951097 961563837 896611020 819557131 873501952 449957989 404623941 210177503 597538891 917200690 672566561 463554086 287628304 183478309 501551961 334152945 392987668 73509920 772390859 839262537 574096155 ...

output:

1207936031638
118747020859
913818453498
1644050354708
817223329561
706074172118
1672964443553
141066605382
1407145149269
1688560430308
1609407772178
1043340942347
1038662043365
85922400375
500088949508
644923691873
737314327467
815737936927
766241606028
749631859737
1277317624066
387011109167
129041...

result:

ok 49939 lines

Test #70:

score: 0
Accepted
time: 1422ms
memory: 67200kb

input:

49913 1000000000 49979
99810504 99876070 99674859 99671842 121208696 109186471 99585115 115003368 99783969 99704451 99754263 99600541 100684297 99559144 99580001 99741149 99530973 99522901 116531393 100029706 99610891 99694872 99612585 102122420 99797856 99715650 99824358 99846342 99489115 99593830 ...

output:

75021083161705494
3687116444114934
33411361173222204
79126378651836082
56591495019562750
1482076097167512
56522532505669444
80695581931849593
52335904470582196
93704259183420706
4723285457422075
19569230326587661
42900419987961232
27328370250770456
22085284801732060
30297428495631749
974078059303944...

result:

ok 49979 lines

Test #71:

score: 0
Accepted
time: 2557ms
memory: 64904kb

input:

50000 1000000000 50000
95103343 149617502 97279041 103251933 102014267 119508947 98353262 101480638 102415936 97068407 100900889 121682528 103955675 97356468 95203299 100042191 106251861 98783592 98593775 99517269 97086090 121697940 124801062 100042858 101718302 96554305 96694019 98129049 95005801 9...

output:

47008496048832832
6162516818596597
70951257176722118
29100759507151473
88166200321392274
64056598481648073
66156822633782521
66675935261416948
37939987904485364
49032894641764951
3714533953620752
11014195987141948
53746717224033312
17686292264159632
28488972544308603
30657743644699744
11360321361349...

result:

ok 50000 lines

Test #72:

score: 0
Accepted
time: 80ms
memory: 65732kb

input:

50000 1000000000 50000
103326936 219737816 232003032 108252350 99998460 99998868 99999526 99999106 100000799 99999969 99999445 100000048 104592491 99999283 99998538 100001653 99999850 102463592 99998771 100000433 99998474 141904675 100000723 99999604 99999476 99998172 99999577 99998668 99999804 1085...

output:

77396062051816824
74085671312607659
95614601954590434
1170817688923755
68322185067625298
21395762642211971
5865433735431284
87051278899282142
10178618350135518
17930038769889394
66935732691981770
50355134911706497
91271949883795850
22072995466334107
65606069221844581
8650047742615250
902729326985898...

result:

ok 50000 lines

Test #73:

score: 0
Accepted
time: 1466ms
memory: 70392kb

input:

49975 1000000000 49931
84211 55336 252755 15254 246875 187979 49163 126582 104827 58559 36655 17384 81160 253364 81593 1088 6290 14081 251659 4443 118797 60225 53745 162953 15582 244560 117951 269103 42702 6237 50099 3903 21127 72300 9840 56844 214011 45170 68840 3741 273694 180905 197439 63969 8999...

output:

575538275842
300512392765
469007988507
267686303867
349105411769
426565773268
238390907849
587417902212
533805438581
543593700291
366847933070
532552325620
510568807260
496054751124
415287402994
471817548429
466789246262
29802468507
455288062652
310589058150
258539566001
285101078148
570433865779
22...

result:

ok 49931 lines

Test #74:

score: 0
Accepted
time: 2842ms
memory: 73548kb

input:

50000 1000000000 50000
754556 604242 30208 542679 448867 603232 169511 354225 393639 16940 2193 368268 43224 102249 241678 534317 671413 332623 11291 665173 445259 11441 578280 424891 314203 550049 313612 20072 139534 290088 62216 145495 73893 192190 175869 47215 655361 3515 619712 42608 701347 6795...

output:

421930105097
547218226844
543311314309
361472439272
438190520204
509582782153
230599478684
307470715330
309194170439
285783941979
258161362851
537532959643
429828501604
81224380835
188673519826
467110827147
605775726908
316487391961
532219227736
187828657740
567658393497
314324203311
209209137040
19...

result:

ok 50000 lines

Test #75:

score: 0
Accepted
time: 83ms
memory: 73148kb

input:

50000 1000000000 50000
1134165 347193 180933 1053859 2312 372547 1078267 1083658 382385 429520 845927 395979 56002 1225717 5183 967972 32075 9216 287034 751452 628631 7947 130616 668468 381268 494670 63653 785586 63015 1106385 403603 690434 834061 44355 63162 1080532 968842 1138436 352645 340186 112...

output:

349435172399
586604962022
606751966296
387956419936
324606135217
566474644490
481850670002
415647494771
497633859377
242556355951
527762334456
385191095006
290638807846
404327548248
397808031771
263595093054
593329584989
626157577441
353475221277
368014304022
575210926858
504674983709
508778344452
4...

result:

ok 50000 lines

Test #76:

score: 0
Accepted
time: 1916ms
memory: 75356kb

input:

50000 1000000000 50000
274244 273876 274594 271268 273839 274432 274721 268995 270279 273020 273609 274253 273402 274649 274806 263610 265880 267775 267994 272814 272654 259494 271788 274185 273958 272774 272647 274201 274141 274851 274655 262196 233119 253829 265810 265620 264446 264733 265915 2722...

output:

55136692089
250834673323
344674479053
78834875741
236060056920
126799931193
204097179679
123034533236
400642413809
145026515187
220587028923
222928708321
273855371961
222554351044
163751461798
177715135672
177886265475
335250135690
163796577274
275368772016
344319231518
181453404240
287633135961
103...

result:

ok 50000 lines

Test #77:

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

input:

1 2 5
1000000000
1 1
1 2
2 1
2 2
1 1

output:

0
1000000000
1000000000
0
0

result:

ok 5 lines

Test #78:

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

input:

2 1 5
2 1
1 2 1000000000000
1 1
1 2
2 2
1 1
2 1

output:

0
1000000000000
0
0
1000000000000

result:

ok 5 lines

Test #79:

score: 0
Accepted
time: 2018ms
memory: 60880kb

input:

50000 4000000 50000
382301843 633396262 827855850 48475432 887864673 687939704 607616554 120228975 79407125 84139528 423498566 584293361 905756486 849324647 151892270 764293038 694946413 931202330 770860665 393234279 567989976 686902309 361150294 994395718 504779657 289443347 75618549 598869058 3999...

output:

424106350335457
1125014398223421
455079888665385
766178112932568
527984154416466
619833051400100
1123830521865158
1125226434262619
148338745040548
971461232920796
414954093909887
622070581630960
512228784337357
895851145651473
881736770328828
969296466259934
537957040677244
1123619626410926
57196391...

result:

ok 50000 lines

Test #80:

score: 0
Accepted
time: 2176ms
memory: 60808kb

input:

50000 1000000000 50000
3449221 2102673 2176708 696083 2506047 2432759 3297061 3076792 540192 1174 269187 243193 526878 3817928 3323318 2451113 2785608 3544672 707021 382876 3819594 2558361 595693 1282087 2296605 3089284 3989615 2265754 1949186 550386 2291305 899744 2631735 3181412 367832 3727 214611...

output:

508181937298650
46279739241752
1018973544656104
1265677558399170
629480405891489
48385337538677
806138663484583
1042571321208996
818149646972220
569452420814038
123280847744172
1265741747019876
714734464602640
286481219912146
1265727961782487
756563441554218
716054097571375
171322023576204
126565268...

result:

ok 50000 lines

Test #81:

score: 0
Accepted
time: 2254ms
memory: 68724kb

input:

50000 1000000000 50000
99576593 98734697 97524742 97810575 99289324 98135482 97797653 98620702 97695682 163605131 97936493 98333350 98003113 99273070 97575097 98634231 97462634 97943735 97594517 98038106 97630836 100822998 98135923 97939696 106718214 98140511 98659048 97615297 98503308 101723090 992...

output:

82950625033043526
74253135347159837
60884710255754091
84740747428531022
66956889787680848
21526721179617801
46875382323933928
26884330743856575
51455205640946454
86503964949033473
66869460714280650
22310817075948757
20187728367206704
38976799423009773
87817556427002773
38579576546564774
699333023072...

result:

ok 50000 lines

Test #82:

score: 0
Accepted
time: 2328ms
memory: 73492kb

input:

50000 1000000000 50000
447243 16285 126704 6176 53588 87042 261073 395620 76727 336604 47553 487612 219730 46634 431675 305257 1800 19013 214222 2324 18455 394370 442219 419889 171 230338 2889 518616 454899 53901 449709 69183 414430 43 104954 458113 109502 302689 83202 6297 14561 290169 80230 90905 ...

output:

373917380256
378326235442
422123400
72615600
278817150388
375477068213
268375058031
268753664685
223496700
326275942584
88046683618
155838421208
3782880459
294486412398
375408863513
179078632044
261331037610
158744400
350019357893
157523165141
378079747280
191464466775
87594736848
278073519674
31828...

result:

ok 50000 lines

Test #83:

score: 0
Accepted
time: 2270ms
memory: 74984kb

input:

50000 1000000000 50000
233570 4572 265455 26312 194346 256089 156368 192860 91078 252234 27682 172842 31727 92384 16930 162122 84095 911 184949 158481 58631 244106 179366 1656 115521 5587 265185 123234 9568 32678 40157 158757 8050 101042 35141 10232 132569 155735 153746 223237 249962 3881 119542 253...

output:

121669595177
283246371516
278267972133
223194073315
261820205854
321376970576
313046043702
180048804510
362418761931
223964070367
405564550265
248415535249
257550775258
254709096137
166837269756
295074013994
277887325188
387123587634
330498043181
342157238429
229396986326
362931606211
239179644224
3...

result:

ok 50000 lines

Test #84:

score: 0
Accepted
time: 2329ms
memory: 65948kb

input:

50000 1000000000 50000
116148600 96494196 96846514 102901566 95839781 96755789 97247372 114734508 95819490 95644709 95633495 99580181 106565039 98930619 95824589 98207917 96246800 97927785 97962897 100846363 95697463 95758986 106405173 95904121 101525399 98757319 98937921 96940376 102559409 98572697...

output:

76042316296232337
79190014018617130
50958903488352320
45733597598894250
84359580387743721
7411365772197816
82484049041815905
51983488354616909
92619695827498568
84091249944402926
30168374771314228
62304529338472472
46777277486973575
42293296273527556
81745618788159884
12278184899304622
1844182841943...

result:

ok 50000 lines

Subtask #8:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

0%