# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
797403 | 2023-07-29T10:26:56 Z | kingfran1907 | Birthday gift (IZhO18_treearray) | C++14 | 1055 ms | 74112 KB |
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5+10; const int logo = 20; int n, m, q; vector< int > graph[maxn]; int dp[logo + 10][maxn]; int dis[maxn]; int niz[maxn]; set< pair<int, int> > qs[maxn]; void dfs(int x, int parr) { dp[0][x] = parr; dis[x] = 1 + dis[parr]; for (int tren : graph[x]) { if (tren != parr) dfs(tren, x); } } int lif(int x, int val) { for (int i = 0; i < logo; i++) if (val & (1 << i)) x = dp[i][x]; return x; } int lca(int a, int b) { if (dis[a] > dis[b]) a = lif(a, dis[a] - dis[b]); else b = lif(b, dis[b] - dis[a]); if (a == b) return a; for (int i = logo - 1; i >= 0; i--) { if (dp[i][a] != dp[i][b]) { a = dp[i][a]; b = dp[i][b]; } } return dp[0][a]; } int main() { scanf("%d%d%d", &n, &m, &q); for (int i = 1; i < n; i++) { int a, b; scanf("%d%d", &a, &b); graph[a].push_back(b); graph[b].push_back(a); } dfs(1, 0); for (int i = 1; i < logo; i++) for (int j = 1; j <= n; j++) dp[i][j] = dp[i - 1][dp[i - 1][j]]; for (int i = 0; i < m; i++) { scanf("%d", niz+i); qs[niz[i]].insert({i, i}); if (i > 0) qs[lca(niz[i - 1], niz[i])].insert({i - 1, i}); } while (q--) { int t; scanf("%d", &t); if (t == 1) { int x, v; scanf("%d%d", &x, &v); x--; qs[niz[x]].erase({x, x}); if (x > 0) qs[lca(niz[x - 1], niz[x])].erase({x - 1, x}); if (x < m - 1) qs[lca(niz[x], niz[x + 1])].erase({x, x + 1}); niz[x] = v; qs[niz[x]].insert({x, x}); if (x > 0) qs[lca(niz[x - 1], niz[x])].insert({x - 1, x}); if (x < m - 1) qs[lca(niz[x], niz[x + 1])].insert({x, x + 1}); } else { int l, r, v; scanf("%d%d%d", &l, &r, &v); l--, r--; auto iter = qs[v].lower_bound({l, l}); if (iter == qs[v].end() || iter->second > r) printf("-1 -1\n"); else printf("%d %d\n", iter->first + 1, iter->second + 1); } } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 14420 KB | n=5 |
2 | Correct | 9 ms | 14420 KB | n=100 |
3 | Correct | 8 ms | 14416 KB | n=100 |
4 | Correct | 7 ms | 14528 KB | n=100 |
5 | Correct | 7 ms | 14528 KB | n=100 |
6 | Correct | 8 ms | 14528 KB | n=100 |
7 | Correct | 7 ms | 14420 KB | n=100 |
8 | Correct | 7 ms | 14524 KB | n=100 |
9 | Correct | 10 ms | 14524 KB | n=100 |
10 | Correct | 8 ms | 14420 KB | n=100 |
11 | Correct | 7 ms | 14500 KB | n=100 |
12 | Correct | 7 ms | 14528 KB | n=100 |
13 | Correct | 7 ms | 14524 KB | n=100 |
14 | Correct | 9 ms | 14472 KB | n=100 |
15 | Correct | 9 ms | 14528 KB | n=100 |
16 | Correct | 10 ms | 14528 KB | n=100 |
17 | Correct | 8 ms | 14420 KB | n=100 |
18 | Correct | 11 ms | 14524 KB | n=100 |
19 | Correct | 7 ms | 14528 KB | n=100 |
20 | Correct | 8 ms | 14420 KB | n=100 |
21 | Correct | 10 ms | 14528 KB | n=100 |
22 | Correct | 9 ms | 14420 KB | n=100 |
23 | Correct | 7 ms | 14420 KB | n=100 |
24 | Correct | 8 ms | 14420 KB | n=100 |
25 | Correct | 8 ms | 14420 KB | n=100 |
26 | Correct | 8 ms | 14412 KB | n=12 |
27 | Correct | 8 ms | 14420 KB | n=100 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 14420 KB | n=5 |
2 | Correct | 9 ms | 14420 KB | n=100 |
3 | Correct | 8 ms | 14416 KB | n=100 |
4 | Correct | 7 ms | 14528 KB | n=100 |
5 | Correct | 7 ms | 14528 KB | n=100 |
6 | Correct | 8 ms | 14528 KB | n=100 |
7 | Correct | 7 ms | 14420 KB | n=100 |
8 | Correct | 7 ms | 14524 KB | n=100 |
9 | Correct | 10 ms | 14524 KB | n=100 |
10 | Correct | 8 ms | 14420 KB | n=100 |
11 | Correct | 7 ms | 14500 KB | n=100 |
12 | Correct | 7 ms | 14528 KB | n=100 |
13 | Correct | 7 ms | 14524 KB | n=100 |
14 | Correct | 9 ms | 14472 KB | n=100 |
15 | Correct | 9 ms | 14528 KB | n=100 |
16 | Correct | 10 ms | 14528 KB | n=100 |
17 | Correct | 8 ms | 14420 KB | n=100 |
18 | Correct | 11 ms | 14524 KB | n=100 |
19 | Correct | 7 ms | 14528 KB | n=100 |
20 | Correct | 8 ms | 14420 KB | n=100 |
21 | Correct | 10 ms | 14528 KB | n=100 |
22 | Correct | 9 ms | 14420 KB | n=100 |
23 | Correct | 7 ms | 14420 KB | n=100 |
24 | Correct | 8 ms | 14420 KB | n=100 |
25 | Correct | 8 ms | 14420 KB | n=100 |
26 | Correct | 8 ms | 14412 KB | n=12 |
27 | Correct | 8 ms | 14420 KB | n=100 |
28 | Correct | 12 ms | 14548 KB | n=500 |
29 | Correct | 10 ms | 14548 KB | n=500 |
30 | Correct | 10 ms | 14548 KB | n=500 |
31 | Correct | 8 ms | 14540 KB | n=500 |
32 | Correct | 10 ms | 14548 KB | n=500 |
33 | Correct | 8 ms | 14548 KB | n=500 |
34 | Correct | 9 ms | 14564 KB | n=500 |
35 | Correct | 8 ms | 14548 KB | n=500 |
36 | Correct | 8 ms | 14540 KB | n=500 |
37 | Correct | 12 ms | 14592 KB | n=500 |
38 | Correct | 12 ms | 14608 KB | n=500 |
39 | Correct | 8 ms | 14548 KB | n=500 |
40 | Correct | 9 ms | 14584 KB | n=500 |
41 | Correct | 8 ms | 14548 KB | n=500 |
42 | Correct | 8 ms | 14548 KB | n=500 |
43 | Correct | 10 ms | 14540 KB | n=500 |
44 | Correct | 9 ms | 14548 KB | n=500 |
45 | Correct | 10 ms | 14548 KB | n=500 |
46 | Correct | 7 ms | 14632 KB | n=500 |
47 | Correct | 9 ms | 14672 KB | n=500 |
48 | Correct | 10 ms | 14544 KB | n=500 |
49 | Correct | 8 ms | 14624 KB | n=500 |
50 | Correct | 7 ms | 14532 KB | n=500 |
51 | Correct | 8 ms | 14548 KB | n=500 |
52 | Correct | 9 ms | 14548 KB | n=500 |
53 | Correct | 10 ms | 14536 KB | n=500 |
54 | Correct | 9 ms | 14532 KB | n=500 |
55 | Correct | 8 ms | 14528 KB | n=278 |
56 | Correct | 10 ms | 14536 KB | n=500 |
57 | Correct | 11 ms | 14548 KB | n=500 |
58 | Correct | 9 ms | 14548 KB | n=500 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 14420 KB | n=5 |
2 | Correct | 9 ms | 14420 KB | n=100 |
3 | Correct | 8 ms | 14416 KB | n=100 |
4 | Correct | 7 ms | 14528 KB | n=100 |
5 | Correct | 7 ms | 14528 KB | n=100 |
6 | Correct | 8 ms | 14528 KB | n=100 |
7 | Correct | 7 ms | 14420 KB | n=100 |
8 | Correct | 7 ms | 14524 KB | n=100 |
9 | Correct | 10 ms | 14524 KB | n=100 |
10 | Correct | 8 ms | 14420 KB | n=100 |
11 | Correct | 7 ms | 14500 KB | n=100 |
12 | Correct | 7 ms | 14528 KB | n=100 |
13 | Correct | 7 ms | 14524 KB | n=100 |
14 | Correct | 9 ms | 14472 KB | n=100 |
15 | Correct | 9 ms | 14528 KB | n=100 |
16 | Correct | 10 ms | 14528 KB | n=100 |
17 | Correct | 8 ms | 14420 KB | n=100 |
18 | Correct | 11 ms | 14524 KB | n=100 |
19 | Correct | 7 ms | 14528 KB | n=100 |
20 | Correct | 8 ms | 14420 KB | n=100 |
21 | Correct | 10 ms | 14528 KB | n=100 |
22 | Correct | 9 ms | 14420 KB | n=100 |
23 | Correct | 7 ms | 14420 KB | n=100 |
24 | Correct | 8 ms | 14420 KB | n=100 |
25 | Correct | 8 ms | 14420 KB | n=100 |
26 | Correct | 8 ms | 14412 KB | n=12 |
27 | Correct | 8 ms | 14420 KB | n=100 |
28 | Correct | 12 ms | 14548 KB | n=500 |
29 | Correct | 10 ms | 14548 KB | n=500 |
30 | Correct | 10 ms | 14548 KB | n=500 |
31 | Correct | 8 ms | 14540 KB | n=500 |
32 | Correct | 10 ms | 14548 KB | n=500 |
33 | Correct | 8 ms | 14548 KB | n=500 |
34 | Correct | 9 ms | 14564 KB | n=500 |
35 | Correct | 8 ms | 14548 KB | n=500 |
36 | Correct | 8 ms | 14540 KB | n=500 |
37 | Correct | 12 ms | 14592 KB | n=500 |
38 | Correct | 12 ms | 14608 KB | n=500 |
39 | Correct | 8 ms | 14548 KB | n=500 |
40 | Correct | 9 ms | 14584 KB | n=500 |
41 | Correct | 8 ms | 14548 KB | n=500 |
42 | Correct | 8 ms | 14548 KB | n=500 |
43 | Correct | 10 ms | 14540 KB | n=500 |
44 | Correct | 9 ms | 14548 KB | n=500 |
45 | Correct | 10 ms | 14548 KB | n=500 |
46 | Correct | 7 ms | 14632 KB | n=500 |
47 | Correct | 9 ms | 14672 KB | n=500 |
48 | Correct | 10 ms | 14544 KB | n=500 |
49 | Correct | 8 ms | 14624 KB | n=500 |
50 | Correct | 7 ms | 14532 KB | n=500 |
51 | Correct | 8 ms | 14548 KB | n=500 |
52 | Correct | 9 ms | 14548 KB | n=500 |
53 | Correct | 10 ms | 14536 KB | n=500 |
54 | Correct | 9 ms | 14532 KB | n=500 |
55 | Correct | 8 ms | 14528 KB | n=278 |
56 | Correct | 10 ms | 14536 KB | n=500 |
57 | Correct | 11 ms | 14548 KB | n=500 |
58 | Correct | 9 ms | 14548 KB | n=500 |
59 | Correct | 10 ms | 14932 KB | n=2000 |
60 | Correct | 10 ms | 15060 KB | n=2000 |
61 | Correct | 10 ms | 14928 KB | n=2000 |
62 | Correct | 11 ms | 15012 KB | n=2000 |
63 | Correct | 13 ms | 14896 KB | n=2000 |
64 | Correct | 11 ms | 14920 KB | n=2000 |
65 | Correct | 10 ms | 14920 KB | n=2000 |
66 | Correct | 16 ms | 14912 KB | n=2000 |
67 | Correct | 11 ms | 14924 KB | n=2000 |
68 | Correct | 10 ms | 14924 KB | n=2000 |
69 | Correct | 11 ms | 14928 KB | n=2000 |
70 | Correct | 11 ms | 14924 KB | n=2000 |
71 | Correct | 9 ms | 14932 KB | n=2000 |
72 | Correct | 10 ms | 14920 KB | n=2000 |
73 | Correct | 10 ms | 14924 KB | n=2000 |
74 | Correct | 12 ms | 14920 KB | n=1844 |
75 | Correct | 9 ms | 14932 KB | n=2000 |
76 | Correct | 11 ms | 14992 KB | n=2000 |
77 | Correct | 13 ms | 14996 KB | n=2000 |
78 | Correct | 10 ms | 14920 KB | n=2000 |
79 | Correct | 10 ms | 14932 KB | n=2000 |
80 | Correct | 12 ms | 15052 KB | n=2000 |
81 | Correct | 12 ms | 14920 KB | n=2000 |
82 | Correct | 10 ms | 14932 KB | n=2000 |
83 | Correct | 10 ms | 15036 KB | n=2000 |
84 | Correct | 10 ms | 14896 KB | n=2000 |
85 | Correct | 12 ms | 14960 KB | n=2000 |
86 | Correct | 14 ms | 14920 KB | n=2000 |
87 | Correct | 11 ms | 14928 KB | n=2000 |
88 | Correct | 11 ms | 15060 KB | n=2000 |
89 | Correct | 15 ms | 15012 KB | n=2000 |
90 | Correct | 10 ms | 15056 KB | n=2000 |
91 | Correct | 10 ms | 14884 KB | n=2000 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 14420 KB | n=5 |
2 | Correct | 9 ms | 14420 KB | n=100 |
3 | Correct | 8 ms | 14416 KB | n=100 |
4 | Correct | 7 ms | 14528 KB | n=100 |
5 | Correct | 7 ms | 14528 KB | n=100 |
6 | Correct | 8 ms | 14528 KB | n=100 |
7 | Correct | 7 ms | 14420 KB | n=100 |
8 | Correct | 7 ms | 14524 KB | n=100 |
9 | Correct | 10 ms | 14524 KB | n=100 |
10 | Correct | 8 ms | 14420 KB | n=100 |
11 | Correct | 7 ms | 14500 KB | n=100 |
12 | Correct | 7 ms | 14528 KB | n=100 |
13 | Correct | 7 ms | 14524 KB | n=100 |
14 | Correct | 9 ms | 14472 KB | n=100 |
15 | Correct | 9 ms | 14528 KB | n=100 |
16 | Correct | 10 ms | 14528 KB | n=100 |
17 | Correct | 8 ms | 14420 KB | n=100 |
18 | Correct | 11 ms | 14524 KB | n=100 |
19 | Correct | 7 ms | 14528 KB | n=100 |
20 | Correct | 8 ms | 14420 KB | n=100 |
21 | Correct | 10 ms | 14528 KB | n=100 |
22 | Correct | 9 ms | 14420 KB | n=100 |
23 | Correct | 7 ms | 14420 KB | n=100 |
24 | Correct | 8 ms | 14420 KB | n=100 |
25 | Correct | 8 ms | 14420 KB | n=100 |
26 | Correct | 8 ms | 14412 KB | n=12 |
27 | Correct | 8 ms | 14420 KB | n=100 |
28 | Correct | 12 ms | 14548 KB | n=500 |
29 | Correct | 10 ms | 14548 KB | n=500 |
30 | Correct | 10 ms | 14548 KB | n=500 |
31 | Correct | 8 ms | 14540 KB | n=500 |
32 | Correct | 10 ms | 14548 KB | n=500 |
33 | Correct | 8 ms | 14548 KB | n=500 |
34 | Correct | 9 ms | 14564 KB | n=500 |
35 | Correct | 8 ms | 14548 KB | n=500 |
36 | Correct | 8 ms | 14540 KB | n=500 |
37 | Correct | 12 ms | 14592 KB | n=500 |
38 | Correct | 12 ms | 14608 KB | n=500 |
39 | Correct | 8 ms | 14548 KB | n=500 |
40 | Correct | 9 ms | 14584 KB | n=500 |
41 | Correct | 8 ms | 14548 KB | n=500 |
42 | Correct | 8 ms | 14548 KB | n=500 |
43 | Correct | 10 ms | 14540 KB | n=500 |
44 | Correct | 9 ms | 14548 KB | n=500 |
45 | Correct | 10 ms | 14548 KB | n=500 |
46 | Correct | 7 ms | 14632 KB | n=500 |
47 | Correct | 9 ms | 14672 KB | n=500 |
48 | Correct | 10 ms | 14544 KB | n=500 |
49 | Correct | 8 ms | 14624 KB | n=500 |
50 | Correct | 7 ms | 14532 KB | n=500 |
51 | Correct | 8 ms | 14548 KB | n=500 |
52 | Correct | 9 ms | 14548 KB | n=500 |
53 | Correct | 10 ms | 14536 KB | n=500 |
54 | Correct | 9 ms | 14532 KB | n=500 |
55 | Correct | 8 ms | 14528 KB | n=278 |
56 | Correct | 10 ms | 14536 KB | n=500 |
57 | Correct | 11 ms | 14548 KB | n=500 |
58 | Correct | 9 ms | 14548 KB | n=500 |
59 | Correct | 10 ms | 14932 KB | n=2000 |
60 | Correct | 10 ms | 15060 KB | n=2000 |
61 | Correct | 10 ms | 14928 KB | n=2000 |
62 | Correct | 11 ms | 15012 KB | n=2000 |
63 | Correct | 13 ms | 14896 KB | n=2000 |
64 | Correct | 11 ms | 14920 KB | n=2000 |
65 | Correct | 10 ms | 14920 KB | n=2000 |
66 | Correct | 16 ms | 14912 KB | n=2000 |
67 | Correct | 11 ms | 14924 KB | n=2000 |
68 | Correct | 10 ms | 14924 KB | n=2000 |
69 | Correct | 11 ms | 14928 KB | n=2000 |
70 | Correct | 11 ms | 14924 KB | n=2000 |
71 | Correct | 9 ms | 14932 KB | n=2000 |
72 | Correct | 10 ms | 14920 KB | n=2000 |
73 | Correct | 10 ms | 14924 KB | n=2000 |
74 | Correct | 12 ms | 14920 KB | n=1844 |
75 | Correct | 9 ms | 14932 KB | n=2000 |
76 | Correct | 11 ms | 14992 KB | n=2000 |
77 | Correct | 13 ms | 14996 KB | n=2000 |
78 | Correct | 10 ms | 14920 KB | n=2000 |
79 | Correct | 10 ms | 14932 KB | n=2000 |
80 | Correct | 12 ms | 15052 KB | n=2000 |
81 | Correct | 12 ms | 14920 KB | n=2000 |
82 | Correct | 10 ms | 14932 KB | n=2000 |
83 | Correct | 10 ms | 15036 KB | n=2000 |
84 | Correct | 10 ms | 14896 KB | n=2000 |
85 | Correct | 12 ms | 14960 KB | n=2000 |
86 | Correct | 14 ms | 14920 KB | n=2000 |
87 | Correct | 11 ms | 14928 KB | n=2000 |
88 | Correct | 11 ms | 15060 KB | n=2000 |
89 | Correct | 15 ms | 15012 KB | n=2000 |
90 | Correct | 10 ms | 15056 KB | n=2000 |
91 | Correct | 10 ms | 14884 KB | n=2000 |
92 | Correct | 926 ms | 65076 KB | n=200000 |
93 | Correct | 947 ms | 68756 KB | n=200000 |
94 | Correct | 957 ms | 72260 KB | n=200000 |
95 | Correct | 801 ms | 64816 KB | n=200000 |
96 | Correct | 746 ms | 64892 KB | n=200000 |
97 | Correct | 1024 ms | 68324 KB | n=200000 |
98 | Correct | 830 ms | 64848 KB | n=200000 |
99 | Correct | 1055 ms | 64896 KB | n=200000 |
100 | Correct | 899 ms | 64876 KB | n=200000 |
101 | Correct | 858 ms | 74112 KB | n=200000 |
102 | Correct | 480 ms | 66116 KB | n=200000 |
103 | Correct | 425 ms | 66144 KB | n=200000 |
104 | Correct | 424 ms | 66104 KB | n=200000 |
105 | Correct | 428 ms | 66472 KB | n=200000 |
106 | Correct | 409 ms | 66484 KB | n=200000 |
107 | Correct | 386 ms | 66488 KB | n=200000 |
108 | Correct | 786 ms | 64972 KB | n=200000 |
109 | Correct | 833 ms | 64980 KB | n=200000 |
110 | Correct | 850 ms | 65108 KB | n=200000 |
111 | Correct | 710 ms | 64512 KB | n=200000 |
112 | Correct | 796 ms | 73108 KB | n=200000 |
113 | Correct | 922 ms | 68608 KB | n=200000 |
114 | Correct | 776 ms | 64408 KB | n=200000 |
115 | Correct | 1006 ms | 66480 KB | n=200000 |
116 | Correct | 727 ms | 65112 KB | n=200000 |
117 | Correct | 752 ms | 73552 KB | n=200000 |
118 | Correct | 983 ms | 67536 KB | n=200000 |
119 | Correct | 706 ms | 65060 KB | n=200000 |
120 | Correct | 792 ms | 73604 KB | n=200000 |
121 | Correct | 792 ms | 73612 KB | n=200000 |
122 | Correct | 761 ms | 73792 KB | n=200000 |
123 | Correct | 446 ms | 65972 KB | n=200000 |
124 | Correct | 167 ms | 29356 KB | n=25264 |