QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#473301#5828. 游戏LinkZelda100 ✓91ms69652kbC++142.6kb2024-07-12 00:57:152024-07-12 00:57:15

Judging History

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

  • [2024-07-12 00:57:15]
  • 评测
  • 测评结果:100
  • 用时:91ms
  • 内存:69652kb
  • [2024-07-12 00:57:15]
  • 提交

answer

#include<bits/stdc++.h>
#define pr pair<int,int>
#define eps 1e-10
#define int long long

using namespace std;

inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=(x*10+ch-'0');ch=getchar();}
	return x*f;
}

const int N=200005;
int head[N],to[N*2],nxt[N*2],cnt;
void add(int u,int v)
{
	to[++cnt]=v;
	nxt[cnt]=head[u];
	head[u]=cnt;
}

int n,q;
int fa[N],dep[N],lg[N],st[21][N],maxx[N],rt;
bool vis[N];
vector<int>awa,qwq[N];

void dfs(int now,int fath)
{
	dep[now]=dep[fath]+1;
	if(dep[now]>dep[rt])
		rt=now;
	fa[now]=fath;
	for(int i=head[now];i;i=nxt[i])
	{
		int v=to[i];
		if(v==fath||vis[v])
			continue;
		dfs(v,now);
	}
}

int a[4],p[4];

int query(int l,int r)
{
	int len=lg[r-l+1];
	return (maxx[st[len][l]]>maxx[st[len][r-(1<<len)+1]])?st[len][l]:st[len][r-(1<<len)+1];
}

void solve()
{
	n=read();
	for(int i=1;i<n;i++)
	{
		int u=read(),v=read();
		add(u,v),add(v,u);
	}
	rt=0;
	dfs(1,0);
	dfs(rt,0);
	while(rt)
		vis[rt]=1,awa.push_back(rt),rt=fa[rt];
	for(int i=2;i<=n;i++)
		lg[i]=lg[i>>1]+1;
	for(int i=0;i<(int)awa.size();i++)
	{
		rt=0;dep[0]=-1;
		dfs(awa[i],0);
		st[0][i+1]=i;
		maxx[i]=dep[rt];
		while(rt!=awa[i])
			qwq[i].push_back(rt),rt=fa[rt];
		qwq[i].push_back(rt);
		reverse(qwq[i].begin(),qwq[i].end()); 
	}
	int len=awa.size();
	for(int i=1;i<=20;i++)
		for(int j=1;j+(1<<i)-1<=len;j++)
			st[i][j]=(maxx[st[i-1][j]]>maxx[st[i-1][j+(1<<(i-1))]])?st[i-1][j]:st[i-1][j+(1<<(i-1))];
	q=read();
	while(q--)
	{
		for(int i=1;i<=3;i++)
			a[i]=read(),p[i]=i;
		sort(p+1,p+4,[&](int x,int y){return a[x]>a[y];});
		int u,v,w;
		int dis1=(a[p[2]]-a[p[3]]+a[p[1]])/2,dis2=a[p[1]]-dis1;
		int ovo=query(dis1+1,len-dis2);
		if(maxx[ovo]>=a[p[2]]-dis1)
		{
//            printf("!!!!%lld %lld\n",awa[ovo],maxx[ovo]);
			u=awa[ovo-dis1];
			v=awa[ovo+dis2];
			w=qwq[ovo][a[p[2]]-dis1];
		}
		else
		{
			ovo=query(dis2+1,len-dis1);
//			printf("!!!%lld %lld\n",awa[ovo],maxx[ovo]);
			u=awa[ovo+dis1];
			v=awa[ovo-dis2];
			w=qwq[ovo][a[p[2]]-dis1];
		}//(u,v) (u,w) (v,w)
		if(p[1]==1&&p[2]==2)
			printf("%lld %lld %lld\n",u,v,w);
		if(p[1]==1&&p[2]==3)
			printf("%lld %lld %lld\n",v,u,w);
		if(p[1]==2&&p[2]==1)
			printf("%lld %lld %lld\n",u,w,v);
		if(p[1]==2&&p[2]==3)
			printf("%lld %lld %lld\n",v,w,u);
		if(p[1]==3&&p[2]==1)
			printf("%lld %lld %lld\n",w,u,v);
		if(p[1]==3&&p[2]==2)
			printf("%lld %lld %lld\n",w,v,u);
	}
}

signed main() 
{
//	freopen("sum.in","r",stdin);
//	freopen("sum.out","w",stdout); 
	int Tests=1;
	while(Tests--)
		solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 10
Accepted
time: 0ms
memory: 24132kb

input:

500
279 196
182 105
400 14
278 217
198 411
379 318
120 421
314 95
437 325
23 433
71 485
192 154
90 224
180 71
328 93
183 101
404 349
223 285
492 100
366 480
29 328
200 448
365 156
226 231
129 167
246 273
171 452
284 6
131 471
229 90
480 48
448 157
240 221
7 36
401 200
255 438
436 110
281 489
388 258...

output:

421 175 463
93 47 190
333 236 175
343 209 473
39 190 57
30 110 333
343 246 7
203 430 49
179 39 93
328 28 435
305 49 378
487 150 463
253 110 430
423 108 120
125 242 175
49 273 378
413 28 478
60 417 476
253 148 493
158 202 36
215 57 401
493 227 406
333 120 439
127 169 311
305 215 406
110 139 390
123 4...

result:

ok Accepted!

Test #2:

score: 10
Accepted
time: 3ms
memory: 30648kb

input:

2000
643 1871
689 23
1822 1443
1031 1027
1655 845
189 771
1561 498
19 1778
576 1080
904 717
1690 291
1387 1077
398 811
1310 1231
645 1291
480 927
330 170
1464 1057
1033 894
1308 288
1292 1529
1212 122
1108 401
89 1118
1058 1088
1764 1314
981 1255
1893 864
180 1887
1903 843
734 1412
883 1013
1739 124...

output:

798 1000 175
231 898 1242
1050 1000 1105
258 1600 1337
1540 1591 1763
1285 646 120
1995 970 1738
1563 565 1672
1390 440 1095
339 1053 439
850 1540 1999
836 413 471
1574 910 1050
1201 572 152
1630 572 977
134 1152 174
152 1152 1343
1636 848 964
393 1118 86
1848 1734 1948
1343 974 145
1458 211 1630
14...

result:

ok Accepted!

Test #3:

score: 10
Accepted
time: 51ms
memory: 43348kb

input:

200000
56968 132021
105656 107536
123627 58349
119191 138198
133708 142638
114350 24980
137784 40346
124158 130204
80684 183207
78156 94449
21893 157560
54464 73571
145830 57756
160288 32120
178632 142663
26565 185985
70576 24906
32217 115826
185756 137673
54280 179613
77826 144447
66005 29955
11745...

output:

6740 173803 167377

result:

ok Accepted!

Test #4:

score: 10
Accepted
time: 56ms
memory: 43272kb

input:

200000
41999 100683
85781 129266
122431 179332
162416 44814
24405 42267
154161 12483
178049 159964
67625 152391
133072 25866
178005 14695
94384 170290
54701 40323
66280 128515
159022 55057
14985 12920
182805 40659
173117 67973
99771 26102
198919 94543
23608 187601
61125 5759
89437 47647
18142 192402...

output:

82066 7276 199629

result:

ok Accepted!

Test #5:

score: 10
Accepted
time: 55ms
memory: 44288kb

input:

200000
195072 75458
31991 127114
60943 49502
186375 1130
45394 147217
168455 84307
132752 188952
101108 130004
107490 22003
16275 187645
111002 42669
138880 137115
112688 172751
81697 99037
166996 18495
2234 56119
170807 101349
105736 23180
148159 40863
136678 11849
190707 91245
61779 120740
157115 ...

output:

42943 98198 35469
17965 62489 120229
19128 64637 17387
129196 118391 75453
96028 74366 93926
47753 193552 124636
86727 124776 193560
36173 21360 118748
16928 105792 116603
80802 106757 97478

result:

ok Accepted!

Test #6:

score: 10
Accepted
time: 56ms
memory: 44140kb

input:

200000
48556 78408
155026 9376
8983 61211
150393 85068
90892 109283
75746 89742
6760 187245
168658 130735
68602 127646
60802 149828
22898 59471
172845 100274
42303 190696
7612 134905
94702 59800
129633 192496
19903 64869
51318 63358
34692 66030
98535 176606
153647 177529
157903 147292
106273 107278
...

output:

160968 71887 172972
68776 27494 155718
134802 99663 157918
135638 139436 15491
147837 188731 19984
75607 19769 187886
4746 57897 148651
32668 166229 99352
132237 27861 51911
142520 121513 155540

result:

ok Accepted!

Test #7:

score: 10
Accepted
time: 90ms
memory: 69652kb

input:

200000
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51
51 52
52 5...

output:

54356 200000 137052
200000 170197 131241
84517 200000 179296
183330 163219 200000
158370 200000 194345
85385 171870 200000
143829 200000 85216
200000 122372 28132
200000 25711 157674
200000 179037 24813
200000 197101 57460
117928 178289 200000
200000 179418 195973
22762 116045 200000
100818 200000 1...

result:

ok Accepted!

Test #8:

score: 10
Accepted
time: 80ms
memory: 43244kb

input:

200000
5732 55198
128966 25317
114737 116391
150003 18274
43867 70745
76222 4169
55976 114951
198396 72896
38647 19711
12756 172119
73197 117994
117512 14177
130965 126990
119440 183341
142023 60829
111893 57350
122754 123305
36525 79077
36447 91967
135405 170456
165839 147481
66074 175822
22238 264...

output:

197325 197325 62931
197325 197325 155225
76081 76081 197926
197325 197325 173619
197325 197325 176507
197325 197325 157250
197325 197325 80952
197325 197325 26834
197325 197325 13198
197325 197325 6019
197325 197325 152815
197325 197325 148642
197325 197325 193253
197325 197325 87746
197325 197325 7...

result:

ok Accepted!

Test #9:

score: 10
Accepted
time: 91ms
memory: 43564kb

input:

200000
185063 17064
180987 114492
88071 71803
158363 135918
60910 54848
97338 6734
192937 9410
49617 199068
82499 63554
188791 188152
178767 40866
11304 27212
144234 138097
42236 3946
103355 12683
50992 20598
145723 48620
11709 115688
123172 121379
70541 130844
147827 39431
139372 61280
42705 54015
...

output:

80097 34708 81596
147087 56002 142950
104657 175190 140544
26871 68813 102483
66610 120520 160376
119681 178802 87450
95574 177939 173324
196768 107997 93428
155312 102188 165590
75873 188561 184300
60384 123039 66285
31618 98649 113665
151223 16594 71093
3957 182002 80938
82137 178243 159894
99825 ...

result:

ok Accepted!

Test #10:

score: 10
Accepted
time: 90ms
memory: 42584kb

input:

200000
197244 185999
18639 124754
154223 12099
53676 167616
22710 22294
150412 66132
19320 75478
170410 122661
130961 175554
171586 85572
188386 81238
120249 117687
43214 126266
8744 165654
164725 189519
124144 170329
86605 100197
130545 17030
113301 96665
67733 187286
37846 146399
75352 117550
3235...

output:

46612 115995 19487
95761 11770 131379
2614 109635 143204
25740 146957 128773
41838 39603 83393
163893 1353 78456
130689 166930 162505
35922 151246 94060
21175 41973 74478
137988 108490 126401
73735 90970 182873
17316 118619 100001
77703 8619 156309
95660 168939 35969
17492 38268 22990
172124 50538 8...

result:

ok Accepted!

Extra Test:

score: 0
Extra Test Passed