QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#594411#8579. 경찰과 도둑Matutino0 588ms72096kbC++143.5kb2024-09-27 23:14:162024-09-27 23:14:16

Judging History

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

  • [2024-09-27 23:14:16]
  • 评测
  • 测评结果:0
  • 用时:588ms
  • 内存:72096kb
  • [2024-09-27 23:14:16]
  • 提交

answer

#include<bits/stdc++.h>
#define reg register
#define int long long
const int N=2e5+10;
int n,q,Fa[20][N],dep[N],dis[N];
std::vector<std::pair<int,int>> G[N];
#define ll __int128
struct Node{
	int x,y;
	inline bool operator<(const Node &A)const{return x!=A.x?x<A.x:y<A.y;}
	inline bool operator>(const Node &A)const{return x!=A.x?x>A.x:y>A.y;}
	inline Node operator+(const int &A)const{return {x+A,y};}
}f1[N],f2[N],g[N];
struct Fac{
	int x,y;
	inline bool operator<(const Fac &A)const{return (ll)x*A.y<y*A.x;}
	inline bool operator>(const Fac &A)const{return (ll)x*A.y>y*A.x;}
	inline void prt(){std::cerr<<"Fac "<<x<<" "<<y<<"\n";}
};
#define mp std::make_pair
inline void add(reg int u,reg int v,reg int w){G[u].push_back({v,w}),G[v].push_back({u,w});}
void dfs1(reg int u,reg int fa=0){
	f1[u]=f2[u]={0,-1},dep[u]=dep[Fa[0][u]=fa]+1;
	for (reg int j=1;j<19;j++) Fa[j][u]=Fa[j-1][Fa[j-1][u]];
	for (auto [v,w]:G[u]) if (v^fa){
		dis[v]=dis[u]+w,dfs1(v,u); reg Node F=f1[v]+w; F.y=v;
		if (F>f1[u]) f2[u]=f1[u],f1[u]=F; else f2[u]=std::max(f2[u],F);
	}  
}
void dfs2(reg int u,reg int fa=0){
	for (auto [v,w]:G[u]) if (v^fa){
		g[v]=std::max(g[u],f1[u].y==v?f2[u]:f1[u])+w;
		g[v].y=u,dfs2(v,u);
	}
}
inline int LCA(reg int x,reg int y){
	if (dep[x]<dep[y]) std::swap(x,y);
	for (reg int i=18;i>=0;i--) if (dep[Fa[i][x]]>=dep[y]) x=Fa[i][x];
	if (x==y) return x;
	for (reg int i=18;i>=0;i--) if (Fa[i][x]^Fa[i][y]) x=Fa[i][x],y=Fa[i][y];
	return Fa[0][x]; 
}
inline int jump(reg int x,reg int d){
	// std::cerr<<"jump "<<x<<" "<<d<<"\n";
	for (reg int i=18;i>=0;i--) if (d>>i&1) x=Fa[i][x]; return x;}
inline int get(reg int u,reg int ban){
	// std::cerr<<"get "<<u<<" "<<ban<<"\n";
	Node res=f1[u].y==ban?f2[u]:f1[u];
	if (g[u].y!=ban) res=std::max(res,g[u]); return res.x;
}
inline Fac query(reg int x,reg int y,reg int v1,reg int v2){
	reg int p=LCA(x,y),D=dep[x]+dep[y]-dep[p]-dep[p];
	reg Fac val,ans={0,1};
	// std::cerr<<x<<" "<<y<<" "<<v1<<" "<<v2<<"\n";
	auto check=[&](reg int d)->bool {
		reg int u,d1,d2;
		if (d<=dep[x]-dep[p]){
			u=jump(x,d),d2=dis[x]-dis[u],d1=dis[y]+dis[u]-dis[p]-dis[p];
			if (d2*v1>=d1*v2) return val={0,1},0; 
			reg int mxd=get(jump(x,d),d==dep[x]-dep[p]?jump(y,dep[y]-dep[p]-1):jump(x,d+1));
			if (v1<=v2) return val={d1+mxd,v1},1;
			// std::cerr<<"<< "<<d<<" "<<mxd<<"\n"; 
			return val=std::min(Fac{d1+mxd,v1},Fac{d1-d2,v1-v2}),Fac{d1+mxd,v1}<Fac{d1-d2,v1-v2};
		}else{
			u=jump(y,D-d),d2=dis[x]+dis[u]-dis[p]-dis[p],d1=dis[y]-dis[u];
			if (d2*v1>=d1*v2) return val={0,1},0; 
			reg int mxd=get(jump(y,D-d),jump(y,D-d-1));
			if (v1<=v2) return val={d1+mxd,v1},1;
			return val=std::min(Fac{d1+mxd,v1},Fac{d1-d2,v1-v2}),Fac{d1+mxd,v1}<Fac{d1-d2,v1-v2};
		}
	};
	reg int L=0,R=D-1,nw=-1;
	while (L<=R){
		reg int mid=L+R>>1;
		if (check(mid)) L=mid+1,nw=mid;
		else R=mid-1;
	}
	// std::cerr<<nw<<"\n";
	if (nw>-1) check(nw),val.prt(),ans=std::max(ans,val);
	if (nw+1<D) check(nw+1),val.prt(),ans=std::max(ans,val);
	return ans;
}
#undef int
std::vector<std::array<long long, 2>> police_thief(std::vector<int> A, std::vector<int> B, std::vector<int> D, std::vector<int> P, std::vector<int> V1, std::vector<int> T, std::vector<int> V2){
	n=A.size()+1,q=P.size(); std::vector<std::array<long long, 2>> C(q);
	for (reg int i=1;i<n;i++) add(A[i-1]+1,B[i-1]+1,D[i-1]);
	dfs1(1),dfs2(1); 
	for (reg int i=0;i<q;i++){
		auto [x,y]=query(T[i]+1,P[i]+1,V1[i],V2[i]);
		C[i][0]=x,C[i][1]=y;
	}	
	return C;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

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

input:

2 1
0 1 1
1 1000000 0 1000000

output:

moonrabbit2
1 1000000

result:

ok 2 lines

Test #2:

score: 0
Wrong Answer
time: 11ms
memory: 46048kb

input:

5000 5000
0 1 33612
1 2 364922
2 3 690361
3 4 936229
4 5 481430
5 6 990836
6 7 530318
7 8 809490
8 9 220360
9 10 2821
10 11 245681
11 12 545618
12 13 439038
13 14 750751
14 15 712817
15 16 178970
16 17 906394
17 18 294106
18 19 413472
19 20 395779
20 21 208193
21 22 374509
22 23 467478
23 24 211975
...

output:

moonrabbit2
74345126 12231
2141302600 31817
977131971 525511
1153824435 206157
1093602993 252970
1152577327 29996
2425408314 297482
727256921 386859
1986719014 394159
838512644 275337
2405376736 566803
973664128 531078
685039389 616324
2418996397 253035
1655204376 673807
2063972802 44840
1230097402 ...

result:

wrong answer 5th lines differ - expected: '384608145 68719', found: '1153824435 206157'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Wrong Answer

Test #95:

score: 0
Wrong Answer
time: 588ms
memory: 72096kb

input:

100000 100000
0 1 213617
1 2 967030
2 3 775032
3 4 505755
4 5 584670
5 6 478373
6 7 934089
7 8 274771
8 9 94919
9 10 201468
10 11 555776
11 12 530533
12 13 812779
13 14 78486
14 15 35907
15 16 613290
16 17 115129
17 18 414055
18 19 290156
19 20 373454
20 21 778454
21 22 337075
22 23 555529
23 24 974...

output:

moonrabbit2
48884074951 292792
13147147341 458303
13479380354 128689
27340670843 215559
28148697691 499660
13341326497 259690
48595680094 307094
44557181788 462428
32961396067 566507
49578768583 860478
41272537702 153615
40820157590 454333
26803960218 240315
45525041839 174790
49810508741 249866
435...

result:

wrong answer 4th lines differ - expected: '1225398214 11699', found: '13479380354 128689'

Subtask #4:

score: 0
Wrong Answer

Test #100:

score: 0
Wrong Answer
time: 323ms
memory: 61644kb

input:

100000 100000
0 1 308120
0 2 334554
0 3 784231
0 4 200542
0 5 322271
0 6 145147
0 7 701703
0 8 697197
0 9 230649
0 10 66406
0 11 192060
0 12 646979
0 13 994898
0 14 790273
0 15 857997
0 16 500846
0 17 614504
0 18 116003
0 19 860435
0 20 408561
0 21 807567
0 22 865625
0 23 912380
0 24 159361
0 25 445...

output:

moonrabbit2
1881133 342039
1365560 189840
1904664 146478
1970494 11123
1619685 16108
836019 771771
1139409 399295
1098511 681253
1255719 107615
1310172 102267
1678613 187200
1568008 126217
1621523 688489
528290 228877
675740 326129
1418730 49439
1302170 122766
1576107 151377
1792279 741719
1475969 7...

result:

wrong answer 3rd lines differ - expected: '4877 678', found: '1365560 189840'

Subtask #5:

score: 0
Wrong Answer

Test #107:

score: 0
Wrong Answer
time: 315ms
memory: 62052kb

input:

100000 100000
79032 30329 248444
88464 37167 111467
39863 17716 351134
54587 41263 457638
29720 44292 788955
35224 34773 21953
35197 81607 854881
10506 53579 730874
42849 18020 284719
11562 2134 691047
9748 66972 829044
40305 74689 96507
29530 57073 963318
60683 93450 502599
31421 18784 58037
38493 ...

output:

moonrabbit2
2467705 357807
6853519 638322
404573654 473209
2928200 596526
2635493 429398
2477489 329431
858933 245050
4529473 93542
302027555 226746
362270730 88462
310246991 288097
384855003 803454
358841914 355202
292335543 361114
367627986 90537
3835425 313089
354676453 541540
451874933 381408
45...

result:

wrong answer 5th lines differ - expected: '1464100 298263', found: '2928200 596526'

Subtask #6:

score: 0
Wrong Answer

Test #150:

score: 0
Wrong Answer
time: 268ms
memory: 61380kb

input:

100000 100000
93969 0 382662
93969 1 79501
93969 2 520957
93969 3 376570
93969 4 150693
93969 5 541083
93969 6 597220
93969 7 265149
93969 8 197919
93969 9 640117
93969 10 696733
93969 11 275493
93969 12 168554
93969 13 676861
93969 14 883069
93969 15 323396
93969 16 378012
93969 17 862488
93969 18 ...

output:

moonrabbit2
1382657 544032
463806 547769
1039621 502219
1153977 956794
1382657 259660
991144 285699
1054453 867241
1382657 516889
1382657 143336
1026650 816496
351279 557336
1382657 318712
1382657 458677
1382657 282536
1271828 863911
1382657 66063
1242824 671259
1014021 275352
658992 562229
993770 1...

result:

wrong answer 5th lines differ - expected: '67881 56282', found: '1153977 956794'

Subtask #7:

score: 0
Wrong Answer

Test #156:

score: 0
Wrong Answer
time: 508ms
memory: 67936kb

input:

100000 100000
14404 85036 1
16085 23033 46643
26279 34617 1
80367 35294 1
67695 57594 1
78450 39315 1
62640 36792 1
16192 15790 1
31390 63335 1
26051 33567 1
35882 27009 1
10252 23161 43001
29996 64903 7575
1460 99182 31033
85422 67493 796
27279 68234 36580
44622 79868 5109
87113 52694 40225
49912 7...

output:

moonrabbit2
299999 299999
299999 299999
299999 299999
299999 299999
299999 299999
299999 299999
299999 299999
299999 299999
299999 299999
299999 299999
299999 299999
299999 299999
299999 299999
299999 299999
299999 299999
299999 299999
299999 299999
299999 299999
299999 299999
299999 299999
299999 2...

result:

wrong answer 2nd lines differ - expected: '1 1', found: '299999 299999'

Subtask #8:

score: 0
Wrong Answer

Test #176:

score: 0
Wrong Answer
time: 507ms
memory: 67956kb

input:

100000 100000
55628 58606 40689
5784 15690 24257
72720 4206 1
69608 99473 7530
48167 78928 1
53941 38396 1
51953 39907 1
97834 17721 14667
88387 64737 1
94122 38165 1
58616 20038 1
90640 40598 31512
84598 84729 9557
39311 27869 48827
95273 81340 27050
51941 93655 1
5842 33582 44082
5873 68938 1
5918...

output:

moonrabbit2
299999 299999
299999 299999
299999 299999
299999 299999
299999 299999
299999 299999
299999 299999
299999 299999
299999 299999
299999 299999
299999 299999
299999 299999
299999 299999
299999 299999
299999 299999
299999 299999
299999 299999
299999 299999
299999 299999
299999 299999
299999 2...

result:

wrong answer 2nd lines differ - expected: '1 1', found: '299999 299999'

Subtask #9:

score: 0
Skipped

Dependency #1:

0%