QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#78157 | #5515. Cat Exercise | lcjlcj | 54 | 147ms | 40820kb | C++14 | 1.7kb | 2023-02-17 09:52:45 | 2023-02-17 09:52:47 |
Judging History
answer
#include <bits/stdc++.h>
//#define int long long
#define ll long long
#define db double
#define fi first
#define se second
#define pii pair<int,int>
#define vi vector<int>
using namespace std;
const int maxn=2e5;
int n,p[maxn+5],pos[maxn+5];
vector<int> g[maxn+5];
int fa[maxn+5][20],dep[maxn+5],ff[maxn+5],mxpos[maxn+5],f[maxn+5];
void dfs(int u,int pre) {
for (auto v:g[u]) {
if (v==pre) continue ;
dep[v]=dep[u]+1;
dfs(v,u);
fa[v][0]=u;
}
}
int find(int x) {
return ff[x]==x?x:ff[x]=find(ff[x]);
}
int LCA(int u,int v) {
if (dep[u]<dep[v]) swap(u,v);
for (int j=19;j>=0;j--) {
if (fa[u][j] && dep[fa[u][j]]>=dep[v]) {
u=fa[u][j];
}
}
if (u==v) return u;
for (int j=19;j>=0;j--) {
if (fa[u][j] != fa[v][j]) {
u=fa[u][j],v=fa[v][j];
}
}
return fa[u][0];
}
void Union(int x,int y) {
int fu=find(x),fv=find(y);
if (fu==fv) return ;
ff[fu]=fv;
if (p[mxpos[fv]]<p[mxpos[fu]]) mxpos[fv]=mxpos[fu];
}
int dis(int u,int v) {
return dep[u]+dep[v]-2*dep[LCA(u,v)];
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
cin>>n;
for (int i=1;i<=n;i++) cin>>p[i],pos[p[i]]=i,ff[i]=i,mxpos[i]=i;
for (int i=1;i<n;i++) {
int u,v;
cin>>u>>v;
g[u].push_back(v);
g[v].push_back(u);
}
dfs(1,0);
for (int j=1;(1<<j)<=n;j++) {
for (int i=1;i<=n;i++) {
fa[i][j]=fa[fa[i][j-1]][j-1];
}
}
for (int i=1;i<=n;i++) {
int u=pos[i];
f[u]=0;
for (auto v:g[u]) {
if (p[v]>p[u]) continue ;
int fv=find(v);
int P=mxpos[fv];
f[u]=max(f[u],dis(P,u)+f[P]);
}
for (auto v:g[u]) {
if (p[v]<=p[u]) Union(u,v);
}
}
cout<<f[pos[n]]<<'\n';
return 0;
}
詳細信息
Subtask #1:
score: 7
Accepted
Test #1:
score: 7
Accepted
time: 2ms
memory: 13632kb
input:
10 9 4 3 2 1 10 7 5 6 8 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10
output:
10
result:
ok single line: '10'
Test #2:
score: 0
Accepted
time: 4ms
memory: 11528kb
input:
10 8 6 5 7 10 1 2 3 4 9 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10
output:
10
result:
ok single line: '10'
Test #3:
score: 0
Accepted
time: 1ms
memory: 13808kb
input:
16 16 14 12 10 8 6 4 2 1 3 5 7 9 11 13 15 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
output:
120
result:
ok single line: '120'
Test #4:
score: 0
Accepted
time: 0ms
memory: 9552kb
input:
16 15 14 13 12 10 9 8 5 4 3 2 1 6 7 11 16 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
output:
58
result:
ok single line: '58'
Test #5:
score: 0
Accepted
time: 2ms
memory: 11584kb
input:
16 16 14 13 12 2 10 7 4 3 1 5 6 8 9 11 15 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
output:
77
result:
ok single line: '77'
Test #6:
score: 0
Accepted
time: 4ms
memory: 9708kb
input:
2 1 2 1 2
output:
1
result:
ok single line: '1'
Test #7:
score: 0
Accepted
time: 1ms
memory: 11680kb
input:
16 12 15 5 2 13 4 7 6 1 11 14 10 3 9 16 8 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
output:
38
result:
ok single line: '38'
Test #8:
score: 0
Accepted
time: 4ms
memory: 11584kb
input:
16 16 8 7 9 1 5 3 13 11 15 12 10 2 4 14 6 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
output:
22
result:
ok single line: '22'
Test #9:
score: 0
Accepted
time: 4ms
memory: 11612kb
input:
16 2 14 8 11 16 1 3 7 12 6 13 5 9 15 10 4 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
output:
17
result:
ok single line: '17'
Subtask #2:
score: 7
Accepted
Dependency #1:
100%
Accepted
Test #10:
score: 7
Accepted
time: 3ms
memory: 14048kb
input:
300 300 298 296 294 292 290 288 286 284 282 280 278 276 274 272 270 268 266 264 262 260 258 256 254 252 250 248 246 244 242 240 238 236 234 232 230 228 226 224 222 220 218 216 214 212 210 208 206 204 202 200 198 196 194 192 190 188 186 184 182 180 178 176 174 172 170 168 166 164 162 160 158 156 154 ...
output:
44850
result:
ok single line: '44850'
Test #11:
score: 0
Accepted
time: 1ms
memory: 13596kb
input:
300 298 30 295 294 291 289 283 280 277 275 273 271 270 268 267 29 263 262 261 28 257 256 255 27 254 253 252 249 246 245 242 241 240 238 236 230 227 226 223 221 26 217 216 214 213 210 209 204 200 197 25 196 194 193 191 185 178 24 177 176 175 173 171 23 170 169 168 164 163 160 158 157 156 153 152 151 ...
output:
20638
result:
ok single line: '20638'
Test #12:
score: 0
Accepted
time: 5ms
memory: 14232kb
input:
300 299 297 296 294 290 289 288 286 285 284 283 281 280 279 278 277 276 22 274 273 271 269 268 267 266 264 259 255 250 247 21 246 244 242 241 240 239 237 234 233 232 230 228 226 225 224 223 221 219 214 213 211 209 207 206 203 202 201 200 199 195 194 189 187 186 185 182 181 20 176 174 172 171 170 19 ...
output:
22062
result:
ok single line: '22062'
Test #13:
score: 0
Accepted
time: 4ms
memory: 9596kb
input:
300 158 241 135 137 113 59 275 127 261 65 28 112 20 101 299 263 295 209 92 129 54 86 109 105 44 102 280 220 221 196 73 74 214 224 228 91 57 38 146 274 47 56 175 232 188 173 182 143 210 130 284 257 122 141 165 237 3 167 187 278 208 85 200 155 140 283 223 273 150 191 32 216 151 204 18 63 156 258 71 31...
output:
853
result:
ok single line: '853'
Test #14:
score: 0
Accepted
time: 3ms
memory: 11732kb
input:
300 106 208 19 26 155 205 219 25 57 115 210 68 231 175 140 139 81 248 199 172 261 192 200 50 239 291 133 36 191 204 216 122 95 35 126 275 151 73 146 188 241 144 79 42 66 189 121 270 297 53 15 117 282 8 193 46 246 264 252 78 135 157 247 169 28 167 160 130 224 64 31 29 105 56 102 237 14 226 104 174 11...
output:
613
result:
ok single line: '613'
Test #15:
score: 0
Accepted
time: 4ms
memory: 9756kb
input:
300 51 181 14 64 161 90 27 26 5 67 103 156 209 36 272 229 120 33 237 71 298 32 22 260 96 182 243 300 207 72 94 221 113 124 52 167 210 282 244 173 16 184 60 228 273 152 100 172 245 131 17 191 258 21 189 192 44 25 217 112 75 121 55 57 223 137 231 145 215 270 240 54 130 285 56 139 238 115 277 4 205 129...
output:
409
result:
ok single line: '409'
Test #16:
score: 0
Accepted
time: 4ms
memory: 11788kb
input:
300 81 20 270 26 143 217 119 135 46 292 108 246 106 11 95 69 121 100 226 7 234 249 181 104 90 83 5 51 272 174 190 35 224 216 179 9 1 61 297 299 92 49 263 218 88 300 164 32 146 207 203 155 245 125 42 291 148 153 288 191 259 240 220 111 84 298 126 172 107 149 96 123 29 99 128 169 248 275 31 57 170 78 ...
output:
448
result:
ok single line: '448'
Subtask #3:
score: 7
Accepted
Dependency #2:
100%
Accepted
Test #17:
score: 7
Accepted
time: 6ms
memory: 14276kb
input:
5000 5000 4998 4996 4994 4992 4990 4988 4986 4984 4982 4980 4978 4976 4974 4972 4970 4968 4966 4964 4962 4960 4958 4956 4954 4952 4950 4948 4946 4944 4942 4940 4938 4936 4934 4932 4930 4928 4926 4924 4922 4920 4918 4916 4914 4912 4910 4908 4906 4904 4902 4900 4898 4896 4894 4892 4890 4888 4886 4884 ...
output:
12497500
result:
ok single line: '12497500'
Test #18:
score: 0
Accepted
time: 6ms
memory: 12344kb
input:
5000 4998 4997 4995 4993 4990 457 4989 4987 4986 4984 4983 4982 4979 4977 4976 4975 4974 4970 4969 456 4968 4966 4962 455 4960 4959 4957 454 4954 4949 4948 4947 4942 4941 4937 4935 4933 4932 4931 4928 4927 4926 4925 4920 4919 453 4918 4914 4912 4911 4910 452 4906 4905 4904 4903 4902 4901 4898 451 48...
output:
5574749
result:
ok single line: '5574749'
Test #19:
score: 0
Accepted
time: 7ms
memory: 14016kb
input:
5000 4998 4997 4996 4994 4993 469 4991 4987 4986 4983 4982 4981 4978 4975 4972 4969 4968 4965 4963 4962 4958 4954 4950 468 4947 4941 4937 4934 4933 4930 4929 4927 4926 4925 467 4923 4920 4919 466 4914 4913 4912 4911 4909 4908 4907 4906 4905 4904 4903 4900 4898 4895 465 4891 4889 4886 4883 4878 464 4...
output:
5641202
result:
ok single line: '5641202'
Test #20:
score: 0
Accepted
time: 4ms
memory: 14364kb
input:
5000 1173 1790 485 3355 881 383 955 3750 3520 3284 1637 1197 4388 1451 1390 1448 3007 3857 693 3139 4082 685 3022 2716 3047 4938 4228 2858 4633 664 4848 2245 2881 3257 4962 3583 3312 3535 4835 582 3925 2799 213 3329 1865 4787 1794 3074 568 473 3812 4692 3191 4084 4609 2618 2082 3199 815 105 2448 246...
output:
6072
result:
ok single line: '6072'
Test #21:
score: 0
Accepted
time: 3ms
memory: 16000kb
input:
5000 4372 716 1450 4881 3404 3964 4918 2154 3897 4195 3426 1964 412 2905 3731 572 3641 1169 4191 1480 384 2241 4781 2952 947 677 462 1982 228 3644 3470 2911 4000 3906 4314 1127 3807 548 2578 3995 277 2498 702 789 703 2912 2846 4747 3898 1553 4495 996 782 496 1276 914 1384 3436 3626 1332 4739 3324 40...
output:
9050
result:
ok single line: '9050'
Test #22:
score: 0
Accepted
time: 6ms
memory: 10324kb
input:
5000 2717 539 4388 4260 3811 4870 921 987 2100 2686 4296 2588 4683 1893 2807 4244 4777 2293 1563 3510 3608 4656 2284 1041 4750 794 1850 3062 2743 1859 1921 856 4953 2327 460 2709 3416 491 543 4964 1272 4230 58 533 3554 2661 544 106 1849 2172 975 214 1540 3537 3105 3367 4686 2737 3206 2781 888 2844 1...
output:
6106
result:
ok single line: '6106'
Test #23:
score: 0
Accepted
time: 6ms
memory: 12344kb
input:
5000 2530 1608 3085 3987 3449 1301 346 2839 3532 1308 3663 3716 2871 2154 4443 1378 592 2688 401 2574 4723 4948 1056 1588 1681 1447 4696 260 2814 1825 2510 4393 2037 315 3804 2468 3905 2639 742 1593 4435 3769 2892 4371 3039 4763 1190 1047 1706 3216 854 2604 3047 3476 1444 283 2249 3512 3319 210 3780...
output:
4633
result:
ok single line: '4633'
Subtask #4:
score: 10
Accepted
Dependency #3:
100%
Accepted
Test #24:
score: 10
Accepted
time: 3ms
memory: 14088kb
input:
5000 2443 4316 4835 3133 2064 1132 2595 1618 709 2401 4411 1332 3143 4533 1645 1069 1141 2036 571 3166 1862 2973 2701 1056 2286 777 343 1341 891 3956 682 1789 1101 2124 642 2399 1175 430 2100 3616 916 1239 4343 4322 4012 1632 1846 4720 1484 3473 3953 690 186 1607 2095 3482 2651 4974 3954 2239 4775 3...
output:
3141224
result:
ok single line: '3141224'
Test #25:
score: 0
Accepted
time: 6ms
memory: 13944kb
input:
5000 1461 2143 636 1327 3099 1008 3862 764 861 517 97 1183 4533 2145 81 1238 3165 1768 363 1975 1346 3863 673 4028 4095 4189 1375 2741 4323 2221 2476 2587 2282 2955 2558 4046 3753 143 1471 1779 942 3180 532 3910 3987 3460 2800 3713 3937 4485 3372 4069 1643 2528 3473 444 2229 1544 832 4781 983 4866 1...
output:
3161222
result:
ok single line: '3161222'
Test #26:
score: 0
Accepted
time: 3ms
memory: 10268kb
input:
5000 877 2529 4583 977 3596 4179 718 4192 2653 4763 1045 626 4786 4569 2826 1750 943 780 980 2917 1006 1535 2032 566 2818 2300 4958 115 4523 3617 2454 1603 1243 3772 3845 1041 2735 4269 2453 2819 2943 2449 1770 3394 3503 4314 4538 440 3848 3521 2226 250 2937 136 4744 1341 296 4610 338 3273 3739 1795...
output:
3104067
result:
ok single line: '3104067'
Test #27:
score: 0
Accepted
time: 1ms
memory: 10312kb
input:
5000 284 728 3780 3349 2304 1667 481 2286 3992 3127 2267 2708 703 560 667 1959 4931 1860 3292 1539 1018 4125 561 2379 3331 2657 175 207 2846 4557 2747 2082 4883 2598 4770 3532 279 2778 3027 3577 3005 959 1259 2826 3888 4164 4402 1332 1296 335 4038 2094 1440 4456 293 2910 4529 3335 146 4012 468 213 8...
output:
3028608
result:
ok single line: '3028608'
Test #28:
score: 0
Accepted
time: 6ms
memory: 10192kb
input:
5000 1327 1167 4074 1668 2623 2814 3670 2255 2039 1079 4343 284 1448 2868 705 2103 1115 4015 130 4524 818 1399 4893 950 134 1936 456 1585 564 4187 4696 2144 4478 2314 2227 3117 4881 1400 58 4328 244 828 4461 4241 1487 427 2675 634 1263 2343 4781 658 3959 4366 4147 1996 264 3649 4839 1967 879 3981 29...
output:
3236
result:
ok single line: '3236'
Test #29:
score: 0
Accepted
time: 1ms
memory: 13916kb
input:
5000 16 2342 1372 372 1890 3654 4812 4307 2689 4982 1881 1309 3863 2897 388 4031 2026 3256 4412 1080 4306 4483 2656 4089 933 1198 1096 1597 639 3609 4120 2611 559 1512 623 709 1724 4780 2136 689 3766 119 4423 1413 1904 3532 3503 2363 4081 1607 2329 1506 4638 3511 3903 4234 4949 251 4041 765 2921 358...
output:
8215
result:
ok single line: '8215'
Test #30:
score: 0
Accepted
time: 0ms
memory: 10184kb
input:
5000 676 4812 4561 3717 4493 995 4212 1194 4445 3928 1473 2414 4514 4452 3456 496 3376 4930 1524 1436 386 3670 2231 846 4601 48 1827 946 4597 2473 242 4629 2912 2245 3138 1697 3884 3960 2085 2546 859 3779 969 2946 317 4495 2803 2547 2116 3379 2807 1722 1151 1612 2971 2201 2851 2753 3013 1650 2000 30...
output:
5169
result:
ok single line: '5169'
Test #31:
score: 0
Accepted
time: 7ms
memory: 13944kb
input:
5000 1145 3129 1935 4752 4430 3169 1051 4710 3335 4755 262 4267 492 627 49 1826 2524 2375 4447 4721 2916 4300 3293 2387 2728 1774 279 4598 4534 4173 2809 3515 1949 346 166 973 3214 1166 2988 1707 1032 3229 2833 137 1839 1077 3094 2050 4265 4974 1364 4633 3379 3697 4223 862 4691 55 820 4431 2022 2051...
output:
7500
result:
ok single line: '7500'
Subtask #5:
score: 0
Wrong Answer
Test #32:
score: 0
Wrong Answer
time: 92ms
memory: 40820kb
input:
200000 200000 199998 199996 199994 199992 199990 199988 199986 199984 199982 199980 199978 199976 199974 199972 199970 199968 199966 199964 199962 199960 199958 199956 199954 199952 199950 199948 199946 199944 199942 199940 199938 199936 199934 199932 199930 199928 199926 199924 199922 199920 199918...
output:
671859034
result:
wrong answer 1st lines differ - expected: '19999900000', found: '671859034'
Subtask #6:
score: 23
Accepted
Test #39:
score: 23
Accepted
time: 1ms
memory: 13820kb
input:
200 49 181 133 160 142 76 134 189 25 167 10 54 59 158 186 53 58 145 95 9 27 30 116 77 140 173 131 21 151 128 190 51 19 112 40 161 136 93 46 52 45 84 18 42 63 43 73 188 147 153 124 127 177 32 75 150 96 175 34 183 106 13 80 196 141 198 67 26 92 192 191 172 90 83 164 180 107 143 121 146 125 174 139 104...
output:
256
result:
ok single line: '256'
Test #40:
score: 0
Accepted
time: 144ms
memory: 34792kb
input:
200000 47590 74846 33440 172120 93313 6143 118842 183554 57721 114949 56442 25767 28220 10101 116823 185481 76250 82471 149808 167830 176621 84906 178870 135367 94129 107804 33861 133096 39663 156399 193810 84691 45814 156960 107510 195808 47135 17660 119624 99945 87252 140615 92398 154908 120735 15...
output:
432517
result:
ok single line: '432517'
Test #41:
score: 0
Accepted
time: 147ms
memory: 34640kb
input:
200000 54514 132138 136991 158483 149121 87580 164108 86612 22687 92566 45018 38190 71624 146051 34722 140067 56355 83040 61329 154797 35240 11212 70478 94271 46277 166489 110079 98582 165864 111293 15446 143673 99507 13750 83946 132565 13323 185680 63850 63999 67105 15785 85805 153610 42258 14357 1...
output:
486019
result:
ok single line: '486019'
Test #42:
score: 0
Accepted
time: 139ms
memory: 34576kb
input:
200000 67281 123460 65755 103449 80776 37208 166821 2511 113868 129359 63375 172281 111678 75568 198230 134639 58140 171726 134196 45888 101272 137261 155291 97353 59848 119410 147885 64293 144417 117383 114431 127365 121467 94143 42470 68084 188544 176844 21694 59475 23226 123527 12303 48756 59959 ...
output:
410237
result:
ok single line: '410237'
Subtask #7:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
100%
Accepted
Dependency #4:
100%
Accepted
Dependency #5:
0%