# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
528163 | 2022-02-19T14:42:53 Z | peuch | Birthday gift (IZhO18_treearray) | C++17 | 1068 ms | 91844 KB |
#include<bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 10; const int MAXL = 22; int n, m, q; int v[MAXN]; int prof[MAXN]; int dp[MAXN][MAXL]; vector<int> ar[MAXN]; set<int> loc[MAXN]; set<int> loc2[MAXN]; void preCalc(int cur); int lca(int a, int b); int main(){ scanf("%d %d %d", &n, &m, &q); for(int i = 1; i < n; i++){ int a, b; scanf("%d %d", &a, &b); ar[a].push_back(b); ar[b].push_back(a); } preCalc(1); for(int i = 1; i <= m; i++){ scanf("%d", &v[i]); int anc = lca(v[i - 1], v[i]); loc[anc].insert(i - 1); loc2[v[i]].insert(i); } for(int i = 1; i <= q; i++){ int t; scanf("%d", &t); if(t == 1){ int a, b; scanf("%d %d", &a, &b); int anc; anc = lca(v[a], v[a + 1]); loc[anc].erase(a); anc = lca(v[a - 1], v[a]); loc[anc].erase(a - 1); loc2[v[a]].erase(a); v[a] = b; anc = lca(v[a], v[a + 1]); loc[anc].insert(a); anc = lca(v[a - 1], v[a]); loc[anc].insert(a - 1); loc2[v[a]].insert(a); } if(t == 2){ int a, b, c; scanf("%d %d %d", &a, &b, &c); set<int> :: iterator it = loc[c].lower_bound(a); if(it == loc[c].end() || *it >= b){ it = loc2[c].lower_bound(a); if(it == loc2[c].end() || *it > b){ printf("-1 -1\n"); continue; } printf("%d %d\n", *it, *it); continue; } printf("%d %d\n", *it, *it + 1); } } } void preCalc(int cur){ for(int k = 1; k < MAXL; k++) dp[cur][k] = dp[dp[cur][k - 1]][k - 1]; for(int i = 0; i < ar[cur].size(); i++){ int viz = ar[cur][i]; if(viz == dp[cur][0]) continue; dp[viz][0] = cur; prof[viz] = prof[cur] + 1; preCalc(viz); } } int lca(int a, int b){ if(prof[a] < prof[b]) swap(a, b); int d = prof[a] - prof[b]; for(int k = 0; k < MAXL; k++) if((1 << k) & d) a = dp[a][k]; if(a == b) return b; for(int k = MAXL - 1; k >= 0; k--) if(dp[a][k] != dp[b][k]) a = dp[a][k], b = dp[b][k]; return dp[a][0]; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 23756 KB | n=5 |
2 | Correct | 13 ms | 23756 KB | n=100 |
3 | Correct | 12 ms | 23792 KB | n=100 |
4 | Correct | 12 ms | 23784 KB | n=100 |
5 | Correct | 12 ms | 23808 KB | n=100 |
6 | Correct | 12 ms | 23756 KB | n=100 |
7 | Correct | 12 ms | 23780 KB | n=100 |
8 | Correct | 12 ms | 23756 KB | n=100 |
9 | Correct | 12 ms | 23792 KB | n=100 |
10 | Correct | 12 ms | 23756 KB | n=100 |
11 | Correct | 12 ms | 23756 KB | n=100 |
12 | Correct | 12 ms | 23760 KB | n=100 |
13 | Correct | 12 ms | 23784 KB | n=100 |
14 | Correct | 12 ms | 23756 KB | n=100 |
15 | Correct | 14 ms | 23756 KB | n=100 |
16 | Correct | 12 ms | 23756 KB | n=100 |
17 | Correct | 12 ms | 23756 KB | n=100 |
18 | Correct | 12 ms | 23772 KB | n=100 |
19 | Correct | 12 ms | 23792 KB | n=100 |
20 | Correct | 12 ms | 23792 KB | n=100 |
21 | Correct | 12 ms | 23756 KB | n=100 |
22 | Correct | 12 ms | 23756 KB | n=100 |
23 | Correct | 14 ms | 23824 KB | n=100 |
24 | Correct | 12 ms | 23792 KB | n=100 |
25 | Correct | 12 ms | 23792 KB | n=100 |
26 | Correct | 13 ms | 23744 KB | n=12 |
27 | Correct | 13 ms | 23756 KB | n=100 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 23756 KB | n=5 |
2 | Correct | 13 ms | 23756 KB | n=100 |
3 | Correct | 12 ms | 23792 KB | n=100 |
4 | Correct | 12 ms | 23784 KB | n=100 |
5 | Correct | 12 ms | 23808 KB | n=100 |
6 | Correct | 12 ms | 23756 KB | n=100 |
7 | Correct | 12 ms | 23780 KB | n=100 |
8 | Correct | 12 ms | 23756 KB | n=100 |
9 | Correct | 12 ms | 23792 KB | n=100 |
10 | Correct | 12 ms | 23756 KB | n=100 |
11 | Correct | 12 ms | 23756 KB | n=100 |
12 | Correct | 12 ms | 23760 KB | n=100 |
13 | Correct | 12 ms | 23784 KB | n=100 |
14 | Correct | 12 ms | 23756 KB | n=100 |
15 | Correct | 14 ms | 23756 KB | n=100 |
16 | Correct | 12 ms | 23756 KB | n=100 |
17 | Correct | 12 ms | 23756 KB | n=100 |
18 | Correct | 12 ms | 23772 KB | n=100 |
19 | Correct | 12 ms | 23792 KB | n=100 |
20 | Correct | 12 ms | 23792 KB | n=100 |
21 | Correct | 12 ms | 23756 KB | n=100 |
22 | Correct | 12 ms | 23756 KB | n=100 |
23 | Correct | 14 ms | 23824 KB | n=100 |
24 | Correct | 12 ms | 23792 KB | n=100 |
25 | Correct | 12 ms | 23792 KB | n=100 |
26 | Correct | 13 ms | 23744 KB | n=12 |
27 | Correct | 13 ms | 23756 KB | n=100 |
28 | Correct | 13 ms | 23920 KB | n=500 |
29 | Correct | 12 ms | 23848 KB | n=500 |
30 | Correct | 13 ms | 23884 KB | n=500 |
31 | Correct | 13 ms | 23884 KB | n=500 |
32 | Correct | 14 ms | 23884 KB | n=500 |
33 | Correct | 15 ms | 23936 KB | n=500 |
34 | Correct | 15 ms | 23888 KB | n=500 |
35 | Correct | 16 ms | 23884 KB | n=500 |
36 | Correct | 13 ms | 23892 KB | n=500 |
37 | Correct | 16 ms | 23792 KB | n=500 |
38 | Correct | 12 ms | 23792 KB | n=500 |
39 | Correct | 15 ms | 23916 KB | n=500 |
40 | Correct | 13 ms | 23884 KB | n=500 |
41 | Correct | 12 ms | 23804 KB | n=500 |
42 | Correct | 15 ms | 23904 KB | n=500 |
43 | Correct | 13 ms | 23920 KB | n=500 |
44 | Correct | 13 ms | 23884 KB | n=500 |
45 | Correct | 13 ms | 23872 KB | n=500 |
46 | Correct | 13 ms | 23936 KB | n=500 |
47 | Correct | 14 ms | 23848 KB | n=500 |
48 | Correct | 13 ms | 23856 KB | n=500 |
49 | Correct | 13 ms | 23884 KB | n=500 |
50 | Correct | 15 ms | 23860 KB | n=500 |
51 | Correct | 13 ms | 23924 KB | n=500 |
52 | Correct | 13 ms | 23884 KB | n=500 |
53 | Correct | 13 ms | 23848 KB | n=500 |
54 | Correct | 12 ms | 23884 KB | n=500 |
55 | Correct | 13 ms | 23884 KB | n=278 |
56 | Correct | 18 ms | 23836 KB | n=500 |
57 | Correct | 13 ms | 23884 KB | n=500 |
58 | Correct | 13 ms | 23884 KB | n=500 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 23756 KB | n=5 |
2 | Correct | 13 ms | 23756 KB | n=100 |
3 | Correct | 12 ms | 23792 KB | n=100 |
4 | Correct | 12 ms | 23784 KB | n=100 |
5 | Correct | 12 ms | 23808 KB | n=100 |
6 | Correct | 12 ms | 23756 KB | n=100 |
7 | Correct | 12 ms | 23780 KB | n=100 |
8 | Correct | 12 ms | 23756 KB | n=100 |
9 | Correct | 12 ms | 23792 KB | n=100 |
10 | Correct | 12 ms | 23756 KB | n=100 |
11 | Correct | 12 ms | 23756 KB | n=100 |
12 | Correct | 12 ms | 23760 KB | n=100 |
13 | Correct | 12 ms | 23784 KB | n=100 |
14 | Correct | 12 ms | 23756 KB | n=100 |
15 | Correct | 14 ms | 23756 KB | n=100 |
16 | Correct | 12 ms | 23756 KB | n=100 |
17 | Correct | 12 ms | 23756 KB | n=100 |
18 | Correct | 12 ms | 23772 KB | n=100 |
19 | Correct | 12 ms | 23792 KB | n=100 |
20 | Correct | 12 ms | 23792 KB | n=100 |
21 | Correct | 12 ms | 23756 KB | n=100 |
22 | Correct | 12 ms | 23756 KB | n=100 |
23 | Correct | 14 ms | 23824 KB | n=100 |
24 | Correct | 12 ms | 23792 KB | n=100 |
25 | Correct | 12 ms | 23792 KB | n=100 |
26 | Correct | 13 ms | 23744 KB | n=12 |
27 | Correct | 13 ms | 23756 KB | n=100 |
28 | Correct | 13 ms | 23920 KB | n=500 |
29 | Correct | 12 ms | 23848 KB | n=500 |
30 | Correct | 13 ms | 23884 KB | n=500 |
31 | Correct | 13 ms | 23884 KB | n=500 |
32 | Correct | 14 ms | 23884 KB | n=500 |
33 | Correct | 15 ms | 23936 KB | n=500 |
34 | Correct | 15 ms | 23888 KB | n=500 |
35 | Correct | 16 ms | 23884 KB | n=500 |
36 | Correct | 13 ms | 23892 KB | n=500 |
37 | Correct | 16 ms | 23792 KB | n=500 |
38 | Correct | 12 ms | 23792 KB | n=500 |
39 | Correct | 15 ms | 23916 KB | n=500 |
40 | Correct | 13 ms | 23884 KB | n=500 |
41 | Correct | 12 ms | 23804 KB | n=500 |
42 | Correct | 15 ms | 23904 KB | n=500 |
43 | Correct | 13 ms | 23920 KB | n=500 |
44 | Correct | 13 ms | 23884 KB | n=500 |
45 | Correct | 13 ms | 23872 KB | n=500 |
46 | Correct | 13 ms | 23936 KB | n=500 |
47 | Correct | 14 ms | 23848 KB | n=500 |
48 | Correct | 13 ms | 23856 KB | n=500 |
49 | Correct | 13 ms | 23884 KB | n=500 |
50 | Correct | 15 ms | 23860 KB | n=500 |
51 | Correct | 13 ms | 23924 KB | n=500 |
52 | Correct | 13 ms | 23884 KB | n=500 |
53 | Correct | 13 ms | 23848 KB | n=500 |
54 | Correct | 12 ms | 23884 KB | n=500 |
55 | Correct | 13 ms | 23884 KB | n=278 |
56 | Correct | 18 ms | 23836 KB | n=500 |
57 | Correct | 13 ms | 23884 KB | n=500 |
58 | Correct | 13 ms | 23884 KB | n=500 |
59 | Correct | 17 ms | 24180 KB | n=2000 |
60 | Correct | 15 ms | 24404 KB | n=2000 |
61 | Correct | 16 ms | 24268 KB | n=2000 |
62 | Correct | 17 ms | 24332 KB | n=2000 |
63 | Correct | 20 ms | 24268 KB | n=2000 |
64 | Correct | 16 ms | 24280 KB | n=2000 |
65 | Correct | 16 ms | 24228 KB | n=2000 |
66 | Correct | 19 ms | 24396 KB | n=2000 |
67 | Correct | 16 ms | 24268 KB | n=2000 |
68 | Correct | 19 ms | 24364 KB | n=2000 |
69 | Correct | 16 ms | 24268 KB | n=2000 |
70 | Correct | 15 ms | 24300 KB | n=2000 |
71 | Correct | 15 ms | 24312 KB | n=2000 |
72 | Correct | 15 ms | 24268 KB | n=2000 |
73 | Correct | 15 ms | 24268 KB | n=2000 |
74 | Correct | 18 ms | 24232 KB | n=1844 |
75 | Correct | 18 ms | 24188 KB | n=2000 |
76 | Correct | 15 ms | 24296 KB | n=2000 |
77 | Correct | 16 ms | 24268 KB | n=2000 |
78 | Correct | 16 ms | 24308 KB | n=2000 |
79 | Correct | 15 ms | 24220 KB | n=2000 |
80 | Correct | 18 ms | 24340 KB | n=2000 |
81 | Correct | 20 ms | 24352 KB | n=2000 |
82 | Correct | 20 ms | 24268 KB | n=2000 |
83 | Correct | 16 ms | 24308 KB | n=2000 |
84 | Correct | 17 ms | 24316 KB | n=2000 |
85 | Correct | 18 ms | 24356 KB | n=2000 |
86 | Correct | 16 ms | 24316 KB | n=2000 |
87 | Correct | 17 ms | 24268 KB | n=2000 |
88 | Correct | 15 ms | 24396 KB | n=2000 |
89 | Correct | 20 ms | 24352 KB | n=2000 |
90 | Correct | 16 ms | 24468 KB | n=2000 |
91 | Correct | 15 ms | 24268 KB | n=2000 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 23756 KB | n=5 |
2 | Correct | 13 ms | 23756 KB | n=100 |
3 | Correct | 12 ms | 23792 KB | n=100 |
4 | Correct | 12 ms | 23784 KB | n=100 |
5 | Correct | 12 ms | 23808 KB | n=100 |
6 | Correct | 12 ms | 23756 KB | n=100 |
7 | Correct | 12 ms | 23780 KB | n=100 |
8 | Correct | 12 ms | 23756 KB | n=100 |
9 | Correct | 12 ms | 23792 KB | n=100 |
10 | Correct | 12 ms | 23756 KB | n=100 |
11 | Correct | 12 ms | 23756 KB | n=100 |
12 | Correct | 12 ms | 23760 KB | n=100 |
13 | Correct | 12 ms | 23784 KB | n=100 |
14 | Correct | 12 ms | 23756 KB | n=100 |
15 | Correct | 14 ms | 23756 KB | n=100 |
16 | Correct | 12 ms | 23756 KB | n=100 |
17 | Correct | 12 ms | 23756 KB | n=100 |
18 | Correct | 12 ms | 23772 KB | n=100 |
19 | Correct | 12 ms | 23792 KB | n=100 |
20 | Correct | 12 ms | 23792 KB | n=100 |
21 | Correct | 12 ms | 23756 KB | n=100 |
22 | Correct | 12 ms | 23756 KB | n=100 |
23 | Correct | 14 ms | 23824 KB | n=100 |
24 | Correct | 12 ms | 23792 KB | n=100 |
25 | Correct | 12 ms | 23792 KB | n=100 |
26 | Correct | 13 ms | 23744 KB | n=12 |
27 | Correct | 13 ms | 23756 KB | n=100 |
28 | Correct | 13 ms | 23920 KB | n=500 |
29 | Correct | 12 ms | 23848 KB | n=500 |
30 | Correct | 13 ms | 23884 KB | n=500 |
31 | Correct | 13 ms | 23884 KB | n=500 |
32 | Correct | 14 ms | 23884 KB | n=500 |
33 | Correct | 15 ms | 23936 KB | n=500 |
34 | Correct | 15 ms | 23888 KB | n=500 |
35 | Correct | 16 ms | 23884 KB | n=500 |
36 | Correct | 13 ms | 23892 KB | n=500 |
37 | Correct | 16 ms | 23792 KB | n=500 |
38 | Correct | 12 ms | 23792 KB | n=500 |
39 | Correct | 15 ms | 23916 KB | n=500 |
40 | Correct | 13 ms | 23884 KB | n=500 |
41 | Correct | 12 ms | 23804 KB | n=500 |
42 | Correct | 15 ms | 23904 KB | n=500 |
43 | Correct | 13 ms | 23920 KB | n=500 |
44 | Correct | 13 ms | 23884 KB | n=500 |
45 | Correct | 13 ms | 23872 KB | n=500 |
46 | Correct | 13 ms | 23936 KB | n=500 |
47 | Correct | 14 ms | 23848 KB | n=500 |
48 | Correct | 13 ms | 23856 KB | n=500 |
49 | Correct | 13 ms | 23884 KB | n=500 |
50 | Correct | 15 ms | 23860 KB | n=500 |
51 | Correct | 13 ms | 23924 KB | n=500 |
52 | Correct | 13 ms | 23884 KB | n=500 |
53 | Correct | 13 ms | 23848 KB | n=500 |
54 | Correct | 12 ms | 23884 KB | n=500 |
55 | Correct | 13 ms | 23884 KB | n=278 |
56 | Correct | 18 ms | 23836 KB | n=500 |
57 | Correct | 13 ms | 23884 KB | n=500 |
58 | Correct | 13 ms | 23884 KB | n=500 |
59 | Correct | 17 ms | 24180 KB | n=2000 |
60 | Correct | 15 ms | 24404 KB | n=2000 |
61 | Correct | 16 ms | 24268 KB | n=2000 |
62 | Correct | 17 ms | 24332 KB | n=2000 |
63 | Correct | 20 ms | 24268 KB | n=2000 |
64 | Correct | 16 ms | 24280 KB | n=2000 |
65 | Correct | 16 ms | 24228 KB | n=2000 |
66 | Correct | 19 ms | 24396 KB | n=2000 |
67 | Correct | 16 ms | 24268 KB | n=2000 |
68 | Correct | 19 ms | 24364 KB | n=2000 |
69 | Correct | 16 ms | 24268 KB | n=2000 |
70 | Correct | 15 ms | 24300 KB | n=2000 |
71 | Correct | 15 ms | 24312 KB | n=2000 |
72 | Correct | 15 ms | 24268 KB | n=2000 |
73 | Correct | 15 ms | 24268 KB | n=2000 |
74 | Correct | 18 ms | 24232 KB | n=1844 |
75 | Correct | 18 ms | 24188 KB | n=2000 |
76 | Correct | 15 ms | 24296 KB | n=2000 |
77 | Correct | 16 ms | 24268 KB | n=2000 |
78 | Correct | 16 ms | 24308 KB | n=2000 |
79 | Correct | 15 ms | 24220 KB | n=2000 |
80 | Correct | 18 ms | 24340 KB | n=2000 |
81 | Correct | 20 ms | 24352 KB | n=2000 |
82 | Correct | 20 ms | 24268 KB | n=2000 |
83 | Correct | 16 ms | 24308 KB | n=2000 |
84 | Correct | 17 ms | 24316 KB | n=2000 |
85 | Correct | 18 ms | 24356 KB | n=2000 |
86 | Correct | 16 ms | 24316 KB | n=2000 |
87 | Correct | 17 ms | 24268 KB | n=2000 |
88 | Correct | 15 ms | 24396 KB | n=2000 |
89 | Correct | 20 ms | 24352 KB | n=2000 |
90 | Correct | 16 ms | 24468 KB | n=2000 |
91 | Correct | 15 ms | 24268 KB | n=2000 |
92 | Correct | 733 ms | 76080 KB | n=200000 |
93 | Correct | 989 ms | 84184 KB | n=200000 |
94 | Correct | 988 ms | 89596 KB | n=200000 |
95 | Correct | 718 ms | 75844 KB | n=200000 |
96 | Correct | 826 ms | 75764 KB | n=200000 |
97 | Correct | 1066 ms | 82544 KB | n=200000 |
98 | Correct | 737 ms | 75868 KB | n=200000 |
99 | Correct | 901 ms | 76044 KB | n=200000 |
100 | Correct | 750 ms | 75912 KB | n=200000 |
101 | Correct | 976 ms | 91844 KB | n=200000 |
102 | Correct | 456 ms | 77004 KB | n=200000 |
103 | Correct | 471 ms | 77132 KB | n=200000 |
104 | Correct | 504 ms | 77040 KB | n=200000 |
105 | Correct | 466 ms | 77424 KB | n=200000 |
106 | Correct | 566 ms | 77400 KB | n=200000 |
107 | Correct | 497 ms | 77444 KB | n=200000 |
108 | Correct | 867 ms | 75924 KB | n=200000 |
109 | Correct | 835 ms | 75944 KB | n=200000 |
110 | Correct | 834 ms | 75984 KB | n=200000 |
111 | Correct | 756 ms | 75324 KB | n=200000 |
112 | Correct | 1047 ms | 90136 KB | n=200000 |
113 | Correct | 1018 ms | 82552 KB | n=200000 |
114 | Correct | 764 ms | 75432 KB | n=200000 |
115 | Correct | 1068 ms | 79008 KB | n=200000 |
116 | Correct | 707 ms | 76004 KB | n=200000 |
117 | Correct | 989 ms | 90812 KB | n=200000 |
118 | Correct | 1041 ms | 80788 KB | n=200000 |
119 | Correct | 679 ms | 76040 KB | n=200000 |
120 | Correct | 947 ms | 90768 KB | n=200000 |
121 | Correct | 908 ms | 90776 KB | n=200000 |
122 | Correct | 948 ms | 91252 KB | n=200000 |
123 | Correct | 493 ms | 77380 KB | n=200000 |
124 | Correct | 214 ms | 39520 KB | n=25264 |