# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
40443 | 2018-02-01T13:11:19 Z | szawinis | Birthday gift (IZhO18_treearray) | C++14 | 2045 ms | 105188 KB |
#include <iostream> #include <cstdio> #include <algorithm> #include <vector> #include <set> #include <unordered_map> #include <unordered_set> using namespace std; const int N = 1 << 18; int n, m, q, a[N]; vector<int> g[N]; set<int> pos[N], lca_pos[N]; int d[N]; vector<int> anc[N]; void dfs(int u, int p) { for(int v: g[u]) if(v != p) { d[v] = d[u] + 1; anc[v].push_back(u); for(int j = 0; 1 << j+1 <= d[v]; j++) anc[v].push_back(anc[anc[v][j]][j]); dfs(v, u); } } int lca(int u, int v) { if(d[v] > d[u]) swap(u, v); if(d[u] > d[v]) { for(int j = 0; 1 << j <= d[u] - d[v]; j++) if(d[u] - d[v] >> j & 1) u = anc[u][j]; } if(u == v) return u; for(int j = 18; j >= 0; j--) if(j < anc[u].size() && anc[u][j] != anc[v][j]) u = anc[u][j], v = anc[v][j]; return anc[u][0]; } int main() { scanf("%d %d %d", &n, &m, &q); for(int i = 1, u, v; i < n; i++) { scanf("%d %d", &u, &v); g[u].push_back(v); g[v].push_back(u); } dfs(1, 0); for(int i = 1; i <= m; i++) { scanf("%d", a+i); pos[a[i]].insert(i); if(i > 1) lca_pos[lca(a[i-1], a[i])].insert(i-1); } for(int z = 0, tp, l, r, v, i; z < q; z++) { scanf("%d", &tp); if(tp == 1) { scanf("%d %d", &i, &v); if(i < m) lca_pos[lca(a[i], a[i+1])].erase(i); if(i > 1) lca_pos[lca(a[i-1], a[i])].erase(i-1); pos[a[i]].erase(i); a[i] = v; if(i < m) lca_pos[lca(a[i], a[i+1])].insert(i); if(i > 1) lca_pos[lca(a[i-1], a[i])].insert(i-1); pos[a[i]].insert(i); } else { scanf("%d %d %d", &l, &r, &v); auto it = lca_pos[v].lower_bound(l); if(it != lca_pos[v].end() && *it < r) printf("%d %d\n", *it, *it+1); else { auto it = pos[v].lower_bound(l); if(it == pos[v].end() || *it > r) printf("-1 -1\n"); else printf("%d %d\n", *it, *it); } } } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 32 ms | 37240 KB | n=5 |
2 | Correct | 31 ms | 37348 KB | n=100 |
3 | Correct | 30 ms | 37348 KB | n=100 |
4 | Correct | 31 ms | 37452 KB | n=100 |
5 | Correct | 30 ms | 37452 KB | n=100 |
6 | Correct | 30 ms | 37452 KB | n=100 |
7 | Correct | 32 ms | 37452 KB | n=100 |
8 | Correct | 31 ms | 37524 KB | n=100 |
9 | Correct | 31 ms | 37524 KB | n=100 |
10 | Correct | 30 ms | 37524 KB | n=100 |
11 | Correct | 31 ms | 37524 KB | n=100 |
12 | Correct | 32 ms | 37524 KB | n=100 |
13 | Correct | 31 ms | 37540 KB | n=100 |
14 | Correct | 39 ms | 37540 KB | n=100 |
15 | Correct | 34 ms | 37540 KB | n=100 |
16 | Correct | 31 ms | 37596 KB | n=100 |
17 | Correct | 31 ms | 37596 KB | n=100 |
18 | Correct | 34 ms | 37596 KB | n=100 |
19 | Correct | 32 ms | 37596 KB | n=100 |
20 | Correct | 32 ms | 37596 KB | n=100 |
21 | Correct | 31 ms | 37596 KB | n=100 |
22 | Correct | 33 ms | 37596 KB | n=100 |
23 | Correct | 38 ms | 37596 KB | n=100 |
24 | Correct | 31 ms | 37596 KB | n=100 |
25 | Correct | 32 ms | 37596 KB | n=100 |
26 | Correct | 32 ms | 37596 KB | n=12 |
27 | Correct | 35 ms | 37596 KB | n=100 |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 32 ms | 37240 KB | n=5 |
2 | Correct | 31 ms | 37348 KB | n=100 |
3 | Correct | 30 ms | 37348 KB | n=100 |
4 | Correct | 31 ms | 37452 KB | n=100 |
5 | Correct | 30 ms | 37452 KB | n=100 |
6 | Correct | 30 ms | 37452 KB | n=100 |
7 | Correct | 32 ms | 37452 KB | n=100 |
8 | Correct | 31 ms | 37524 KB | n=100 |
9 | Correct | 31 ms | 37524 KB | n=100 |
10 | Correct | 30 ms | 37524 KB | n=100 |
11 | Correct | 31 ms | 37524 KB | n=100 |
12 | Correct | 32 ms | 37524 KB | n=100 |
13 | Correct | 31 ms | 37540 KB | n=100 |
14 | Correct | 39 ms | 37540 KB | n=100 |
15 | Correct | 34 ms | 37540 KB | n=100 |
16 | Correct | 31 ms | 37596 KB | n=100 |
17 | Correct | 31 ms | 37596 KB | n=100 |
18 | Correct | 34 ms | 37596 KB | n=100 |
19 | Correct | 32 ms | 37596 KB | n=100 |
20 | Correct | 32 ms | 37596 KB | n=100 |
21 | Correct | 31 ms | 37596 KB | n=100 |
22 | Correct | 33 ms | 37596 KB | n=100 |
23 | Correct | 38 ms | 37596 KB | n=100 |
24 | Correct | 31 ms | 37596 KB | n=100 |
25 | Correct | 32 ms | 37596 KB | n=100 |
26 | Correct | 32 ms | 37596 KB | n=12 |
27 | Correct | 35 ms | 37596 KB | n=100 |
28 | Correct | 32 ms | 37596 KB | n=500 |
29 | Correct | 32 ms | 37596 KB | n=500 |
30 | Correct | 38 ms | 37724 KB | n=500 |
31 | Correct | 36 ms | 37724 KB | n=500 |
32 | Correct | 32 ms | 37724 KB | n=500 |
33 | Correct | 32 ms | 37724 KB | n=500 |
34 | Correct | 32 ms | 37724 KB | n=500 |
35 | Correct | 32 ms | 37724 KB | n=500 |
36 | Correct | 36 ms | 37724 KB | n=500 |
37 | Correct | 32 ms | 37724 KB | n=500 |
38 | Correct | 32 ms | 37724 KB | n=500 |
39 | Correct | 32 ms | 37724 KB | n=500 |
40 | Correct | 36 ms | 37724 KB | n=500 |
41 | Correct | 32 ms | 37724 KB | n=500 |
42 | Correct | 32 ms | 37724 KB | n=500 |
43 | Correct | 32 ms | 37724 KB | n=500 |
44 | Correct | 33 ms | 37724 KB | n=500 |
45 | Correct | 33 ms | 37724 KB | n=500 |
46 | Correct | 32 ms | 37724 KB | n=500 |
47 | Correct | 32 ms | 37724 KB | n=500 |
48 | Correct | 34 ms | 37724 KB | n=500 |
49 | Correct | 33 ms | 37724 KB | n=500 |
50 | Correct | 33 ms | 37724 KB | n=500 |
51 | Correct | 35 ms | 37728 KB | n=500 |
52 | Correct | 33 ms | 37728 KB | n=500 |
53 | Correct | 33 ms | 37728 KB | n=500 |
54 | Correct | 36 ms | 37728 KB | n=500 |
55 | Correct | 31 ms | 37728 KB | n=278 |
56 | Correct | 37 ms | 37728 KB | n=500 |
57 | Correct | 33 ms | 37728 KB | n=500 |
58 | Correct | 39 ms | 37728 KB | n=500 |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 32 ms | 37240 KB | n=5 |
2 | Correct | 31 ms | 37348 KB | n=100 |
3 | Correct | 30 ms | 37348 KB | n=100 |
4 | Correct | 31 ms | 37452 KB | n=100 |
5 | Correct | 30 ms | 37452 KB | n=100 |
6 | Correct | 30 ms | 37452 KB | n=100 |
7 | Correct | 32 ms | 37452 KB | n=100 |
8 | Correct | 31 ms | 37524 KB | n=100 |
9 | Correct | 31 ms | 37524 KB | n=100 |
10 | Correct | 30 ms | 37524 KB | n=100 |
11 | Correct | 31 ms | 37524 KB | n=100 |
12 | Correct | 32 ms | 37524 KB | n=100 |
13 | Correct | 31 ms | 37540 KB | n=100 |
14 | Correct | 39 ms | 37540 KB | n=100 |
15 | Correct | 34 ms | 37540 KB | n=100 |
16 | Correct | 31 ms | 37596 KB | n=100 |
17 | Correct | 31 ms | 37596 KB | n=100 |
18 | Correct | 34 ms | 37596 KB | n=100 |
19 | Correct | 32 ms | 37596 KB | n=100 |
20 | Correct | 32 ms | 37596 KB | n=100 |
21 | Correct | 31 ms | 37596 KB | n=100 |
22 | Correct | 33 ms | 37596 KB | n=100 |
23 | Correct | 38 ms | 37596 KB | n=100 |
24 | Correct | 31 ms | 37596 KB | n=100 |
25 | Correct | 32 ms | 37596 KB | n=100 |
26 | Correct | 32 ms | 37596 KB | n=12 |
27 | Correct | 35 ms | 37596 KB | n=100 |
28 | Correct | 32 ms | 37596 KB | n=500 |
29 | Correct | 32 ms | 37596 KB | n=500 |
30 | Correct | 38 ms | 37724 KB | n=500 |
31 | Correct | 36 ms | 37724 KB | n=500 |
32 | Correct | 32 ms | 37724 KB | n=500 |
33 | Correct | 32 ms | 37724 KB | n=500 |
34 | Correct | 32 ms | 37724 KB | n=500 |
35 | Correct | 32 ms | 37724 KB | n=500 |
36 | Correct | 36 ms | 37724 KB | n=500 |
37 | Correct | 32 ms | 37724 KB | n=500 |
38 | Correct | 32 ms | 37724 KB | n=500 |
39 | Correct | 32 ms | 37724 KB | n=500 |
40 | Correct | 36 ms | 37724 KB | n=500 |
41 | Correct | 32 ms | 37724 KB | n=500 |
42 | Correct | 32 ms | 37724 KB | n=500 |
43 | Correct | 32 ms | 37724 KB | n=500 |
44 | Correct | 33 ms | 37724 KB | n=500 |
45 | Correct | 33 ms | 37724 KB | n=500 |
46 | Correct | 32 ms | 37724 KB | n=500 |
47 | Correct | 32 ms | 37724 KB | n=500 |
48 | Correct | 34 ms | 37724 KB | n=500 |
49 | Correct | 33 ms | 37724 KB | n=500 |
50 | Correct | 33 ms | 37724 KB | n=500 |
51 | Correct | 35 ms | 37728 KB | n=500 |
52 | Correct | 33 ms | 37728 KB | n=500 |
53 | Correct | 33 ms | 37728 KB | n=500 |
54 | Correct | 36 ms | 37728 KB | n=500 |
55 | Correct | 31 ms | 37728 KB | n=278 |
56 | Correct | 37 ms | 37728 KB | n=500 |
57 | Correct | 33 ms | 37728 KB | n=500 |
58 | Correct | 39 ms | 37728 KB | n=500 |
59 | Correct | 36 ms | 37852 KB | n=2000 |
60 | Correct | 38 ms | 38108 KB | n=2000 |
61 | Correct | 38 ms | 38108 KB | n=2000 |
62 | Correct | 37 ms | 38108 KB | n=2000 |
63 | Correct | 36 ms | 38108 KB | n=2000 |
64 | Correct | 37 ms | 38108 KB | n=2000 |
65 | Correct | 37 ms | 38108 KB | n=2000 |
66 | Correct | 36 ms | 38108 KB | n=2000 |
67 | Correct | 35 ms | 38108 KB | n=2000 |
68 | Correct | 43 ms | 38108 KB | n=2000 |
69 | Correct | 39 ms | 38108 KB | n=2000 |
70 | Correct | 39 ms | 38108 KB | n=2000 |
71 | Correct | 37 ms | 38108 KB | n=2000 |
72 | Correct | 42 ms | 38108 KB | n=2000 |
73 | Correct | 35 ms | 38108 KB | n=2000 |
74 | Correct | 37 ms | 38108 KB | n=1844 |
75 | Correct | 43 ms | 38108 KB | n=2000 |
76 | Correct | 45 ms | 38108 KB | n=2000 |
77 | Correct | 46 ms | 38108 KB | n=2000 |
78 | Correct | 38 ms | 38108 KB | n=2000 |
79 | Correct | 37 ms | 38108 KB | n=2000 |
80 | Correct | 38 ms | 38108 KB | n=2000 |
81 | Correct | 39 ms | 38108 KB | n=2000 |
82 | Correct | 38 ms | 38108 KB | n=2000 |
83 | Correct | 38 ms | 38108 KB | n=2000 |
84 | Correct | 38 ms | 38108 KB | n=2000 |
85 | Correct | 36 ms | 38108 KB | n=2000 |
86 | Correct | 36 ms | 38108 KB | n=2000 |
87 | Correct | 37 ms | 38108 KB | n=2000 |
88 | Correct | 42 ms | 38172 KB | n=2000 |
89 | Correct | 36 ms | 38172 KB | n=2000 |
90 | Correct | 38 ms | 38172 KB | n=2000 |
91 | Correct | 34 ms | 38172 KB | n=2000 |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 32 ms | 37240 KB | n=5 |
2 | Correct | 31 ms | 37348 KB | n=100 |
3 | Correct | 30 ms | 37348 KB | n=100 |
4 | Correct | 31 ms | 37452 KB | n=100 |
5 | Correct | 30 ms | 37452 KB | n=100 |
6 | Correct | 30 ms | 37452 KB | n=100 |
7 | Correct | 32 ms | 37452 KB | n=100 |
8 | Correct | 31 ms | 37524 KB | n=100 |
9 | Correct | 31 ms | 37524 KB | n=100 |
10 | Correct | 30 ms | 37524 KB | n=100 |
11 | Correct | 31 ms | 37524 KB | n=100 |
12 | Correct | 32 ms | 37524 KB | n=100 |
13 | Correct | 31 ms | 37540 KB | n=100 |
14 | Correct | 39 ms | 37540 KB | n=100 |
15 | Correct | 34 ms | 37540 KB | n=100 |
16 | Correct | 31 ms | 37596 KB | n=100 |
17 | Correct | 31 ms | 37596 KB | n=100 |
18 | Correct | 34 ms | 37596 KB | n=100 |
19 | Correct | 32 ms | 37596 KB | n=100 |
20 | Correct | 32 ms | 37596 KB | n=100 |
21 | Correct | 31 ms | 37596 KB | n=100 |
22 | Correct | 33 ms | 37596 KB | n=100 |
23 | Correct | 38 ms | 37596 KB | n=100 |
24 | Correct | 31 ms | 37596 KB | n=100 |
25 | Correct | 32 ms | 37596 KB | n=100 |
26 | Correct | 32 ms | 37596 KB | n=12 |
27 | Correct | 35 ms | 37596 KB | n=100 |
28 | Correct | 32 ms | 37596 KB | n=500 |
29 | Correct | 32 ms | 37596 KB | n=500 |
30 | Correct | 38 ms | 37724 KB | n=500 |
31 | Correct | 36 ms | 37724 KB | n=500 |
32 | Correct | 32 ms | 37724 KB | n=500 |
33 | Correct | 32 ms | 37724 KB | n=500 |
34 | Correct | 32 ms | 37724 KB | n=500 |
35 | Correct | 32 ms | 37724 KB | n=500 |
36 | Correct | 36 ms | 37724 KB | n=500 |
37 | Correct | 32 ms | 37724 KB | n=500 |
38 | Correct | 32 ms | 37724 KB | n=500 |
39 | Correct | 32 ms | 37724 KB | n=500 |
40 | Correct | 36 ms | 37724 KB | n=500 |
41 | Correct | 32 ms | 37724 KB | n=500 |
42 | Correct | 32 ms | 37724 KB | n=500 |
43 | Correct | 32 ms | 37724 KB | n=500 |
44 | Correct | 33 ms | 37724 KB | n=500 |
45 | Correct | 33 ms | 37724 KB | n=500 |
46 | Correct | 32 ms | 37724 KB | n=500 |
47 | Correct | 32 ms | 37724 KB | n=500 |
48 | Correct | 34 ms | 37724 KB | n=500 |
49 | Correct | 33 ms | 37724 KB | n=500 |
50 | Correct | 33 ms | 37724 KB | n=500 |
51 | Correct | 35 ms | 37728 KB | n=500 |
52 | Correct | 33 ms | 37728 KB | n=500 |
53 | Correct | 33 ms | 37728 KB | n=500 |
54 | Correct | 36 ms | 37728 KB | n=500 |
55 | Correct | 31 ms | 37728 KB | n=278 |
56 | Correct | 37 ms | 37728 KB | n=500 |
57 | Correct | 33 ms | 37728 KB | n=500 |
58 | Correct | 39 ms | 37728 KB | n=500 |
59 | Correct | 36 ms | 37852 KB | n=2000 |
60 | Correct | 38 ms | 38108 KB | n=2000 |
61 | Correct | 38 ms | 38108 KB | n=2000 |
62 | Correct | 37 ms | 38108 KB | n=2000 |
63 | Correct | 36 ms | 38108 KB | n=2000 |
64 | Correct | 37 ms | 38108 KB | n=2000 |
65 | Correct | 37 ms | 38108 KB | n=2000 |
66 | Correct | 36 ms | 38108 KB | n=2000 |
67 | Correct | 35 ms | 38108 KB | n=2000 |
68 | Correct | 43 ms | 38108 KB | n=2000 |
69 | Correct | 39 ms | 38108 KB | n=2000 |
70 | Correct | 39 ms | 38108 KB | n=2000 |
71 | Correct | 37 ms | 38108 KB | n=2000 |
72 | Correct | 42 ms | 38108 KB | n=2000 |
73 | Correct | 35 ms | 38108 KB | n=2000 |
74 | Correct | 37 ms | 38108 KB | n=1844 |
75 | Correct | 43 ms | 38108 KB | n=2000 |
76 | Correct | 45 ms | 38108 KB | n=2000 |
77 | Correct | 46 ms | 38108 KB | n=2000 |
78 | Correct | 38 ms | 38108 KB | n=2000 |
79 | Correct | 37 ms | 38108 KB | n=2000 |
80 | Correct | 38 ms | 38108 KB | n=2000 |
81 | Correct | 39 ms | 38108 KB | n=2000 |
82 | Correct | 38 ms | 38108 KB | n=2000 |
83 | Correct | 38 ms | 38108 KB | n=2000 |
84 | Correct | 38 ms | 38108 KB | n=2000 |
85 | Correct | 36 ms | 38108 KB | n=2000 |
86 | Correct | 36 ms | 38108 KB | n=2000 |
87 | Correct | 37 ms | 38108 KB | n=2000 |
88 | Correct | 42 ms | 38172 KB | n=2000 |
89 | Correct | 36 ms | 38172 KB | n=2000 |
90 | Correct | 38 ms | 38172 KB | n=2000 |
91 | Correct | 34 ms | 38172 KB | n=2000 |
92 | Correct | 1109 ms | 72416 KB | n=200000 |
93 | Correct | 1933 ms | 95432 KB | n=200000 |
94 | Correct | 2004 ms | 102688 KB | n=200000 |
95 | Correct | 1020 ms | 102688 KB | n=200000 |
96 | Correct | 1110 ms | 102688 KB | n=200000 |
97 | Correct | 2013 ms | 102688 KB | n=200000 |
98 | Correct | 1077 ms | 102688 KB | n=200000 |
99 | Correct | 1304 ms | 102688 KB | n=200000 |
100 | Correct | 1136 ms | 102688 KB | n=200000 |
101 | Correct | 1969 ms | 104732 KB | n=200000 |
102 | Correct | 671 ms | 104732 KB | n=200000 |
103 | Correct | 682 ms | 104732 KB | n=200000 |
104 | Correct | 669 ms | 104732 KB | n=200000 |
105 | Correct | 872 ms | 104732 KB | n=200000 |
106 | Correct | 820 ms | 104732 KB | n=200000 |
107 | Correct | 744 ms | 104732 KB | n=200000 |
108 | Correct | 1293 ms | 104732 KB | n=200000 |
109 | Correct | 1288 ms | 104732 KB | n=200000 |
110 | Correct | 1239 ms | 104732 KB | n=200000 |
111 | Correct | 1158 ms | 104732 KB | n=200000 |
112 | Correct | 1990 ms | 104732 KB | n=200000 |
113 | Correct | 1983 ms | 104732 KB | n=200000 |
114 | Correct | 1111 ms | 104732 KB | n=200000 |
115 | Correct | 2017 ms | 104732 KB | n=200000 |
116 | Correct | 1014 ms | 104732 KB | n=200000 |
117 | Correct | 2001 ms | 104732 KB | n=200000 |
118 | Correct | 1863 ms | 104732 KB | n=200000 |
119 | Correct | 998 ms | 104732 KB | n=200000 |
120 | Correct | 1920 ms | 104732 KB | n=200000 |
121 | Correct | 1985 ms | 104732 KB | n=200000 |
122 | Correct | 2045 ms | 105188 KB | n=200000 |
123 | Correct | 748 ms | 105188 KB | n=200000 |
124 | Correct | 458 ms | 105188 KB | n=25264 |