# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
84465 | 2018-11-15T10:23:36 Z | inom | Birthday gift (IZhO18_treearray) | C++14 | 1516 ms | 263168 KB |
#include<bits/stdc++.h> #define pb push_back using namespace std; #pragma GCC optimize("Ofast") #pragma GCC optimize("no-stack-protector") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native") #pragma GCC optimize("fast-math") #pragma warning(disable : 4996) const int N = 2 * 1e5 + 10; int n, m, q; int node[N]; vector<int> verr[N]; int l = 1, timer = 1; int tin[N], tout[N]; int up[N][20]; set<int> lca[N], pos[N]; void dfs(int x, int pr = 1) { tin[x] = timer; timer++; up[x][0] = pr; for (int i = 1; i <= l; i++) { up[x][i] = up[up[x][i - 1]][i - 1]; } for (auto i: verr[x]) { if (i != pr) { dfs(i, x); } } tout[x] = timer; timer++; } bool upper(int x, int y) { return tin[x] <= tin[y] && tout[x] >= tout[y]; } int get_lca(int x, int y) { if (upper(x, y)) { return x; } else if (upper(y, x)) { return y; } else { for (int i = l; i >= 0; i--) { if (!upper(up[x][i], y)) { x = up[x][i]; } } return up[x][0]; } } int main() { ios_base::sync_with_stdio(false); scanf("%d %d %d", &n, &m, &q); for (int i = 1; i <= n - 1; i++) { int x, y; scanf("%d %d", &x, &y); verr[x].pb(y); verr[y].pb(x); } for (int i = 1; i <= n; i++) { lca[i].insert(m + 1); pos[i].insert(m + 1); } while ((1<<l) <= n) { l++; } dfs(1); for (int i = 1; i <= m; i++) { scanf("%d", &node[i]); pos[node[i]].insert(i); if (i > 1) { int x = get_lca(node[i], node[i - 1]); lca[x].insert(i - 1); } } for (int i = 1; i <= q; i++) { int t; scanf("%d", &t); if (t == 1) { int x, y; scanf("%d %d", &x, &y); pos[node[x]].erase(x); if (x > 1) { int cur = get_lca(node[x], node[x - 1]); lca[cur].erase(x - 1); } if (x + 1 <= n) { int cur = get_lca(node[x], node[x + 1]); lca[cur].erase(x); } node[x] = y; pos[node[x]].insert(x); if (x > 1) { int cur = get_lca(node[x], node[x - 1]); lca[cur].insert(x - 1); } if (x + 1 <= n) { int cur = get_lca(node[x], node[x + 1]); lca[cur].insert(x); } } else { int l, r, v; scanf("%d %d %d", &l, &r, &v); auto f = pos[v].lower_bound(l), s = lca[v].lower_bound(l); if (f != pos[v].end() && *f <= r) { printf("%d %d\n", *f, *f); } else if (s != lca[v].end() && *s + 1 <= r) { printf("%d %d\n", *s, *s + 1); } else { printf("-1 -1\n"); } } } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 23 ms | 24056 KB | n=5 |
2 | Correct | 23 ms | 24056 KB | n=100 |
3 | Correct | 24 ms | 24168 KB | n=100 |
4 | Correct | 23 ms | 24216 KB | n=100 |
5 | Correct | 23 ms | 24328 KB | n=100 |
6 | Correct | 24 ms | 24332 KB | n=100 |
7 | Correct | 23 ms | 24336 KB | n=100 |
8 | Correct | 23 ms | 24356 KB | n=100 |
9 | Correct | 23 ms | 24420 KB | n=100 |
10 | Correct | 24 ms | 24428 KB | n=100 |
11 | Correct | 22 ms | 24428 KB | n=100 |
12 | Correct | 24 ms | 24432 KB | n=100 |
13 | Correct | 23 ms | 24436 KB | n=100 |
14 | Correct | 23 ms | 24440 KB | n=100 |
15 | Correct | 24 ms | 24448 KB | n=100 |
16 | Correct | 22 ms | 24568 KB | n=100 |
17 | Correct | 23 ms | 24568 KB | n=100 |
18 | Correct | 22 ms | 24568 KB | n=100 |
19 | Correct | 24 ms | 24568 KB | n=100 |
20 | Correct | 23 ms | 24568 KB | n=100 |
21 | Correct | 26 ms | 24568 KB | n=100 |
22 | Correct | 23 ms | 24568 KB | n=100 |
23 | Correct | 23 ms | 24568 KB | n=100 |
24 | Correct | 24 ms | 24604 KB | n=100 |
25 | Correct | 23 ms | 24604 KB | n=100 |
26 | Correct | 29 ms | 24604 KB | n=12 |
27 | Correct | 22 ms | 24604 KB | n=100 |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 23 ms | 24056 KB | n=5 |
2 | Correct | 23 ms | 24056 KB | n=100 |
3 | Correct | 24 ms | 24168 KB | n=100 |
4 | Correct | 23 ms | 24216 KB | n=100 |
5 | Correct | 23 ms | 24328 KB | n=100 |
6 | Correct | 24 ms | 24332 KB | n=100 |
7 | Correct | 23 ms | 24336 KB | n=100 |
8 | Correct | 23 ms | 24356 KB | n=100 |
9 | Correct | 23 ms | 24420 KB | n=100 |
10 | Correct | 24 ms | 24428 KB | n=100 |
11 | Correct | 22 ms | 24428 KB | n=100 |
12 | Correct | 24 ms | 24432 KB | n=100 |
13 | Correct | 23 ms | 24436 KB | n=100 |
14 | Correct | 23 ms | 24440 KB | n=100 |
15 | Correct | 24 ms | 24448 KB | n=100 |
16 | Correct | 22 ms | 24568 KB | n=100 |
17 | Correct | 23 ms | 24568 KB | n=100 |
18 | Correct | 22 ms | 24568 KB | n=100 |
19 | Correct | 24 ms | 24568 KB | n=100 |
20 | Correct | 23 ms | 24568 KB | n=100 |
21 | Correct | 26 ms | 24568 KB | n=100 |
22 | Correct | 23 ms | 24568 KB | n=100 |
23 | Correct | 23 ms | 24568 KB | n=100 |
24 | Correct | 24 ms | 24604 KB | n=100 |
25 | Correct | 23 ms | 24604 KB | n=100 |
26 | Correct | 29 ms | 24604 KB | n=12 |
27 | Correct | 22 ms | 24604 KB | n=100 |
28 | Correct | 24 ms | 24624 KB | n=500 |
29 | Correct | 28 ms | 24636 KB | n=500 |
30 | Correct | 24 ms | 24704 KB | n=500 |
31 | Correct | 24 ms | 24704 KB | n=500 |
32 | Correct | 26 ms | 24732 KB | n=500 |
33 | Correct | 26 ms | 24744 KB | n=500 |
34 | Correct | 24 ms | 24864 KB | n=500 |
35 | Correct | 25 ms | 24864 KB | n=500 |
36 | Correct | 25 ms | 24864 KB | n=500 |
37 | Correct | 24 ms | 24864 KB | n=500 |
38 | Correct | 24 ms | 24956 KB | n=500 |
39 | Correct | 24 ms | 24956 KB | n=500 |
40 | Correct | 24 ms | 24956 KB | n=500 |
41 | Correct | 24 ms | 24956 KB | n=500 |
42 | Correct | 24 ms | 24956 KB | n=500 |
43 | Correct | 25 ms | 24956 KB | n=500 |
44 | Correct | 24 ms | 24956 KB | n=500 |
45 | Correct | 24 ms | 24956 KB | n=500 |
46 | Correct | 23 ms | 24956 KB | n=500 |
47 | Correct | 27 ms | 24956 KB | n=500 |
48 | Correct | 25 ms | 24972 KB | n=500 |
49 | Correct | 23 ms | 24984 KB | n=500 |
50 | Correct | 35 ms | 25000 KB | n=500 |
51 | Correct | 23 ms | 25012 KB | n=500 |
52 | Correct | 24 ms | 25028 KB | n=500 |
53 | Correct | 24 ms | 25028 KB | n=500 |
54 | Correct | 25 ms | 25060 KB | n=500 |
55 | Correct | 23 ms | 25060 KB | n=278 |
56 | Correct | 28 ms | 25080 KB | n=500 |
57 | Correct | 23 ms | 25092 KB | n=500 |
58 | Correct | 24 ms | 25104 KB | n=500 |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 23 ms | 24056 KB | n=5 |
2 | Correct | 23 ms | 24056 KB | n=100 |
3 | Correct | 24 ms | 24168 KB | n=100 |
4 | Correct | 23 ms | 24216 KB | n=100 |
5 | Correct | 23 ms | 24328 KB | n=100 |
6 | Correct | 24 ms | 24332 KB | n=100 |
7 | Correct | 23 ms | 24336 KB | n=100 |
8 | Correct | 23 ms | 24356 KB | n=100 |
9 | Correct | 23 ms | 24420 KB | n=100 |
10 | Correct | 24 ms | 24428 KB | n=100 |
11 | Correct | 22 ms | 24428 KB | n=100 |
12 | Correct | 24 ms | 24432 KB | n=100 |
13 | Correct | 23 ms | 24436 KB | n=100 |
14 | Correct | 23 ms | 24440 KB | n=100 |
15 | Correct | 24 ms | 24448 KB | n=100 |
16 | Correct | 22 ms | 24568 KB | n=100 |
17 | Correct | 23 ms | 24568 KB | n=100 |
18 | Correct | 22 ms | 24568 KB | n=100 |
19 | Correct | 24 ms | 24568 KB | n=100 |
20 | Correct | 23 ms | 24568 KB | n=100 |
21 | Correct | 26 ms | 24568 KB | n=100 |
22 | Correct | 23 ms | 24568 KB | n=100 |
23 | Correct | 23 ms | 24568 KB | n=100 |
24 | Correct | 24 ms | 24604 KB | n=100 |
25 | Correct | 23 ms | 24604 KB | n=100 |
26 | Correct | 29 ms | 24604 KB | n=12 |
27 | Correct | 22 ms | 24604 KB | n=100 |
28 | Correct | 24 ms | 24624 KB | n=500 |
29 | Correct | 28 ms | 24636 KB | n=500 |
30 | Correct | 24 ms | 24704 KB | n=500 |
31 | Correct | 24 ms | 24704 KB | n=500 |
32 | Correct | 26 ms | 24732 KB | n=500 |
33 | Correct | 26 ms | 24744 KB | n=500 |
34 | Correct | 24 ms | 24864 KB | n=500 |
35 | Correct | 25 ms | 24864 KB | n=500 |
36 | Correct | 25 ms | 24864 KB | n=500 |
37 | Correct | 24 ms | 24864 KB | n=500 |
38 | Correct | 24 ms | 24956 KB | n=500 |
39 | Correct | 24 ms | 24956 KB | n=500 |
40 | Correct | 24 ms | 24956 KB | n=500 |
41 | Correct | 24 ms | 24956 KB | n=500 |
42 | Correct | 24 ms | 24956 KB | n=500 |
43 | Correct | 25 ms | 24956 KB | n=500 |
44 | Correct | 24 ms | 24956 KB | n=500 |
45 | Correct | 24 ms | 24956 KB | n=500 |
46 | Correct | 23 ms | 24956 KB | n=500 |
47 | Correct | 27 ms | 24956 KB | n=500 |
48 | Correct | 25 ms | 24972 KB | n=500 |
49 | Correct | 23 ms | 24984 KB | n=500 |
50 | Correct | 35 ms | 25000 KB | n=500 |
51 | Correct | 23 ms | 25012 KB | n=500 |
52 | Correct | 24 ms | 25028 KB | n=500 |
53 | Correct | 24 ms | 25028 KB | n=500 |
54 | Correct | 25 ms | 25060 KB | n=500 |
55 | Correct | 23 ms | 25060 KB | n=278 |
56 | Correct | 28 ms | 25080 KB | n=500 |
57 | Correct | 23 ms | 25092 KB | n=500 |
58 | Correct | 24 ms | 25104 KB | n=500 |
59 | Correct | 28 ms | 25632 KB | n=2000 |
60 | Correct | 28 ms | 25684 KB | n=2000 |
61 | Correct | 27 ms | 25732 KB | n=2000 |
62 | Correct | 28 ms | 25796 KB | n=2000 |
63 | Correct | 28 ms | 25852 KB | n=2000 |
64 | Correct | 28 ms | 25904 KB | n=2000 |
65 | Correct | 28 ms | 25960 KB | n=2000 |
66 | Correct | 28 ms | 26012 KB | n=2000 |
67 | Correct | 29 ms | 26012 KB | n=2000 |
68 | Correct | 27 ms | 26124 KB | n=2000 |
69 | Correct | 25 ms | 26184 KB | n=2000 |
70 | Correct | 35 ms | 26212 KB | n=2000 |
71 | Correct | 27 ms | 26284 KB | n=2000 |
72 | Correct | 26 ms | 26336 KB | n=2000 |
73 | Correct | 27 ms | 26356 KB | n=2000 |
74 | Correct | 27 ms | 26356 KB | n=1844 |
75 | Correct | 27 ms | 26492 KB | n=2000 |
76 | Correct | 27 ms | 26548 KB | n=2000 |
77 | Correct | 30 ms | 26580 KB | n=2000 |
78 | Correct | 28 ms | 26620 KB | n=2000 |
79 | Correct | 29 ms | 26708 KB | n=2000 |
80 | Correct | 27 ms | 26864 KB | n=2000 |
81 | Correct | 28 ms | 26864 KB | n=2000 |
82 | Correct | 28 ms | 26952 KB | n=2000 |
83 | Correct | 29 ms | 26952 KB | n=2000 |
84 | Correct | 29 ms | 26968 KB | n=2000 |
85 | Correct | 27 ms | 27020 KB | n=2000 |
86 | Correct | 28 ms | 27080 KB | n=2000 |
87 | Correct | 28 ms | 27132 KB | n=2000 |
88 | Correct | 28 ms | 27188 KB | n=2000 |
89 | Correct | 27 ms | 27248 KB | n=2000 |
90 | Correct | 27 ms | 27300 KB | n=2000 |
91 | Correct | 27 ms | 27352 KB | n=2000 |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 23 ms | 24056 KB | n=5 |
2 | Correct | 23 ms | 24056 KB | n=100 |
3 | Correct | 24 ms | 24168 KB | n=100 |
4 | Correct | 23 ms | 24216 KB | n=100 |
5 | Correct | 23 ms | 24328 KB | n=100 |
6 | Correct | 24 ms | 24332 KB | n=100 |
7 | Correct | 23 ms | 24336 KB | n=100 |
8 | Correct | 23 ms | 24356 KB | n=100 |
9 | Correct | 23 ms | 24420 KB | n=100 |
10 | Correct | 24 ms | 24428 KB | n=100 |
11 | Correct | 22 ms | 24428 KB | n=100 |
12 | Correct | 24 ms | 24432 KB | n=100 |
13 | Correct | 23 ms | 24436 KB | n=100 |
14 | Correct | 23 ms | 24440 KB | n=100 |
15 | Correct | 24 ms | 24448 KB | n=100 |
16 | Correct | 22 ms | 24568 KB | n=100 |
17 | Correct | 23 ms | 24568 KB | n=100 |
18 | Correct | 22 ms | 24568 KB | n=100 |
19 | Correct | 24 ms | 24568 KB | n=100 |
20 | Correct | 23 ms | 24568 KB | n=100 |
21 | Correct | 26 ms | 24568 KB | n=100 |
22 | Correct | 23 ms | 24568 KB | n=100 |
23 | Correct | 23 ms | 24568 KB | n=100 |
24 | Correct | 24 ms | 24604 KB | n=100 |
25 | Correct | 23 ms | 24604 KB | n=100 |
26 | Correct | 29 ms | 24604 KB | n=12 |
27 | Correct | 22 ms | 24604 KB | n=100 |
28 | Correct | 24 ms | 24624 KB | n=500 |
29 | Correct | 28 ms | 24636 KB | n=500 |
30 | Correct | 24 ms | 24704 KB | n=500 |
31 | Correct | 24 ms | 24704 KB | n=500 |
32 | Correct | 26 ms | 24732 KB | n=500 |
33 | Correct | 26 ms | 24744 KB | n=500 |
34 | Correct | 24 ms | 24864 KB | n=500 |
35 | Correct | 25 ms | 24864 KB | n=500 |
36 | Correct | 25 ms | 24864 KB | n=500 |
37 | Correct | 24 ms | 24864 KB | n=500 |
38 | Correct | 24 ms | 24956 KB | n=500 |
39 | Correct | 24 ms | 24956 KB | n=500 |
40 | Correct | 24 ms | 24956 KB | n=500 |
41 | Correct | 24 ms | 24956 KB | n=500 |
42 | Correct | 24 ms | 24956 KB | n=500 |
43 | Correct | 25 ms | 24956 KB | n=500 |
44 | Correct | 24 ms | 24956 KB | n=500 |
45 | Correct | 24 ms | 24956 KB | n=500 |
46 | Correct | 23 ms | 24956 KB | n=500 |
47 | Correct | 27 ms | 24956 KB | n=500 |
48 | Correct | 25 ms | 24972 KB | n=500 |
49 | Correct | 23 ms | 24984 KB | n=500 |
50 | Correct | 35 ms | 25000 KB | n=500 |
51 | Correct | 23 ms | 25012 KB | n=500 |
52 | Correct | 24 ms | 25028 KB | n=500 |
53 | Correct | 24 ms | 25028 KB | n=500 |
54 | Correct | 25 ms | 25060 KB | n=500 |
55 | Correct | 23 ms | 25060 KB | n=278 |
56 | Correct | 28 ms | 25080 KB | n=500 |
57 | Correct | 23 ms | 25092 KB | n=500 |
58 | Correct | 24 ms | 25104 KB | n=500 |
59 | Correct | 28 ms | 25632 KB | n=2000 |
60 | Correct | 28 ms | 25684 KB | n=2000 |
61 | Correct | 27 ms | 25732 KB | n=2000 |
62 | Correct | 28 ms | 25796 KB | n=2000 |
63 | Correct | 28 ms | 25852 KB | n=2000 |
64 | Correct | 28 ms | 25904 KB | n=2000 |
65 | Correct | 28 ms | 25960 KB | n=2000 |
66 | Correct | 28 ms | 26012 KB | n=2000 |
67 | Correct | 29 ms | 26012 KB | n=2000 |
68 | Correct | 27 ms | 26124 KB | n=2000 |
69 | Correct | 25 ms | 26184 KB | n=2000 |
70 | Correct | 35 ms | 26212 KB | n=2000 |
71 | Correct | 27 ms | 26284 KB | n=2000 |
72 | Correct | 26 ms | 26336 KB | n=2000 |
73 | Correct | 27 ms | 26356 KB | n=2000 |
74 | Correct | 27 ms | 26356 KB | n=1844 |
75 | Correct | 27 ms | 26492 KB | n=2000 |
76 | Correct | 27 ms | 26548 KB | n=2000 |
77 | Correct | 30 ms | 26580 KB | n=2000 |
78 | Correct | 28 ms | 26620 KB | n=2000 |
79 | Correct | 29 ms | 26708 KB | n=2000 |
80 | Correct | 27 ms | 26864 KB | n=2000 |
81 | Correct | 28 ms | 26864 KB | n=2000 |
82 | Correct | 28 ms | 26952 KB | n=2000 |
83 | Correct | 29 ms | 26952 KB | n=2000 |
84 | Correct | 29 ms | 26968 KB | n=2000 |
85 | Correct | 27 ms | 27020 KB | n=2000 |
86 | Correct | 28 ms | 27080 KB | n=2000 |
87 | Correct | 28 ms | 27132 KB | n=2000 |
88 | Correct | 28 ms | 27188 KB | n=2000 |
89 | Correct | 27 ms | 27248 KB | n=2000 |
90 | Correct | 27 ms | 27300 KB | n=2000 |
91 | Correct | 27 ms | 27352 KB | n=2000 |
92 | Correct | 1200 ms | 97064 KB | n=200000 |
93 | Correct | 1266 ms | 107540 KB | n=200000 |
94 | Correct | 1004 ms | 117796 KB | n=200000 |
95 | Correct | 1133 ms | 118636 KB | n=200000 |
96 | Correct | 1196 ms | 125368 KB | n=200000 |
97 | Correct | 1473 ms | 135136 KB | n=200000 |
98 | Correct | 1215 ms | 139412 KB | n=200000 |
99 | Correct | 1283 ms | 146072 KB | n=200000 |
100 | Correct | 1202 ms | 153156 KB | n=200000 |
101 | Correct | 936 ms | 167160 KB | n=200000 |
102 | Correct | 656 ms | 168336 KB | n=200000 |
103 | Correct | 678 ms | 175036 KB | n=200000 |
104 | Correct | 695 ms | 181624 KB | n=200000 |
105 | Correct | 676 ms | 188808 KB | n=200000 |
106 | Correct | 663 ms | 196168 KB | n=200000 |
107 | Correct | 720 ms | 203516 KB | n=200000 |
108 | Correct | 1207 ms | 209472 KB | n=200000 |
109 | Correct | 1145 ms | 216452 KB | n=200000 |
110 | Correct | 1108 ms | 223236 KB | n=200000 |
111 | Correct | 1140 ms | 229596 KB | n=200000 |
112 | Correct | 894 ms | 243128 KB | n=200000 |
113 | Correct | 1259 ms | 247164 KB | n=200000 |
114 | Correct | 1203 ms | 251148 KB | n=200000 |
115 | Correct | 1516 ms | 259128 KB | n=200000 |
116 | Runtime error | 1078 ms | 263168 KB | Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |
117 | Halted | 0 ms | 0 KB | - |