# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
40431 | 2018-02-01T13:00:44 Z | szawinis | Birthday gift (IZhO18_treearray) | C++14 | 4000 ms | 262144 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]; 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]; } unordered_map<int, unordered_set<int> > t[2*N]; void update(int i, int nw, int idx) { i += N; t[i][lca(a[idx], a[idx+1])].erase(idx); t[i][nw].insert(idx); i >>= 1; while(i >= 1) { t[i][lca(a[idx], a[idx+1])].erase(idx); t[i][nw].insert(idx); i >>= 1; } } int query(int l, int r, int v) { int res = -1; for(l += N, r += N + 1; l < r; l >>= 1, r >>= 1) { if(l & 1) { if(!t[l][v].empty()) res = *t[l][v].begin(); ++l; } if(r & 1) { --r; if(!t[r][v].empty()) res = *t[r][v].begin(); } } return res; } 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) t[N+i-1][lca(a[i-1], a[i])].insert(i-1); } for(int i = N-1; i >= 1; i--) { t[i].insert(t[i<<1].begin(), t[i<<1].end()); for(auto elem: t[i<<1|1]) { for(int v: elem.second) t[i][elem.first].insert(v); } } 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) update(i, lca(v, a[i+1]), i); if(i > 1) update(i-1, lca(a[i-1], v), i-1); pos[a[i]].erase(i); a[i] = v; pos[a[i]].insert(i); } else { scanf("%d %d %d", &l, &r, &v); int res = query(l, r-1, v); if(res == -1) { 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); } else printf("%d %d\n", res, res+1); } } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 49 ms | 53624 KB | n=5 |
2 | Correct | 49 ms | 53936 KB | n=100 |
3 | Correct | 52 ms | 53936 KB | n=100 |
4 | Correct | 49 ms | 54000 KB | n=100 |
5 | Correct | 53 ms | 54144 KB | n=100 |
6 | Correct | 62 ms | 54144 KB | n=100 |
7 | Correct | 62 ms | 54144 KB | n=100 |
8 | Correct | 49 ms | 54144 KB | n=100 |
9 | Correct | 52 ms | 54144 KB | n=100 |
10 | Correct | 52 ms | 54144 KB | n=100 |
11 | Correct | 51 ms | 54144 KB | n=100 |
12 | Correct | 52 ms | 54144 KB | n=100 |
13 | Correct | 51 ms | 54144 KB | n=100 |
14 | Correct | 53 ms | 54144 KB | n=100 |
15 | Correct | 51 ms | 54144 KB | n=100 |
16 | Correct | 51 ms | 54144 KB | n=100 |
17 | Correct | 54 ms | 54236 KB | n=100 |
18 | Correct | 64 ms | 54236 KB | n=100 |
19 | Correct | 61 ms | 54236 KB | n=100 |
20 | Correct | 52 ms | 54236 KB | n=100 |
21 | Correct | 54 ms | 54236 KB | n=100 |
22 | Correct | 51 ms | 54236 KB | n=100 |
23 | Correct | 52 ms | 54236 KB | n=100 |
24 | Correct | 51 ms | 54236 KB | n=100 |
25 | Correct | 51 ms | 54236 KB | n=100 |
26 | Correct | 50 ms | 54236 KB | n=12 |
27 | Correct | 54 ms | 54236 KB | n=100 |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 49 ms | 53624 KB | n=5 |
2 | Correct | 49 ms | 53936 KB | n=100 |
3 | Correct | 52 ms | 53936 KB | n=100 |
4 | Correct | 49 ms | 54000 KB | n=100 |
5 | Correct | 53 ms | 54144 KB | n=100 |
6 | Correct | 62 ms | 54144 KB | n=100 |
7 | Correct | 62 ms | 54144 KB | n=100 |
8 | Correct | 49 ms | 54144 KB | n=100 |
9 | Correct | 52 ms | 54144 KB | n=100 |
10 | Correct | 52 ms | 54144 KB | n=100 |
11 | Correct | 51 ms | 54144 KB | n=100 |
12 | Correct | 52 ms | 54144 KB | n=100 |
13 | Correct | 51 ms | 54144 KB | n=100 |
14 | Correct | 53 ms | 54144 KB | n=100 |
15 | Correct | 51 ms | 54144 KB | n=100 |
16 | Correct | 51 ms | 54144 KB | n=100 |
17 | Correct | 54 ms | 54236 KB | n=100 |
18 | Correct | 64 ms | 54236 KB | n=100 |
19 | Correct | 61 ms | 54236 KB | n=100 |
20 | Correct | 52 ms | 54236 KB | n=100 |
21 | Correct | 54 ms | 54236 KB | n=100 |
22 | Correct | 51 ms | 54236 KB | n=100 |
23 | Correct | 52 ms | 54236 KB | n=100 |
24 | Correct | 51 ms | 54236 KB | n=100 |
25 | Correct | 51 ms | 54236 KB | n=100 |
26 | Correct | 50 ms | 54236 KB | n=12 |
27 | Correct | 54 ms | 54236 KB | n=100 |
28 | Correct | 54 ms | 54620 KB | n=500 |
29 | Correct | 66 ms | 55464 KB | n=500 |
30 | Correct | 58 ms | 55464 KB | n=500 |
31 | Correct | 58 ms | 55464 KB | n=500 |
32 | Correct | 57 ms | 55464 KB | n=500 |
33 | Correct | 59 ms | 55464 KB | n=500 |
34 | Correct | 55 ms | 55464 KB | n=500 |
35 | Correct | 58 ms | 55516 KB | n=500 |
36 | Correct | 53 ms | 55516 KB | n=500 |
37 | Correct | 54 ms | 55516 KB | n=500 |
38 | Correct | 53 ms | 55516 KB | n=500 |
39 | Correct | 55 ms | 55516 KB | n=500 |
40 | Correct | 51 ms | 55516 KB | n=500 |
41 | Correct | 53 ms | 55516 KB | n=500 |
42 | Correct | 59 ms | 55516 KB | n=500 |
43 | Correct | 61 ms | 55516 KB | n=500 |
44 | Correct | 62 ms | 55516 KB | n=500 |
45 | Correct | 65 ms | 55516 KB | n=500 |
46 | Correct | 58 ms | 55516 KB | n=500 |
47 | Correct | 59 ms | 55516 KB | n=500 |
48 | Correct | 56 ms | 55516 KB | n=500 |
49 | Correct | 67 ms | 55516 KB | n=500 |
50 | Correct | 63 ms | 55516 KB | n=500 |
51 | Correct | 63 ms | 55516 KB | n=500 |
52 | Correct | 58 ms | 55576 KB | n=500 |
53 | Correct | 59 ms | 55576 KB | n=500 |
54 | Correct | 58 ms | 55576 KB | n=500 |
55 | Correct | 59 ms | 55576 KB | n=278 |
56 | Correct | 65 ms | 55576 KB | n=500 |
57 | Correct | 60 ms | 55576 KB | n=500 |
58 | Correct | 54 ms | 55576 KB | n=500 |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 49 ms | 53624 KB | n=5 |
2 | Correct | 49 ms | 53936 KB | n=100 |
3 | Correct | 52 ms | 53936 KB | n=100 |
4 | Correct | 49 ms | 54000 KB | n=100 |
5 | Correct | 53 ms | 54144 KB | n=100 |
6 | Correct | 62 ms | 54144 KB | n=100 |
7 | Correct | 62 ms | 54144 KB | n=100 |
8 | Correct | 49 ms | 54144 KB | n=100 |
9 | Correct | 52 ms | 54144 KB | n=100 |
10 | Correct | 52 ms | 54144 KB | n=100 |
11 | Correct | 51 ms | 54144 KB | n=100 |
12 | Correct | 52 ms | 54144 KB | n=100 |
13 | Correct | 51 ms | 54144 KB | n=100 |
14 | Correct | 53 ms | 54144 KB | n=100 |
15 | Correct | 51 ms | 54144 KB | n=100 |
16 | Correct | 51 ms | 54144 KB | n=100 |
17 | Correct | 54 ms | 54236 KB | n=100 |
18 | Correct | 64 ms | 54236 KB | n=100 |
19 | Correct | 61 ms | 54236 KB | n=100 |
20 | Correct | 52 ms | 54236 KB | n=100 |
21 | Correct | 54 ms | 54236 KB | n=100 |
22 | Correct | 51 ms | 54236 KB | n=100 |
23 | Correct | 52 ms | 54236 KB | n=100 |
24 | Correct | 51 ms | 54236 KB | n=100 |
25 | Correct | 51 ms | 54236 KB | n=100 |
26 | Correct | 50 ms | 54236 KB | n=12 |
27 | Correct | 54 ms | 54236 KB | n=100 |
28 | Correct | 54 ms | 54620 KB | n=500 |
29 | Correct | 66 ms | 55464 KB | n=500 |
30 | Correct | 58 ms | 55464 KB | n=500 |
31 | Correct | 58 ms | 55464 KB | n=500 |
32 | Correct | 57 ms | 55464 KB | n=500 |
33 | Correct | 59 ms | 55464 KB | n=500 |
34 | Correct | 55 ms | 55464 KB | n=500 |
35 | Correct | 58 ms | 55516 KB | n=500 |
36 | Correct | 53 ms | 55516 KB | n=500 |
37 | Correct | 54 ms | 55516 KB | n=500 |
38 | Correct | 53 ms | 55516 KB | n=500 |
39 | Correct | 55 ms | 55516 KB | n=500 |
40 | Correct | 51 ms | 55516 KB | n=500 |
41 | Correct | 53 ms | 55516 KB | n=500 |
42 | Correct | 59 ms | 55516 KB | n=500 |
43 | Correct | 61 ms | 55516 KB | n=500 |
44 | Correct | 62 ms | 55516 KB | n=500 |
45 | Correct | 65 ms | 55516 KB | n=500 |
46 | Correct | 58 ms | 55516 KB | n=500 |
47 | Correct | 59 ms | 55516 KB | n=500 |
48 | Correct | 56 ms | 55516 KB | n=500 |
49 | Correct | 67 ms | 55516 KB | n=500 |
50 | Correct | 63 ms | 55516 KB | n=500 |
51 | Correct | 63 ms | 55516 KB | n=500 |
52 | Correct | 58 ms | 55576 KB | n=500 |
53 | Correct | 59 ms | 55576 KB | n=500 |
54 | Correct | 58 ms | 55576 KB | n=500 |
55 | Correct | 59 ms | 55576 KB | n=278 |
56 | Correct | 65 ms | 55576 KB | n=500 |
57 | Correct | 60 ms | 55576 KB | n=500 |
58 | Correct | 54 ms | 55576 KB | n=500 |
59 | Correct | 77 ms | 56584 KB | n=2000 |
60 | Correct | 107 ms | 60764 KB | n=2000 |
61 | Correct | 98 ms | 60764 KB | n=2000 |
62 | Correct | 93 ms | 60764 KB | n=2000 |
63 | Correct | 76 ms | 60764 KB | n=2000 |
64 | Correct | 95 ms | 60764 KB | n=2000 |
65 | Correct | 74 ms | 60764 KB | n=2000 |
66 | Correct | 102 ms | 60764 KB | n=2000 |
67 | Correct | 82 ms | 60764 KB | n=2000 |
68 | Correct | 97 ms | 60764 KB | n=2000 |
69 | Correct | 64 ms | 60764 KB | n=2000 |
70 | Correct | 63 ms | 60764 KB | n=2000 |
71 | Correct | 62 ms | 60764 KB | n=2000 |
72 | Correct | 62 ms | 60764 KB | n=2000 |
73 | Correct | 70 ms | 60764 KB | n=2000 |
74 | Correct | 69 ms | 60764 KB | n=1844 |
75 | Correct | 60 ms | 60764 KB | n=2000 |
76 | Correct | 92 ms | 60764 KB | n=2000 |
77 | Correct | 77 ms | 60764 KB | n=2000 |
78 | Correct | 81 ms | 60764 KB | n=2000 |
79 | Correct | 78 ms | 60764 KB | n=2000 |
80 | Correct | 99 ms | 60764 KB | n=2000 |
81 | Correct | 89 ms | 60764 KB | n=2000 |
82 | Correct | 81 ms | 60764 KB | n=2000 |
83 | Correct | 102 ms | 60764 KB | n=2000 |
84 | Correct | 79 ms | 60764 KB | n=2000 |
85 | Correct | 104 ms | 60764 KB | n=2000 |
86 | Correct | 100 ms | 60764 KB | n=2000 |
87 | Correct | 80 ms | 60764 KB | n=2000 |
88 | Correct | 97 ms | 60764 KB | n=2000 |
89 | Correct | 98 ms | 60764 KB | n=2000 |
90 | Correct | 92 ms | 60764 KB | n=2000 |
91 | Correct | 73 ms | 60764 KB | n=2000 |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 49 ms | 53624 KB | n=5 |
2 | Correct | 49 ms | 53936 KB | n=100 |
3 | Correct | 52 ms | 53936 KB | n=100 |
4 | Correct | 49 ms | 54000 KB | n=100 |
5 | Correct | 53 ms | 54144 KB | n=100 |
6 | Correct | 62 ms | 54144 KB | n=100 |
7 | Correct | 62 ms | 54144 KB | n=100 |
8 | Correct | 49 ms | 54144 KB | n=100 |
9 | Correct | 52 ms | 54144 KB | n=100 |
10 | Correct | 52 ms | 54144 KB | n=100 |
11 | Correct | 51 ms | 54144 KB | n=100 |
12 | Correct | 52 ms | 54144 KB | n=100 |
13 | Correct | 51 ms | 54144 KB | n=100 |
14 | Correct | 53 ms | 54144 KB | n=100 |
15 | Correct | 51 ms | 54144 KB | n=100 |
16 | Correct | 51 ms | 54144 KB | n=100 |
17 | Correct | 54 ms | 54236 KB | n=100 |
18 | Correct | 64 ms | 54236 KB | n=100 |
19 | Correct | 61 ms | 54236 KB | n=100 |
20 | Correct | 52 ms | 54236 KB | n=100 |
21 | Correct | 54 ms | 54236 KB | n=100 |
22 | Correct | 51 ms | 54236 KB | n=100 |
23 | Correct | 52 ms | 54236 KB | n=100 |
24 | Correct | 51 ms | 54236 KB | n=100 |
25 | Correct | 51 ms | 54236 KB | n=100 |
26 | Correct | 50 ms | 54236 KB | n=12 |
27 | Correct | 54 ms | 54236 KB | n=100 |
28 | Correct | 54 ms | 54620 KB | n=500 |
29 | Correct | 66 ms | 55464 KB | n=500 |
30 | Correct | 58 ms | 55464 KB | n=500 |
31 | Correct | 58 ms | 55464 KB | n=500 |
32 | Correct | 57 ms | 55464 KB | n=500 |
33 | Correct | 59 ms | 55464 KB | n=500 |
34 | Correct | 55 ms | 55464 KB | n=500 |
35 | Correct | 58 ms | 55516 KB | n=500 |
36 | Correct | 53 ms | 55516 KB | n=500 |
37 | Correct | 54 ms | 55516 KB | n=500 |
38 | Correct | 53 ms | 55516 KB | n=500 |
39 | Correct | 55 ms | 55516 KB | n=500 |
40 | Correct | 51 ms | 55516 KB | n=500 |
41 | Correct | 53 ms | 55516 KB | n=500 |
42 | Correct | 59 ms | 55516 KB | n=500 |
43 | Correct | 61 ms | 55516 KB | n=500 |
44 | Correct | 62 ms | 55516 KB | n=500 |
45 | Correct | 65 ms | 55516 KB | n=500 |
46 | Correct | 58 ms | 55516 KB | n=500 |
47 | Correct | 59 ms | 55516 KB | n=500 |
48 | Correct | 56 ms | 55516 KB | n=500 |
49 | Correct | 67 ms | 55516 KB | n=500 |
50 | Correct | 63 ms | 55516 KB | n=500 |
51 | Correct | 63 ms | 55516 KB | n=500 |
52 | Correct | 58 ms | 55576 KB | n=500 |
53 | Correct | 59 ms | 55576 KB | n=500 |
54 | Correct | 58 ms | 55576 KB | n=500 |
55 | Correct | 59 ms | 55576 KB | n=278 |
56 | Correct | 65 ms | 55576 KB | n=500 |
57 | Correct | 60 ms | 55576 KB | n=500 |
58 | Correct | 54 ms | 55576 KB | n=500 |
59 | Correct | 77 ms | 56584 KB | n=2000 |
60 | Correct | 107 ms | 60764 KB | n=2000 |
61 | Correct | 98 ms | 60764 KB | n=2000 |
62 | Correct | 93 ms | 60764 KB | n=2000 |
63 | Correct | 76 ms | 60764 KB | n=2000 |
64 | Correct | 95 ms | 60764 KB | n=2000 |
65 | Correct | 74 ms | 60764 KB | n=2000 |
66 | Correct | 102 ms | 60764 KB | n=2000 |
67 | Correct | 82 ms | 60764 KB | n=2000 |
68 | Correct | 97 ms | 60764 KB | n=2000 |
69 | Correct | 64 ms | 60764 KB | n=2000 |
70 | Correct | 63 ms | 60764 KB | n=2000 |
71 | Correct | 62 ms | 60764 KB | n=2000 |
72 | Correct | 62 ms | 60764 KB | n=2000 |
73 | Correct | 70 ms | 60764 KB | n=2000 |
74 | Correct | 69 ms | 60764 KB | n=1844 |
75 | Correct | 60 ms | 60764 KB | n=2000 |
76 | Correct | 92 ms | 60764 KB | n=2000 |
77 | Correct | 77 ms | 60764 KB | n=2000 |
78 | Correct | 81 ms | 60764 KB | n=2000 |
79 | Correct | 78 ms | 60764 KB | n=2000 |
80 | Correct | 99 ms | 60764 KB | n=2000 |
81 | Correct | 89 ms | 60764 KB | n=2000 |
82 | Correct | 81 ms | 60764 KB | n=2000 |
83 | Correct | 102 ms | 60764 KB | n=2000 |
84 | Correct | 79 ms | 60764 KB | n=2000 |
85 | Correct | 104 ms | 60764 KB | n=2000 |
86 | Correct | 100 ms | 60764 KB | n=2000 |
87 | Correct | 80 ms | 60764 KB | n=2000 |
88 | Correct | 97 ms | 60764 KB | n=2000 |
89 | Correct | 98 ms | 60764 KB | n=2000 |
90 | Correct | 92 ms | 60764 KB | n=2000 |
91 | Correct | 73 ms | 60764 KB | n=2000 |
92 | Execution timed out | 4048 ms | 262144 KB | Time limit exceeded |
93 | Halted | 0 ms | 0 KB | - |