# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
54195 | 2018-07-02T18:29:37 Z | ulna | Birthday gift (IZhO18_treearray) | C++11 | 1876 ms | 263168 KB |
#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[200055]; set<int> ss[200055]; 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 | 22 ms | 23888 KB | n=5 |
2 | Correct | 21 ms | 24048 KB | n=100 |
3 | Correct | 22 ms | 24048 KB | n=100 |
4 | Correct | 22 ms | 24152 KB | n=100 |
5 | Correct | 25 ms | 24152 KB | n=100 |
6 | Correct | 24 ms | 24152 KB | n=100 |
7 | Correct | 22 ms | 24176 KB | n=100 |
8 | Correct | 25 ms | 24372 KB | n=100 |
9 | Correct | 23 ms | 24372 KB | n=100 |
10 | Correct | 22 ms | 24372 KB | n=100 |
11 | Correct | 22 ms | 24372 KB | n=100 |
12 | Correct | 21 ms | 24372 KB | n=100 |
13 | Correct | 22 ms | 24372 KB | n=100 |
14 | Correct | 21 ms | 24372 KB | n=100 |
15 | Correct | 22 ms | 24372 KB | n=100 |
16 | Correct | 21 ms | 24372 KB | n=100 |
17 | Correct | 21 ms | 24372 KB | n=100 |
18 | Correct | 22 ms | 24372 KB | n=100 |
19 | Correct | 22 ms | 24372 KB | n=100 |
20 | Correct | 21 ms | 24372 KB | n=100 |
21 | Correct | 21 ms | 24372 KB | n=100 |
22 | Correct | 21 ms | 24372 KB | n=100 |
23 | Correct | 21 ms | 24372 KB | n=100 |
24 | Correct | 21 ms | 24372 KB | n=100 |
25 | Correct | 21 ms | 24372 KB | n=100 |
26 | Correct | 21 ms | 24372 KB | n=12 |
27 | Correct | 21 ms | 24392 KB | n=100 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 22 ms | 23888 KB | n=5 |
2 | Correct | 21 ms | 24048 KB | n=100 |
3 | Correct | 22 ms | 24048 KB | n=100 |
4 | Correct | 22 ms | 24152 KB | n=100 |
5 | Correct | 25 ms | 24152 KB | n=100 |
6 | Correct | 24 ms | 24152 KB | n=100 |
7 | Correct | 22 ms | 24176 KB | n=100 |
8 | Correct | 25 ms | 24372 KB | n=100 |
9 | Correct | 23 ms | 24372 KB | n=100 |
10 | Correct | 22 ms | 24372 KB | n=100 |
11 | Correct | 22 ms | 24372 KB | n=100 |
12 | Correct | 21 ms | 24372 KB | n=100 |
13 | Correct | 22 ms | 24372 KB | n=100 |
14 | Correct | 21 ms | 24372 KB | n=100 |
15 | Correct | 22 ms | 24372 KB | n=100 |
16 | Correct | 21 ms | 24372 KB | n=100 |
17 | Correct | 21 ms | 24372 KB | n=100 |
18 | Correct | 22 ms | 24372 KB | n=100 |
19 | Correct | 22 ms | 24372 KB | n=100 |
20 | Correct | 21 ms | 24372 KB | n=100 |
21 | Correct | 21 ms | 24372 KB | n=100 |
22 | Correct | 21 ms | 24372 KB | n=100 |
23 | Correct | 21 ms | 24372 KB | n=100 |
24 | Correct | 21 ms | 24372 KB | n=100 |
25 | Correct | 21 ms | 24372 KB | n=100 |
26 | Correct | 21 ms | 24372 KB | n=12 |
27 | Correct | 21 ms | 24392 KB | n=100 |
28 | Correct | 22 ms | 24504 KB | n=500 |
29 | Correct | 24 ms | 24516 KB | n=500 |
30 | Correct | 23 ms | 24572 KB | n=500 |
31 | Correct | 25 ms | 24584 KB | n=500 |
32 | Correct | 24 ms | 24596 KB | n=500 |
33 | Correct | 22 ms | 24608 KB | n=500 |
34 | Correct | 22 ms | 24752 KB | n=500 |
35 | Correct | 21 ms | 24752 KB | n=500 |
36 | Correct | 22 ms | 24752 KB | n=500 |
37 | Correct | 22 ms | 24752 KB | n=500 |
38 | Correct | 22 ms | 24752 KB | n=500 |
39 | Correct | 23 ms | 24752 KB | n=500 |
40 | Correct | 25 ms | 24796 KB | n=500 |
41 | Correct | 22 ms | 24796 KB | n=500 |
42 | Correct | 25 ms | 24796 KB | n=500 |
43 | Correct | 22 ms | 24796 KB | n=500 |
44 | Correct | 25 ms | 24796 KB | n=500 |
45 | Correct | 25 ms | 24808 KB | n=500 |
46 | Correct | 25 ms | 24808 KB | n=500 |
47 | Correct | 21 ms | 24864 KB | n=500 |
48 | Correct | 22 ms | 24880 KB | n=500 |
49 | Correct | 22 ms | 24892 KB | n=500 |
50 | Correct | 23 ms | 24908 KB | n=500 |
51 | Correct | 22 ms | 24920 KB | n=500 |
52 | Correct | 23 ms | 24936 KB | n=500 |
53 | Correct | 23 ms | 24956 KB | n=500 |
54 | Correct | 22 ms | 24972 KB | n=500 |
55 | Correct | 23 ms | 24984 KB | n=278 |
56 | Correct | 22 ms | 24992 KB | n=500 |
57 | Correct | 23 ms | 25008 KB | n=500 |
58 | Correct | 22 ms | 25100 KB | n=500 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 22 ms | 23888 KB | n=5 |
2 | Correct | 21 ms | 24048 KB | n=100 |
3 | Correct | 22 ms | 24048 KB | n=100 |
4 | Correct | 22 ms | 24152 KB | n=100 |
5 | Correct | 25 ms | 24152 KB | n=100 |
6 | Correct | 24 ms | 24152 KB | n=100 |
7 | Correct | 22 ms | 24176 KB | n=100 |
8 | Correct | 25 ms | 24372 KB | n=100 |
9 | Correct | 23 ms | 24372 KB | n=100 |
10 | Correct | 22 ms | 24372 KB | n=100 |
11 | Correct | 22 ms | 24372 KB | n=100 |
12 | Correct | 21 ms | 24372 KB | n=100 |
13 | Correct | 22 ms | 24372 KB | n=100 |
14 | Correct | 21 ms | 24372 KB | n=100 |
15 | Correct | 22 ms | 24372 KB | n=100 |
16 | Correct | 21 ms | 24372 KB | n=100 |
17 | Correct | 21 ms | 24372 KB | n=100 |
18 | Correct | 22 ms | 24372 KB | n=100 |
19 | Correct | 22 ms | 24372 KB | n=100 |
20 | Correct | 21 ms | 24372 KB | n=100 |
21 | Correct | 21 ms | 24372 KB | n=100 |
22 | Correct | 21 ms | 24372 KB | n=100 |
23 | Correct | 21 ms | 24372 KB | n=100 |
24 | Correct | 21 ms | 24372 KB | n=100 |
25 | Correct | 21 ms | 24372 KB | n=100 |
26 | Correct | 21 ms | 24372 KB | n=12 |
27 | Correct | 21 ms | 24392 KB | n=100 |
28 | Correct | 22 ms | 24504 KB | n=500 |
29 | Correct | 24 ms | 24516 KB | n=500 |
30 | Correct | 23 ms | 24572 KB | n=500 |
31 | Correct | 25 ms | 24584 KB | n=500 |
32 | Correct | 24 ms | 24596 KB | n=500 |
33 | Correct | 22 ms | 24608 KB | n=500 |
34 | Correct | 22 ms | 24752 KB | n=500 |
35 | Correct | 21 ms | 24752 KB | n=500 |
36 | Correct | 22 ms | 24752 KB | n=500 |
37 | Correct | 22 ms | 24752 KB | n=500 |
38 | Correct | 22 ms | 24752 KB | n=500 |
39 | Correct | 23 ms | 24752 KB | n=500 |
40 | Correct | 25 ms | 24796 KB | n=500 |
41 | Correct | 22 ms | 24796 KB | n=500 |
42 | Correct | 25 ms | 24796 KB | n=500 |
43 | Correct | 22 ms | 24796 KB | n=500 |
44 | Correct | 25 ms | 24796 KB | n=500 |
45 | Correct | 25 ms | 24808 KB | n=500 |
46 | Correct | 25 ms | 24808 KB | n=500 |
47 | Correct | 21 ms | 24864 KB | n=500 |
48 | Correct | 22 ms | 24880 KB | n=500 |
49 | Correct | 22 ms | 24892 KB | n=500 |
50 | Correct | 23 ms | 24908 KB | n=500 |
51 | Correct | 22 ms | 24920 KB | n=500 |
52 | Correct | 23 ms | 24936 KB | n=500 |
53 | Correct | 23 ms | 24956 KB | n=500 |
54 | Correct | 22 ms | 24972 KB | n=500 |
55 | Correct | 23 ms | 24984 KB | n=278 |
56 | Correct | 22 ms | 24992 KB | n=500 |
57 | Correct | 23 ms | 25008 KB | n=500 |
58 | Correct | 22 ms | 25100 KB | n=500 |
59 | Correct | 27 ms | 25288 KB | n=2000 |
60 | Correct | 29 ms | 25468 KB | n=2000 |
61 | Correct | 28 ms | 25568 KB | n=2000 |
62 | Correct | 28 ms | 25580 KB | n=2000 |
63 | Correct | 29 ms | 25636 KB | n=2000 |
64 | Correct | 33 ms | 25688 KB | n=2000 |
65 | Correct | 33 ms | 25744 KB | n=2000 |
66 | Correct | 27 ms | 25796 KB | n=2000 |
67 | Correct | 30 ms | 25796 KB | n=2000 |
68 | Correct | 33 ms | 25908 KB | n=2000 |
69 | Correct | 26 ms | 25964 KB | n=2000 |
70 | Correct | 29 ms | 26016 KB | n=2000 |
71 | Correct | 25 ms | 26068 KB | n=2000 |
72 | Correct | 28 ms | 26120 KB | n=2000 |
73 | Correct | 25 ms | 26296 KB | n=2000 |
74 | Correct | 30 ms | 26296 KB | n=1844 |
75 | Correct | 28 ms | 26296 KB | n=2000 |
76 | Correct | 27 ms | 26332 KB | n=2000 |
77 | Correct | 26 ms | 26380 KB | n=2000 |
78 | Correct | 27 ms | 26380 KB | n=2000 |
79 | Correct | 26 ms | 26380 KB | n=2000 |
80 | Correct | 27 ms | 26536 KB | n=2000 |
81 | Correct | 27 ms | 26592 KB | n=2000 |
82 | Correct | 26 ms | 26620 KB | n=2000 |
83 | Correct | 25 ms | 26668 KB | n=2000 |
84 | Correct | 26 ms | 26668 KB | n=2000 |
85 | Correct | 26 ms | 26844 KB | n=2000 |
86 | Correct | 26 ms | 26864 KB | n=2000 |
87 | Correct | 25 ms | 26920 KB | n=2000 |
88 | Correct | 26 ms | 26956 KB | n=2000 |
89 | Correct | 26 ms | 27028 KB | n=2000 |
90 | Correct | 25 ms | 27120 KB | n=2000 |
91 | Correct | 25 ms | 27136 KB | n=2000 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 22 ms | 23888 KB | n=5 |
2 | Correct | 21 ms | 24048 KB | n=100 |
3 | Correct | 22 ms | 24048 KB | n=100 |
4 | Correct | 22 ms | 24152 KB | n=100 |
5 | Correct | 25 ms | 24152 KB | n=100 |
6 | Correct | 24 ms | 24152 KB | n=100 |
7 | Correct | 22 ms | 24176 KB | n=100 |
8 | Correct | 25 ms | 24372 KB | n=100 |
9 | Correct | 23 ms | 24372 KB | n=100 |
10 | Correct | 22 ms | 24372 KB | n=100 |
11 | Correct | 22 ms | 24372 KB | n=100 |
12 | Correct | 21 ms | 24372 KB | n=100 |
13 | Correct | 22 ms | 24372 KB | n=100 |
14 | Correct | 21 ms | 24372 KB | n=100 |
15 | Correct | 22 ms | 24372 KB | n=100 |
16 | Correct | 21 ms | 24372 KB | n=100 |
17 | Correct | 21 ms | 24372 KB | n=100 |
18 | Correct | 22 ms | 24372 KB | n=100 |
19 | Correct | 22 ms | 24372 KB | n=100 |
20 | Correct | 21 ms | 24372 KB | n=100 |
21 | Correct | 21 ms | 24372 KB | n=100 |
22 | Correct | 21 ms | 24372 KB | n=100 |
23 | Correct | 21 ms | 24372 KB | n=100 |
24 | Correct | 21 ms | 24372 KB | n=100 |
25 | Correct | 21 ms | 24372 KB | n=100 |
26 | Correct | 21 ms | 24372 KB | n=12 |
27 | Correct | 21 ms | 24392 KB | n=100 |
28 | Correct | 22 ms | 24504 KB | n=500 |
29 | Correct | 24 ms | 24516 KB | n=500 |
30 | Correct | 23 ms | 24572 KB | n=500 |
31 | Correct | 25 ms | 24584 KB | n=500 |
32 | Correct | 24 ms | 24596 KB | n=500 |
33 | Correct | 22 ms | 24608 KB | n=500 |
34 | Correct | 22 ms | 24752 KB | n=500 |
35 | Correct | 21 ms | 24752 KB | n=500 |
36 | Correct | 22 ms | 24752 KB | n=500 |
37 | Correct | 22 ms | 24752 KB | n=500 |
38 | Correct | 22 ms | 24752 KB | n=500 |
39 | Correct | 23 ms | 24752 KB | n=500 |
40 | Correct | 25 ms | 24796 KB | n=500 |
41 | Correct | 22 ms | 24796 KB | n=500 |
42 | Correct | 25 ms | 24796 KB | n=500 |
43 | Correct | 22 ms | 24796 KB | n=500 |
44 | Correct | 25 ms | 24796 KB | n=500 |
45 | Correct | 25 ms | 24808 KB | n=500 |
46 | Correct | 25 ms | 24808 KB | n=500 |
47 | Correct | 21 ms | 24864 KB | n=500 |
48 | Correct | 22 ms | 24880 KB | n=500 |
49 | Correct | 22 ms | 24892 KB | n=500 |
50 | Correct | 23 ms | 24908 KB | n=500 |
51 | Correct | 22 ms | 24920 KB | n=500 |
52 | Correct | 23 ms | 24936 KB | n=500 |
53 | Correct | 23 ms | 24956 KB | n=500 |
54 | Correct | 22 ms | 24972 KB | n=500 |
55 | Correct | 23 ms | 24984 KB | n=278 |
56 | Correct | 22 ms | 24992 KB | n=500 |
57 | Correct | 23 ms | 25008 KB | n=500 |
58 | Correct | 22 ms | 25100 KB | n=500 |
59 | Correct | 27 ms | 25288 KB | n=2000 |
60 | Correct | 29 ms | 25468 KB | n=2000 |
61 | Correct | 28 ms | 25568 KB | n=2000 |
62 | Correct | 28 ms | 25580 KB | n=2000 |
63 | Correct | 29 ms | 25636 KB | n=2000 |
64 | Correct | 33 ms | 25688 KB | n=2000 |
65 | Correct | 33 ms | 25744 KB | n=2000 |
66 | Correct | 27 ms | 25796 KB | n=2000 |
67 | Correct | 30 ms | 25796 KB | n=2000 |
68 | Correct | 33 ms | 25908 KB | n=2000 |
69 | Correct | 26 ms | 25964 KB | n=2000 |
70 | Correct | 29 ms | 26016 KB | n=2000 |
71 | Correct | 25 ms | 26068 KB | n=2000 |
72 | Correct | 28 ms | 26120 KB | n=2000 |
73 | Correct | 25 ms | 26296 KB | n=2000 |
74 | Correct | 30 ms | 26296 KB | n=1844 |
75 | Correct | 28 ms | 26296 KB | n=2000 |
76 | Correct | 27 ms | 26332 KB | n=2000 |
77 | Correct | 26 ms | 26380 KB | n=2000 |
78 | Correct | 27 ms | 26380 KB | n=2000 |
79 | Correct | 26 ms | 26380 KB | n=2000 |
80 | Correct | 27 ms | 26536 KB | n=2000 |
81 | Correct | 27 ms | 26592 KB | n=2000 |
82 | Correct | 26 ms | 26620 KB | n=2000 |
83 | Correct | 25 ms | 26668 KB | n=2000 |
84 | Correct | 26 ms | 26668 KB | n=2000 |
85 | Correct | 26 ms | 26844 KB | n=2000 |
86 | Correct | 26 ms | 26864 KB | n=2000 |
87 | Correct | 25 ms | 26920 KB | n=2000 |
88 | Correct | 26 ms | 26956 KB | n=2000 |
89 | Correct | 26 ms | 27028 KB | n=2000 |
90 | Correct | 25 ms | 27120 KB | n=2000 |
91 | Correct | 25 ms | 27136 KB | n=2000 |
92 | Correct | 1085 ms | 75772 KB | n=200000 |
93 | Correct | 1445 ms | 87228 KB | n=200000 |
94 | Correct | 1441 ms | 98244 KB | n=200000 |
95 | Correct | 1066 ms | 98244 KB | n=200000 |
96 | Correct | 980 ms | 103972 KB | n=200000 |
97 | Correct | 1876 ms | 114580 KB | n=200000 |
98 | Correct | 1108 ms | 118304 KB | n=200000 |
99 | Correct | 1368 ms | 124708 KB | n=200000 |
100 | Correct | 1177 ms | 131908 KB | n=200000 |
101 | Correct | 1457 ms | 147856 KB | n=200000 |
102 | Correct | 581 ms | 147856 KB | n=200000 |
103 | Correct | 708 ms | 153716 KB | n=200000 |
104 | Correct | 588 ms | 160412 KB | n=200000 |
105 | Correct | 606 ms | 167560 KB | n=200000 |
106 | Correct | 624 ms | 175120 KB | n=200000 |
107 | Correct | 604 ms | 182296 KB | n=200000 |
108 | Correct | 1204 ms | 188160 KB | n=200000 |
109 | Correct | 1188 ms | 195048 KB | n=200000 |
110 | Correct | 1155 ms | 201992 KB | n=200000 |
111 | Correct | 1317 ms | 208296 KB | n=200000 |
112 | Correct | 1434 ms | 223504 KB | n=200000 |
113 | Correct | 1483 ms | 226512 KB | n=200000 |
114 | Correct | 978 ms | 229844 KB | n=200000 |
115 | Correct | 1610 ms | 238332 KB | n=200000 |
116 | Correct | 1144 ms | 244100 KB | n=200000 |
117 | Correct | 1484 ms | 259976 KB | n=200000 |
118 | Correct | 1526 ms | 261500 KB | n=200000 |
119 | Runtime error | 1048 ms | 263168 KB | Memory limit exceeded |
120 | Halted | 0 ms | 0 KB | - |