# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
89624 | 2018-12-17T16:21:05 Z | Vardanyan | Birthday gift (IZhO18_treearray) | C++14 | 4000 ms | 45460 KB |
#include <bits/stdc++.h> using namespace std; const int N = 2*1000*100+5; int a[N]; vector<int> g[N]; int colour[N]; int par[N]; int dp[N][25]; int depth[N]; void kaxel(int v,int dep = 0,int p = -1){ par[v] = p; dp[v][0] = p; depth[v] = dep; for(int i = 0;i<g[v].size();i++){ int to = g[v][i]; if(to == p) continue; kaxel(to,dep+1,v); } } int lca(int a,int b){ if(depth[a]<depth[b]) swap(a,b); int dif = depth[a]-depth[b]; for(int i = 24;i>=0;i--){ if((dif>>i)&1) a = dp[a][i]; } // cout<<a<<" "<<b<<endl; if(a == b) return a; for(int i = 24;i>=0;i--){ if(dp[a][i] == -1 || dp[b][i] == -1) continue; if(dp[a][i] == dp[b][i]) continue; a = dp[a][i]; b = dp[b][i]; } a = dp[a][0]; return a; } int main(){ int n,m,q; scanf("%d%d%d",&n,&m,&q); for(int i = 1;i<=n-1;i++){ int x,y; scanf("%d%d",&x,&y); g[x].push_back(y); g[y].push_back(x); } memset(dp,-1,sizeof dp); kaxel(1); for(int j = 1;j<=24;j++){ for(int i = 1;i<=n;i++){ if(dp[i][j-1] == -1) dp[i][j] = -1; else dp[i][j] = dp[dp[i][j-1]][j-1]; } } /*int x,y; while(cin>>x>>y){ cout<<lca(x,y)<<endl; }*/ /*for(int i = 1;i<=n;i++){ for(int j = 0;j<=4;j++){ cout<<dp[i][j]<<" "; } cout<<endl; }*/ for(int i = 1;i<=m;i++) scanf("%d",&a[i]); while(q--){ int tp; scanf("%d",&tp); if(tp == 1){ int pos,val; scanf("%d%d",&pos,&val); a[pos] = val; } else{ int l,r,v; scanf("%d%d%d",&l,&r,&v); bool f = false; for(int i = l;i<=r;i++){ if(v == a[i]){ printf("%d %d\n",i,i); f = true; break; } if(i == r) continue; if(lca(a[i],a[i+1]) == v){ printf("%d %d\n",i,i+1); f = true; break; } } if(f) continue; printf("-1 -1\n"); } } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 24568 KB | n=5 |
2 | Correct | 24 ms | 24692 KB | n=100 |
3 | Correct | 23 ms | 24692 KB | n=100 |
4 | Correct | 24 ms | 24832 KB | n=100 |
5 | Correct | 25 ms | 24832 KB | n=100 |
6 | Correct | 25 ms | 24972 KB | n=100 |
7 | Correct | 24 ms | 24972 KB | n=100 |
8 | Correct | 24 ms | 24972 KB | n=100 |
9 | Correct | 24 ms | 24972 KB | n=100 |
10 | Correct | 24 ms | 24972 KB | n=100 |
11 | Correct | 24 ms | 24972 KB | n=100 |
12 | Correct | 24 ms | 24972 KB | n=100 |
13 | Correct | 21 ms | 24972 KB | n=100 |
14 | Correct | 21 ms | 24972 KB | n=100 |
15 | Correct | 21 ms | 24972 KB | n=100 |
16 | Correct | 25 ms | 24972 KB | n=100 |
17 | Correct | 24 ms | 24972 KB | n=100 |
18 | Correct | 24 ms | 24972 KB | n=100 |
19 | Correct | 24 ms | 24972 KB | n=100 |
20 | Correct | 24 ms | 24972 KB | n=100 |
21 | Correct | 25 ms | 24972 KB | n=100 |
22 | Correct | 24 ms | 24972 KB | n=100 |
23 | Correct | 24 ms | 24972 KB | n=100 |
24 | Correct | 23 ms | 24980 KB | n=100 |
25 | Correct | 21 ms | 24980 KB | n=100 |
26 | Correct | 21 ms | 24980 KB | n=12 |
27 | Correct | 21 ms | 24980 KB | n=100 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 24568 KB | n=5 |
2 | Correct | 24 ms | 24692 KB | n=100 |
3 | Correct | 23 ms | 24692 KB | n=100 |
4 | Correct | 24 ms | 24832 KB | n=100 |
5 | Correct | 25 ms | 24832 KB | n=100 |
6 | Correct | 25 ms | 24972 KB | n=100 |
7 | Correct | 24 ms | 24972 KB | n=100 |
8 | Correct | 24 ms | 24972 KB | n=100 |
9 | Correct | 24 ms | 24972 KB | n=100 |
10 | Correct | 24 ms | 24972 KB | n=100 |
11 | Correct | 24 ms | 24972 KB | n=100 |
12 | Correct | 24 ms | 24972 KB | n=100 |
13 | Correct | 21 ms | 24972 KB | n=100 |
14 | Correct | 21 ms | 24972 KB | n=100 |
15 | Correct | 21 ms | 24972 KB | n=100 |
16 | Correct | 25 ms | 24972 KB | n=100 |
17 | Correct | 24 ms | 24972 KB | n=100 |
18 | Correct | 24 ms | 24972 KB | n=100 |
19 | Correct | 24 ms | 24972 KB | n=100 |
20 | Correct | 24 ms | 24972 KB | n=100 |
21 | Correct | 25 ms | 24972 KB | n=100 |
22 | Correct | 24 ms | 24972 KB | n=100 |
23 | Correct | 24 ms | 24972 KB | n=100 |
24 | Correct | 23 ms | 24980 KB | n=100 |
25 | Correct | 21 ms | 24980 KB | n=100 |
26 | Correct | 21 ms | 24980 KB | n=12 |
27 | Correct | 21 ms | 24980 KB | n=100 |
28 | Correct | 26 ms | 24980 KB | n=500 |
29 | Correct | 26 ms | 24980 KB | n=500 |
30 | Correct | 23 ms | 24980 KB | n=500 |
31 | Correct | 28 ms | 24980 KB | n=500 |
32 | Correct | 25 ms | 24980 KB | n=500 |
33 | Correct | 26 ms | 24980 KB | n=500 |
34 | Correct | 25 ms | 24980 KB | n=500 |
35 | Correct | 26 ms | 24980 KB | n=500 |
36 | Correct | 38 ms | 24980 KB | n=500 |
37 | Correct | 38 ms | 24980 KB | n=500 |
38 | Correct | 40 ms | 24980 KB | n=500 |
39 | Correct | 31 ms | 24980 KB | n=500 |
40 | Correct | 31 ms | 24980 KB | n=500 |
41 | Correct | 31 ms | 24980 KB | n=500 |
42 | Correct | 31 ms | 24980 KB | n=500 |
43 | Correct | 31 ms | 24980 KB | n=500 |
44 | Correct | 32 ms | 24980 KB | n=500 |
45 | Correct | 24 ms | 24980 KB | n=500 |
46 | Correct | 27 ms | 24980 KB | n=500 |
47 | Correct | 26 ms | 24980 KB | n=500 |
48 | Correct | 24 ms | 24980 KB | n=500 |
49 | Correct | 26 ms | 24980 KB | n=500 |
50 | Correct | 28 ms | 24980 KB | n=500 |
51 | Correct | 27 ms | 24980 KB | n=500 |
52 | Correct | 29 ms | 24980 KB | n=500 |
53 | Correct | 28 ms | 24980 KB | n=500 |
54 | Correct | 30 ms | 24980 KB | n=500 |
55 | Correct | 25 ms | 24980 KB | n=278 |
56 | Correct | 35 ms | 24980 KB | n=500 |
57 | Correct | 32 ms | 24980 KB | n=500 |
58 | Correct | 35 ms | 24980 KB | n=500 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 24568 KB | n=5 |
2 | Correct | 24 ms | 24692 KB | n=100 |
3 | Correct | 23 ms | 24692 KB | n=100 |
4 | Correct | 24 ms | 24832 KB | n=100 |
5 | Correct | 25 ms | 24832 KB | n=100 |
6 | Correct | 25 ms | 24972 KB | n=100 |
7 | Correct | 24 ms | 24972 KB | n=100 |
8 | Correct | 24 ms | 24972 KB | n=100 |
9 | Correct | 24 ms | 24972 KB | n=100 |
10 | Correct | 24 ms | 24972 KB | n=100 |
11 | Correct | 24 ms | 24972 KB | n=100 |
12 | Correct | 24 ms | 24972 KB | n=100 |
13 | Correct | 21 ms | 24972 KB | n=100 |
14 | Correct | 21 ms | 24972 KB | n=100 |
15 | Correct | 21 ms | 24972 KB | n=100 |
16 | Correct | 25 ms | 24972 KB | n=100 |
17 | Correct | 24 ms | 24972 KB | n=100 |
18 | Correct | 24 ms | 24972 KB | n=100 |
19 | Correct | 24 ms | 24972 KB | n=100 |
20 | Correct | 24 ms | 24972 KB | n=100 |
21 | Correct | 25 ms | 24972 KB | n=100 |
22 | Correct | 24 ms | 24972 KB | n=100 |
23 | Correct | 24 ms | 24972 KB | n=100 |
24 | Correct | 23 ms | 24980 KB | n=100 |
25 | Correct | 21 ms | 24980 KB | n=100 |
26 | Correct | 21 ms | 24980 KB | n=12 |
27 | Correct | 21 ms | 24980 KB | n=100 |
28 | Correct | 26 ms | 24980 KB | n=500 |
29 | Correct | 26 ms | 24980 KB | n=500 |
30 | Correct | 23 ms | 24980 KB | n=500 |
31 | Correct | 28 ms | 24980 KB | n=500 |
32 | Correct | 25 ms | 24980 KB | n=500 |
33 | Correct | 26 ms | 24980 KB | n=500 |
34 | Correct | 25 ms | 24980 KB | n=500 |
35 | Correct | 26 ms | 24980 KB | n=500 |
36 | Correct | 38 ms | 24980 KB | n=500 |
37 | Correct | 38 ms | 24980 KB | n=500 |
38 | Correct | 40 ms | 24980 KB | n=500 |
39 | Correct | 31 ms | 24980 KB | n=500 |
40 | Correct | 31 ms | 24980 KB | n=500 |
41 | Correct | 31 ms | 24980 KB | n=500 |
42 | Correct | 31 ms | 24980 KB | n=500 |
43 | Correct | 31 ms | 24980 KB | n=500 |
44 | Correct | 32 ms | 24980 KB | n=500 |
45 | Correct | 24 ms | 24980 KB | n=500 |
46 | Correct | 27 ms | 24980 KB | n=500 |
47 | Correct | 26 ms | 24980 KB | n=500 |
48 | Correct | 24 ms | 24980 KB | n=500 |
49 | Correct | 26 ms | 24980 KB | n=500 |
50 | Correct | 28 ms | 24980 KB | n=500 |
51 | Correct | 27 ms | 24980 KB | n=500 |
52 | Correct | 29 ms | 24980 KB | n=500 |
53 | Correct | 28 ms | 24980 KB | n=500 |
54 | Correct | 30 ms | 24980 KB | n=500 |
55 | Correct | 25 ms | 24980 KB | n=278 |
56 | Correct | 35 ms | 24980 KB | n=500 |
57 | Correct | 32 ms | 24980 KB | n=500 |
58 | Correct | 35 ms | 24980 KB | n=500 |
59 | Correct | 27 ms | 24980 KB | n=2000 |
60 | Correct | 54 ms | 25064 KB | n=2000 |
61 | Correct | 61 ms | 25104 KB | n=2000 |
62 | Correct | 53 ms | 25104 KB | n=2000 |
63 | Correct | 27 ms | 25104 KB | n=2000 |
64 | Correct | 61 ms | 25104 KB | n=2000 |
65 | Correct | 27 ms | 25104 KB | n=2000 |
66 | Correct | 63 ms | 25104 KB | n=2000 |
67 | Correct | 30 ms | 25104 KB | n=2000 |
68 | Correct | 61 ms | 25104 KB | n=2000 |
69 | Correct | 274 ms | 25260 KB | n=2000 |
70 | Correct | 274 ms | 25260 KB | n=2000 |
71 | Correct | 261 ms | 25260 KB | n=2000 |
72 | Correct | 142 ms | 25260 KB | n=2000 |
73 | Correct | 154 ms | 25260 KB | n=2000 |
74 | Correct | 26 ms | 25260 KB | n=1844 |
75 | Correct | 151 ms | 25260 KB | n=2000 |
76 | Correct | 148 ms | 25260 KB | n=2000 |
77 | Correct | 150 ms | 25260 KB | n=2000 |
78 | Correct | 158 ms | 25260 KB | n=2000 |
79 | Correct | 26 ms | 25260 KB | n=2000 |
80 | Correct | 56 ms | 25260 KB | n=2000 |
81 | Correct | 57 ms | 25260 KB | n=2000 |
82 | Correct | 27 ms | 25260 KB | n=2000 |
83 | Correct | 55 ms | 25260 KB | n=2000 |
84 | Correct | 79 ms | 25260 KB | n=2000 |
85 | Correct | 96 ms | 25260 KB | n=2000 |
86 | Correct | 98 ms | 25260 KB | n=2000 |
87 | Correct | 83 ms | 25260 KB | n=2000 |
88 | Correct | 211 ms | 25260 KB | n=2000 |
89 | Correct | 207 ms | 25260 KB | n=2000 |
90 | Correct | 116 ms | 25260 KB | n=2000 |
91 | Correct | 213 ms | 25260 KB | n=2000 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 24568 KB | n=5 |
2 | Correct | 24 ms | 24692 KB | n=100 |
3 | Correct | 23 ms | 24692 KB | n=100 |
4 | Correct | 24 ms | 24832 KB | n=100 |
5 | Correct | 25 ms | 24832 KB | n=100 |
6 | Correct | 25 ms | 24972 KB | n=100 |
7 | Correct | 24 ms | 24972 KB | n=100 |
8 | Correct | 24 ms | 24972 KB | n=100 |
9 | Correct | 24 ms | 24972 KB | n=100 |
10 | Correct | 24 ms | 24972 KB | n=100 |
11 | Correct | 24 ms | 24972 KB | n=100 |
12 | Correct | 24 ms | 24972 KB | n=100 |
13 | Correct | 21 ms | 24972 KB | n=100 |
14 | Correct | 21 ms | 24972 KB | n=100 |
15 | Correct | 21 ms | 24972 KB | n=100 |
16 | Correct | 25 ms | 24972 KB | n=100 |
17 | Correct | 24 ms | 24972 KB | n=100 |
18 | Correct | 24 ms | 24972 KB | n=100 |
19 | Correct | 24 ms | 24972 KB | n=100 |
20 | Correct | 24 ms | 24972 KB | n=100 |
21 | Correct | 25 ms | 24972 KB | n=100 |
22 | Correct | 24 ms | 24972 KB | n=100 |
23 | Correct | 24 ms | 24972 KB | n=100 |
24 | Correct | 23 ms | 24980 KB | n=100 |
25 | Correct | 21 ms | 24980 KB | n=100 |
26 | Correct | 21 ms | 24980 KB | n=12 |
27 | Correct | 21 ms | 24980 KB | n=100 |
28 | Correct | 26 ms | 24980 KB | n=500 |
29 | Correct | 26 ms | 24980 KB | n=500 |
30 | Correct | 23 ms | 24980 KB | n=500 |
31 | Correct | 28 ms | 24980 KB | n=500 |
32 | Correct | 25 ms | 24980 KB | n=500 |
33 | Correct | 26 ms | 24980 KB | n=500 |
34 | Correct | 25 ms | 24980 KB | n=500 |
35 | Correct | 26 ms | 24980 KB | n=500 |
36 | Correct | 38 ms | 24980 KB | n=500 |
37 | Correct | 38 ms | 24980 KB | n=500 |
38 | Correct | 40 ms | 24980 KB | n=500 |
39 | Correct | 31 ms | 24980 KB | n=500 |
40 | Correct | 31 ms | 24980 KB | n=500 |
41 | Correct | 31 ms | 24980 KB | n=500 |
42 | Correct | 31 ms | 24980 KB | n=500 |
43 | Correct | 31 ms | 24980 KB | n=500 |
44 | Correct | 32 ms | 24980 KB | n=500 |
45 | Correct | 24 ms | 24980 KB | n=500 |
46 | Correct | 27 ms | 24980 KB | n=500 |
47 | Correct | 26 ms | 24980 KB | n=500 |
48 | Correct | 24 ms | 24980 KB | n=500 |
49 | Correct | 26 ms | 24980 KB | n=500 |
50 | Correct | 28 ms | 24980 KB | n=500 |
51 | Correct | 27 ms | 24980 KB | n=500 |
52 | Correct | 29 ms | 24980 KB | n=500 |
53 | Correct | 28 ms | 24980 KB | n=500 |
54 | Correct | 30 ms | 24980 KB | n=500 |
55 | Correct | 25 ms | 24980 KB | n=278 |
56 | Correct | 35 ms | 24980 KB | n=500 |
57 | Correct | 32 ms | 24980 KB | n=500 |
58 | Correct | 35 ms | 24980 KB | n=500 |
59 | Correct | 27 ms | 24980 KB | n=2000 |
60 | Correct | 54 ms | 25064 KB | n=2000 |
61 | Correct | 61 ms | 25104 KB | n=2000 |
62 | Correct | 53 ms | 25104 KB | n=2000 |
63 | Correct | 27 ms | 25104 KB | n=2000 |
64 | Correct | 61 ms | 25104 KB | n=2000 |
65 | Correct | 27 ms | 25104 KB | n=2000 |
66 | Correct | 63 ms | 25104 KB | n=2000 |
67 | Correct | 30 ms | 25104 KB | n=2000 |
68 | Correct | 61 ms | 25104 KB | n=2000 |
69 | Correct | 274 ms | 25260 KB | n=2000 |
70 | Correct | 274 ms | 25260 KB | n=2000 |
71 | Correct | 261 ms | 25260 KB | n=2000 |
72 | Correct | 142 ms | 25260 KB | n=2000 |
73 | Correct | 154 ms | 25260 KB | n=2000 |
74 | Correct | 26 ms | 25260 KB | n=1844 |
75 | Correct | 151 ms | 25260 KB | n=2000 |
76 | Correct | 148 ms | 25260 KB | n=2000 |
77 | Correct | 150 ms | 25260 KB | n=2000 |
78 | Correct | 158 ms | 25260 KB | n=2000 |
79 | Correct | 26 ms | 25260 KB | n=2000 |
80 | Correct | 56 ms | 25260 KB | n=2000 |
81 | Correct | 57 ms | 25260 KB | n=2000 |
82 | Correct | 27 ms | 25260 KB | n=2000 |
83 | Correct | 55 ms | 25260 KB | n=2000 |
84 | Correct | 79 ms | 25260 KB | n=2000 |
85 | Correct | 96 ms | 25260 KB | n=2000 |
86 | Correct | 98 ms | 25260 KB | n=2000 |
87 | Correct | 83 ms | 25260 KB | n=2000 |
88 | Correct | 211 ms | 25260 KB | n=2000 |
89 | Correct | 207 ms | 25260 KB | n=2000 |
90 | Correct | 116 ms | 25260 KB | n=2000 |
91 | Correct | 213 ms | 25260 KB | n=2000 |
92 | Correct | 1185 ms | 38604 KB | n=200000 |
93 | Execution timed out | 4011 ms | 45460 KB | Time limit exceeded |
94 | Halted | 0 ms | 0 KB | - |