# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
54196 | 2018-07-02T18:34:55 Z | ulna | Birthday gift (IZhO18_treearray) | C++11 | 1893 ms | 98516 KB |
#pragma GCC optimize ("O3") #include <bits/stdc++.h> using namespace std; // why am I so weak const int maxn = 2e5; int n, m, q; int a[maxn]; vector<int> g[maxn]; #define MAX_LOG 18 int depth[maxn]; int par[MAX_LOG][maxn]; set<int> s[maxn]; set<int> ss[maxn]; void dfs(int v, int par = -1, int d = 0) { ::par[0][v] = par; depth[v] = d; for (auto u : g[v]) if (u != par) { dfs(u, v, d + 1); } } inline int lca(int v, int u) { if (depth[u] > depth[v]) swap(u, v); for (int i = 0; i < MAX_LOG; i++) if (((depth[v] - depth[u]) >> i) & 1) { v = par[i][v]; } if (u == v) return u; for (int i = MAX_LOG - 1; i >= 0; i--) if (par[i][v] != par[i][u]) { v = par[i][v], u = par[i][u]; } return par[0][v]; } inline void upd(int id, int mode) { if (id < 0 || id + 1 >= m) return; if (mode == -1) ss[lca(a[id], a[id + 1])].erase(id); else ss[lca(a[id], a[id + 1])].insert(id); } int main() { cin >> n >> m >> q; for (int i = 0; i + 1 < n; i++) { int x, y; scanf("%d %d", &x, &y); x--, y--; g[x].push_back(y); g[y].push_back(x); } dfs(0); for (int i = 0; i + 1 < MAX_LOG; i++) for (int j = 0; j < n; j++) { if (par[i][j] < 0) par[i + 1][j] = -1; else par[i + 1][j] = par[i][par[i][j]]; } for (int i = 0; i < m; i++) { scanf("%d", &a[i]); a[i]--; s[a[i]].insert(i); } for (int i = 0; i + 1 < m; i++) { ss[lca(a[i], a[i + 1])].insert(i); } while (q--) { int ope; scanf("%d", &ope); if (ope == 1) { int x, y; scanf("%d %d", &x, &y); x--, y--; s[a[x]].erase(x); upd(x, -1); upd(x - 1, -1); a[x] = y; s[a[x]].insert(x); upd(x, 1); upd(x - 1, 1); } else { int x, y, z; scanf("%d %d %d", &x, &y, &z); x--, y--, z--; auto lb = s[z].lower_bound(x); if (lb != s[z].end() && *lb <= y) { printf("%d %d\n", *lb + 1, *lb + 1); continue; } lb = ss[z].lower_bound(x); if (lb != ss[z].end() && *lb < y) { printf("%d %d\n", *lb + 1, *lb + 2); continue; } puts("-1 -1"); } } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 23928 KB | n=5 |
2 | Correct | 21 ms | 23928 KB | n=100 |
3 | Correct | 21 ms | 24012 KB | n=100 |
4 | Correct | 21 ms | 24088 KB | n=100 |
5 | Correct | 22 ms | 24088 KB | n=100 |
6 | Correct | 27 ms | 24088 KB | n=100 |
7 | Correct | 22 ms | 24088 KB | n=100 |
8 | Correct | 21 ms | 24176 KB | n=100 |
9 | Correct | 24 ms | 24176 KB | n=100 |
10 | Correct | 27 ms | 24208 KB | n=100 |
11 | Correct | 26 ms | 24208 KB | n=100 |
12 | Correct | 27 ms | 24208 KB | n=100 |
13 | Correct | 22 ms | 24208 KB | n=100 |
14 | Correct | 26 ms | 24208 KB | n=100 |
15 | Correct | 27 ms | 24208 KB | n=100 |
16 | Correct | 21 ms | 24208 KB | n=100 |
17 | Correct | 21 ms | 24208 KB | n=100 |
18 | Correct | 24 ms | 24208 KB | n=100 |
19 | Correct | 22 ms | 24208 KB | n=100 |
20 | Correct | 21 ms | 24208 KB | n=100 |
21 | Correct | 21 ms | 24208 KB | n=100 |
22 | Correct | 22 ms | 24208 KB | n=100 |
23 | Correct | 22 ms | 24208 KB | n=100 |
24 | Correct | 22 ms | 24208 KB | n=100 |
25 | Correct | 22 ms | 24208 KB | n=100 |
26 | Correct | 22 ms | 24240 KB | n=12 |
27 | Correct | 22 ms | 24240 KB | n=100 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 23928 KB | n=5 |
2 | Correct | 21 ms | 23928 KB | n=100 |
3 | Correct | 21 ms | 24012 KB | n=100 |
4 | Correct | 21 ms | 24088 KB | n=100 |
5 | Correct | 22 ms | 24088 KB | n=100 |
6 | Correct | 27 ms | 24088 KB | n=100 |
7 | Correct | 22 ms | 24088 KB | n=100 |
8 | Correct | 21 ms | 24176 KB | n=100 |
9 | Correct | 24 ms | 24176 KB | n=100 |
10 | Correct | 27 ms | 24208 KB | n=100 |
11 | Correct | 26 ms | 24208 KB | n=100 |
12 | Correct | 27 ms | 24208 KB | n=100 |
13 | Correct | 22 ms | 24208 KB | n=100 |
14 | Correct | 26 ms | 24208 KB | n=100 |
15 | Correct | 27 ms | 24208 KB | n=100 |
16 | Correct | 21 ms | 24208 KB | n=100 |
17 | Correct | 21 ms | 24208 KB | n=100 |
18 | Correct | 24 ms | 24208 KB | n=100 |
19 | Correct | 22 ms | 24208 KB | n=100 |
20 | Correct | 21 ms | 24208 KB | n=100 |
21 | Correct | 21 ms | 24208 KB | n=100 |
22 | Correct | 22 ms | 24208 KB | n=100 |
23 | Correct | 22 ms | 24208 KB | n=100 |
24 | Correct | 22 ms | 24208 KB | n=100 |
25 | Correct | 22 ms | 24208 KB | n=100 |
26 | Correct | 22 ms | 24240 KB | n=12 |
27 | Correct | 22 ms | 24240 KB | n=100 |
28 | Correct | 23 ms | 24296 KB | n=500 |
29 | Correct | 23 ms | 24296 KB | n=500 |
30 | Correct | 23 ms | 24296 KB | n=500 |
31 | Correct | 28 ms | 24296 KB | n=500 |
32 | Correct | 27 ms | 24296 KB | n=500 |
33 | Correct | 27 ms | 24296 KB | n=500 |
34 | Correct | 30 ms | 24296 KB | n=500 |
35 | Correct | 24 ms | 24296 KB | n=500 |
36 | Correct | 24 ms | 24300 KB | n=500 |
37 | Correct | 23 ms | 24424 KB | n=500 |
38 | Correct | 23 ms | 24424 KB | n=500 |
39 | Correct | 23 ms | 24424 KB | n=500 |
40 | Correct | 29 ms | 24424 KB | n=500 |
41 | Correct | 24 ms | 24424 KB | n=500 |
42 | Correct | 25 ms | 24424 KB | n=500 |
43 | Correct | 24 ms | 24424 KB | n=500 |
44 | Correct | 24 ms | 24424 KB | n=500 |
45 | Correct | 25 ms | 24424 KB | n=500 |
46 | Correct | 24 ms | 24424 KB | n=500 |
47 | Correct | 24 ms | 24424 KB | n=500 |
48 | Correct | 25 ms | 24424 KB | n=500 |
49 | Correct | 26 ms | 24424 KB | n=500 |
50 | Correct | 23 ms | 24424 KB | n=500 |
51 | Correct | 24 ms | 24424 KB | n=500 |
52 | Correct | 28 ms | 24424 KB | n=500 |
53 | Correct | 23 ms | 24424 KB | n=500 |
54 | Correct | 24 ms | 24424 KB | n=500 |
55 | Correct | 22 ms | 24424 KB | n=278 |
56 | Correct | 22 ms | 24424 KB | n=500 |
57 | Correct | 23 ms | 24424 KB | n=500 |
58 | Correct | 22 ms | 24424 KB | n=500 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 23928 KB | n=5 |
2 | Correct | 21 ms | 23928 KB | n=100 |
3 | Correct | 21 ms | 24012 KB | n=100 |
4 | Correct | 21 ms | 24088 KB | n=100 |
5 | Correct | 22 ms | 24088 KB | n=100 |
6 | Correct | 27 ms | 24088 KB | n=100 |
7 | Correct | 22 ms | 24088 KB | n=100 |
8 | Correct | 21 ms | 24176 KB | n=100 |
9 | Correct | 24 ms | 24176 KB | n=100 |
10 | Correct | 27 ms | 24208 KB | n=100 |
11 | Correct | 26 ms | 24208 KB | n=100 |
12 | Correct | 27 ms | 24208 KB | n=100 |
13 | Correct | 22 ms | 24208 KB | n=100 |
14 | Correct | 26 ms | 24208 KB | n=100 |
15 | Correct | 27 ms | 24208 KB | n=100 |
16 | Correct | 21 ms | 24208 KB | n=100 |
17 | Correct | 21 ms | 24208 KB | n=100 |
18 | Correct | 24 ms | 24208 KB | n=100 |
19 | Correct | 22 ms | 24208 KB | n=100 |
20 | Correct | 21 ms | 24208 KB | n=100 |
21 | Correct | 21 ms | 24208 KB | n=100 |
22 | Correct | 22 ms | 24208 KB | n=100 |
23 | Correct | 22 ms | 24208 KB | n=100 |
24 | Correct | 22 ms | 24208 KB | n=100 |
25 | Correct | 22 ms | 24208 KB | n=100 |
26 | Correct | 22 ms | 24240 KB | n=12 |
27 | Correct | 22 ms | 24240 KB | n=100 |
28 | Correct | 23 ms | 24296 KB | n=500 |
29 | Correct | 23 ms | 24296 KB | n=500 |
30 | Correct | 23 ms | 24296 KB | n=500 |
31 | Correct | 28 ms | 24296 KB | n=500 |
32 | Correct | 27 ms | 24296 KB | n=500 |
33 | Correct | 27 ms | 24296 KB | n=500 |
34 | Correct | 30 ms | 24296 KB | n=500 |
35 | Correct | 24 ms | 24296 KB | n=500 |
36 | Correct | 24 ms | 24300 KB | n=500 |
37 | Correct | 23 ms | 24424 KB | n=500 |
38 | Correct | 23 ms | 24424 KB | n=500 |
39 | Correct | 23 ms | 24424 KB | n=500 |
40 | Correct | 29 ms | 24424 KB | n=500 |
41 | Correct | 24 ms | 24424 KB | n=500 |
42 | Correct | 25 ms | 24424 KB | n=500 |
43 | Correct | 24 ms | 24424 KB | n=500 |
44 | Correct | 24 ms | 24424 KB | n=500 |
45 | Correct | 25 ms | 24424 KB | n=500 |
46 | Correct | 24 ms | 24424 KB | n=500 |
47 | Correct | 24 ms | 24424 KB | n=500 |
48 | Correct | 25 ms | 24424 KB | n=500 |
49 | Correct | 26 ms | 24424 KB | n=500 |
50 | Correct | 23 ms | 24424 KB | n=500 |
51 | Correct | 24 ms | 24424 KB | n=500 |
52 | Correct | 28 ms | 24424 KB | n=500 |
53 | Correct | 23 ms | 24424 KB | n=500 |
54 | Correct | 24 ms | 24424 KB | n=500 |
55 | Correct | 22 ms | 24424 KB | n=278 |
56 | Correct | 22 ms | 24424 KB | n=500 |
57 | Correct | 23 ms | 24424 KB | n=500 |
58 | Correct | 22 ms | 24424 KB | n=500 |
59 | Correct | 26 ms | 24556 KB | n=2000 |
60 | Correct | 38 ms | 24556 KB | n=2000 |
61 | Correct | 26 ms | 24572 KB | n=2000 |
62 | Correct | 27 ms | 24588 KB | n=2000 |
63 | Correct | 29 ms | 24588 KB | n=2000 |
64 | Correct | 31 ms | 24604 KB | n=2000 |
65 | Correct | 26 ms | 24604 KB | n=2000 |
66 | Correct | 26 ms | 24604 KB | n=2000 |
67 | Correct | 27 ms | 24604 KB | n=2000 |
68 | Correct | 26 ms | 24608 KB | n=2000 |
69 | Correct | 25 ms | 24608 KB | n=2000 |
70 | Correct | 25 ms | 24608 KB | n=2000 |
71 | Correct | 24 ms | 24608 KB | n=2000 |
72 | Correct | 25 ms | 24608 KB | n=2000 |
73 | Correct | 26 ms | 24608 KB | n=2000 |
74 | Correct | 36 ms | 24608 KB | n=1844 |
75 | Correct | 24 ms | 24732 KB | n=2000 |
76 | Correct | 26 ms | 24732 KB | n=2000 |
77 | Correct | 26 ms | 24732 KB | n=2000 |
78 | Correct | 27 ms | 24732 KB | n=2000 |
79 | Correct | 25 ms | 24732 KB | n=2000 |
80 | Correct | 26 ms | 24812 KB | n=2000 |
81 | Correct | 26 ms | 24812 KB | n=2000 |
82 | Correct | 26 ms | 24812 KB | n=2000 |
83 | Correct | 29 ms | 24812 KB | n=2000 |
84 | Correct | 25 ms | 24812 KB | n=2000 |
85 | Correct | 26 ms | 24812 KB | n=2000 |
86 | Correct | 27 ms | 24812 KB | n=2000 |
87 | Correct | 30 ms | 24812 KB | n=2000 |
88 | Correct | 26 ms | 24812 KB | n=2000 |
89 | Correct | 27 ms | 24812 KB | n=2000 |
90 | Correct | 29 ms | 24812 KB | n=2000 |
91 | Correct | 34 ms | 24812 KB | n=2000 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 23928 KB | n=5 |
2 | Correct | 21 ms | 23928 KB | n=100 |
3 | Correct | 21 ms | 24012 KB | n=100 |
4 | Correct | 21 ms | 24088 KB | n=100 |
5 | Correct | 22 ms | 24088 KB | n=100 |
6 | Correct | 27 ms | 24088 KB | n=100 |
7 | Correct | 22 ms | 24088 KB | n=100 |
8 | Correct | 21 ms | 24176 KB | n=100 |
9 | Correct | 24 ms | 24176 KB | n=100 |
10 | Correct | 27 ms | 24208 KB | n=100 |
11 | Correct | 26 ms | 24208 KB | n=100 |
12 | Correct | 27 ms | 24208 KB | n=100 |
13 | Correct | 22 ms | 24208 KB | n=100 |
14 | Correct | 26 ms | 24208 KB | n=100 |
15 | Correct | 27 ms | 24208 KB | n=100 |
16 | Correct | 21 ms | 24208 KB | n=100 |
17 | Correct | 21 ms | 24208 KB | n=100 |
18 | Correct | 24 ms | 24208 KB | n=100 |
19 | Correct | 22 ms | 24208 KB | n=100 |
20 | Correct | 21 ms | 24208 KB | n=100 |
21 | Correct | 21 ms | 24208 KB | n=100 |
22 | Correct | 22 ms | 24208 KB | n=100 |
23 | Correct | 22 ms | 24208 KB | n=100 |
24 | Correct | 22 ms | 24208 KB | n=100 |
25 | Correct | 22 ms | 24208 KB | n=100 |
26 | Correct | 22 ms | 24240 KB | n=12 |
27 | Correct | 22 ms | 24240 KB | n=100 |
28 | Correct | 23 ms | 24296 KB | n=500 |
29 | Correct | 23 ms | 24296 KB | n=500 |
30 | Correct | 23 ms | 24296 KB | n=500 |
31 | Correct | 28 ms | 24296 KB | n=500 |
32 | Correct | 27 ms | 24296 KB | n=500 |
33 | Correct | 27 ms | 24296 KB | n=500 |
34 | Correct | 30 ms | 24296 KB | n=500 |
35 | Correct | 24 ms | 24296 KB | n=500 |
36 | Correct | 24 ms | 24300 KB | n=500 |
37 | Correct | 23 ms | 24424 KB | n=500 |
38 | Correct | 23 ms | 24424 KB | n=500 |
39 | Correct | 23 ms | 24424 KB | n=500 |
40 | Correct | 29 ms | 24424 KB | n=500 |
41 | Correct | 24 ms | 24424 KB | n=500 |
42 | Correct | 25 ms | 24424 KB | n=500 |
43 | Correct | 24 ms | 24424 KB | n=500 |
44 | Correct | 24 ms | 24424 KB | n=500 |
45 | Correct | 25 ms | 24424 KB | n=500 |
46 | Correct | 24 ms | 24424 KB | n=500 |
47 | Correct | 24 ms | 24424 KB | n=500 |
48 | Correct | 25 ms | 24424 KB | n=500 |
49 | Correct | 26 ms | 24424 KB | n=500 |
50 | Correct | 23 ms | 24424 KB | n=500 |
51 | Correct | 24 ms | 24424 KB | n=500 |
52 | Correct | 28 ms | 24424 KB | n=500 |
53 | Correct | 23 ms | 24424 KB | n=500 |
54 | Correct | 24 ms | 24424 KB | n=500 |
55 | Correct | 22 ms | 24424 KB | n=278 |
56 | Correct | 22 ms | 24424 KB | n=500 |
57 | Correct | 23 ms | 24424 KB | n=500 |
58 | Correct | 22 ms | 24424 KB | n=500 |
59 | Correct | 26 ms | 24556 KB | n=2000 |
60 | Correct | 38 ms | 24556 KB | n=2000 |
61 | Correct | 26 ms | 24572 KB | n=2000 |
62 | Correct | 27 ms | 24588 KB | n=2000 |
63 | Correct | 29 ms | 24588 KB | n=2000 |
64 | Correct | 31 ms | 24604 KB | n=2000 |
65 | Correct | 26 ms | 24604 KB | n=2000 |
66 | Correct | 26 ms | 24604 KB | n=2000 |
67 | Correct | 27 ms | 24604 KB | n=2000 |
68 | Correct | 26 ms | 24608 KB | n=2000 |
69 | Correct | 25 ms | 24608 KB | n=2000 |
70 | Correct | 25 ms | 24608 KB | n=2000 |
71 | Correct | 24 ms | 24608 KB | n=2000 |
72 | Correct | 25 ms | 24608 KB | n=2000 |
73 | Correct | 26 ms | 24608 KB | n=2000 |
74 | Correct | 36 ms | 24608 KB | n=1844 |
75 | Correct | 24 ms | 24732 KB | n=2000 |
76 | Correct | 26 ms | 24732 KB | n=2000 |
77 | Correct | 26 ms | 24732 KB | n=2000 |
78 | Correct | 27 ms | 24732 KB | n=2000 |
79 | Correct | 25 ms | 24732 KB | n=2000 |
80 | Correct | 26 ms | 24812 KB | n=2000 |
81 | Correct | 26 ms | 24812 KB | n=2000 |
82 | Correct | 26 ms | 24812 KB | n=2000 |
83 | Correct | 29 ms | 24812 KB | n=2000 |
84 | Correct | 25 ms | 24812 KB | n=2000 |
85 | Correct | 26 ms | 24812 KB | n=2000 |
86 | Correct | 27 ms | 24812 KB | n=2000 |
87 | Correct | 30 ms | 24812 KB | n=2000 |
88 | Correct | 26 ms | 24812 KB | n=2000 |
89 | Correct | 27 ms | 24812 KB | n=2000 |
90 | Correct | 29 ms | 24812 KB | n=2000 |
91 | Correct | 34 ms | 24812 KB | n=2000 |
92 | Correct | 1302 ms | 66996 KB | n=200000 |
93 | Correct | 1620 ms | 69012 KB | n=200000 |
94 | Correct | 1420 ms | 71252 KB | n=200000 |
95 | Correct | 1036 ms | 71252 KB | n=200000 |
96 | Correct | 1104 ms | 71252 KB | n=200000 |
97 | Correct | 1655 ms | 71252 KB | n=200000 |
98 | Correct | 1008 ms | 71252 KB | n=200000 |
99 | Correct | 1427 ms | 71252 KB | n=200000 |
100 | Correct | 1164 ms | 71252 KB | n=200000 |
101 | Correct | 1599 ms | 72240 KB | n=200000 |
102 | Correct | 598 ms | 72240 KB | n=200000 |
103 | Correct | 655 ms | 72240 KB | n=200000 |
104 | Correct | 603 ms | 72240 KB | n=200000 |
105 | Correct | 655 ms | 72240 KB | n=200000 |
106 | Correct | 717 ms | 72240 KB | n=200000 |
107 | Correct | 612 ms | 72240 KB | n=200000 |
108 | Correct | 1454 ms | 72240 KB | n=200000 |
109 | Correct | 1319 ms | 72240 KB | n=200000 |
110 | Correct | 1327 ms | 72240 KB | n=200000 |
111 | Correct | 1192 ms | 72240 KB | n=200000 |
112 | Correct | 1629 ms | 72240 KB | n=200000 |
113 | Correct | 1675 ms | 72240 KB | n=200000 |
114 | Correct | 1245 ms | 72240 KB | n=200000 |
115 | Correct | 1893 ms | 72240 KB | n=200000 |
116 | Correct | 1126 ms | 72240 KB | n=200000 |
117 | Correct | 1794 ms | 72240 KB | n=200000 |
118 | Correct | 1717 ms | 72240 KB | n=200000 |
119 | Correct | 1240 ms | 72240 KB | n=200000 |
120 | Correct | 1559 ms | 81964 KB | n=200000 |
121 | Correct | 1747 ms | 88856 KB | n=200000 |
122 | Correct | 1556 ms | 96360 KB | n=200000 |
123 | Correct | 580 ms | 98516 KB | n=200000 |
124 | Correct | 352 ms | 98516 KB | n=25264 |