# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
319317 | 2020-11-04T16:47:43 Z | BeanZ | Birthday gift (IZhO18_treearray) | C++14 | 1252 ms | 89444 KB |
// I_Love_LPL #include <bits/stdc++.h> using namespace std; //#define task "A" #define ll int #define endl '\n' const int N = 2e5 + 5; const int mod = 1e9 + 7; const int lg = 18; ll dp[N][lg + 1], dep[N]; vector<ll> node[N]; struct LCA{ ll lca(ll u, ll v){ if (dep[v] < dep[u]) swap(u, v); ll dis = dep[v] - dep[u]; for (int i = lg; i >= 0; i--){ if (dis & (1 << i)){ v = dp[v][i]; } } if (v == u) return u; for (int i = lg; i >= 0; i--){ if (dp[u][i] != dp[v][i]){ v = dp[v][i]; u = dp[u][i]; } } return dp[u][0]; } void dfs(ll u, ll v){ for (int i = 1; i <= lg; i++) dp[u][i] = dp[dp[u][i - 1]][i - 1]; for (auto j : node[u]){ if (j == v) continue; dep[j] = dep[u] + 1; dp[j][0] = u; dfs(j, u); } } } tree; set<ll> two[N], one[N]; ll a[N]; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); if (fopen(".inp", "r")){ freopen(".inp", "r", stdin); freopen(".out", "w", stdout); } ll n, m, q; cin >> n >> m >> q; for (int i = 1; i < n; i++){ ll u, v; cin >> u >> v; node[u].push_back(v); node[v].push_back(u); } tree.dfs(1, 1); for (int i = 1; i <= m; i++) cin >> a[i]; for (int i = 1; i < m; i++) two[tree.lca(a[i], a[i + 1])].insert(i); for (int i = 1; i <= m; i++) one[a[i]].insert(i); while (q--){ ll task; cin >> task; if (task == 1){ ll x, v; cin >> x >> v; one[a[x]].erase(x); one[v].insert(x); if (x < m) two[tree.lca(a[x], a[x + 1])].erase(x); if (x < m) two[tree.lca(v, a[x + 1])].insert(x); if (x > 1) two[tree.lca(a[x - 1], a[x])].erase(x - 1); if (x > 1) two[tree.lca(a[x - 1], v)].insert(x - 1); a[x] = v; } else { ll l, r, v; cin >> l >> r >> v; if (two[v].lower_bound(l) == two[v].end() || *two[v].lower_bound(l) >= r){ if (one[v].lower_bound(l) == one[v].end() || *one[v].lower_bound(l) > r) cout << -1 << " " << -1 << endl; else cout << *one[v].lower_bound(l) << " " << *one[v].lower_bound(l) << endl; } else cout << *two[v].lower_bound(l) << " " << *two[v].lower_bound(l) + 1 << endl; } } } /* 5 4 4 1 2 3 1 3 4 5 3 4 5 2 3 2 1 3 1 1 3 5 2 3 4 5 2 1 3 1 */
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 23788 KB | n=5 |
2 | Correct | 16 ms | 23916 KB | n=100 |
3 | Correct | 16 ms | 23916 KB | n=100 |
4 | Correct | 16 ms | 23916 KB | n=100 |
5 | Correct | 18 ms | 23916 KB | n=100 |
6 | Correct | 16 ms | 23916 KB | n=100 |
7 | Correct | 16 ms | 23916 KB | n=100 |
8 | Correct | 16 ms | 23916 KB | n=100 |
9 | Correct | 16 ms | 23916 KB | n=100 |
10 | Correct | 16 ms | 23908 KB | n=100 |
11 | Correct | 16 ms | 23916 KB | n=100 |
12 | Correct | 16 ms | 23916 KB | n=100 |
13 | Correct | 16 ms | 23916 KB | n=100 |
14 | Correct | 16 ms | 23916 KB | n=100 |
15 | Correct | 16 ms | 23916 KB | n=100 |
16 | Correct | 16 ms | 23936 KB | n=100 |
17 | Correct | 17 ms | 23916 KB | n=100 |
18 | Correct | 17 ms | 23916 KB | n=100 |
19 | Correct | 16 ms | 23916 KB | n=100 |
20 | Correct | 16 ms | 23916 KB | n=100 |
21 | Correct | 16 ms | 23916 KB | n=100 |
22 | Correct | 16 ms | 23916 KB | n=100 |
23 | Correct | 16 ms | 23916 KB | n=100 |
24 | Correct | 16 ms | 23916 KB | n=100 |
25 | Correct | 16 ms | 23916 KB | n=100 |
26 | Correct | 16 ms | 23788 KB | n=12 |
27 | Correct | 16 ms | 23916 KB | n=100 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 23788 KB | n=5 |
2 | Correct | 16 ms | 23916 KB | n=100 |
3 | Correct | 16 ms | 23916 KB | n=100 |
4 | Correct | 16 ms | 23916 KB | n=100 |
5 | Correct | 18 ms | 23916 KB | n=100 |
6 | Correct | 16 ms | 23916 KB | n=100 |
7 | Correct | 16 ms | 23916 KB | n=100 |
8 | Correct | 16 ms | 23916 KB | n=100 |
9 | Correct | 16 ms | 23916 KB | n=100 |
10 | Correct | 16 ms | 23908 KB | n=100 |
11 | Correct | 16 ms | 23916 KB | n=100 |
12 | Correct | 16 ms | 23916 KB | n=100 |
13 | Correct | 16 ms | 23916 KB | n=100 |
14 | Correct | 16 ms | 23916 KB | n=100 |
15 | Correct | 16 ms | 23916 KB | n=100 |
16 | Correct | 16 ms | 23936 KB | n=100 |
17 | Correct | 17 ms | 23916 KB | n=100 |
18 | Correct | 17 ms | 23916 KB | n=100 |
19 | Correct | 16 ms | 23916 KB | n=100 |
20 | Correct | 16 ms | 23916 KB | n=100 |
21 | Correct | 16 ms | 23916 KB | n=100 |
22 | Correct | 16 ms | 23916 KB | n=100 |
23 | Correct | 16 ms | 23916 KB | n=100 |
24 | Correct | 16 ms | 23916 KB | n=100 |
25 | Correct | 16 ms | 23916 KB | n=100 |
26 | Correct | 16 ms | 23788 KB | n=12 |
27 | Correct | 16 ms | 23916 KB | n=100 |
28 | Correct | 17 ms | 23916 KB | n=500 |
29 | Correct | 17 ms | 23916 KB | n=500 |
30 | Correct | 17 ms | 23916 KB | n=500 |
31 | Correct | 17 ms | 23916 KB | n=500 |
32 | Correct | 17 ms | 23916 KB | n=500 |
33 | Correct | 17 ms | 23916 KB | n=500 |
34 | Correct | 18 ms | 23916 KB | n=500 |
35 | Correct | 18 ms | 24044 KB | n=500 |
36 | Correct | 17 ms | 23916 KB | n=500 |
37 | Correct | 17 ms | 23916 KB | n=500 |
38 | Correct | 17 ms | 23916 KB | n=500 |
39 | Correct | 17 ms | 23916 KB | n=500 |
40 | Correct | 17 ms | 23916 KB | n=500 |
41 | Correct | 17 ms | 23916 KB | n=500 |
42 | Correct | 20 ms | 23916 KB | n=500 |
43 | Correct | 18 ms | 24064 KB | n=500 |
44 | Correct | 17 ms | 23916 KB | n=500 |
45 | Correct | 17 ms | 23916 KB | n=500 |
46 | Correct | 19 ms | 23916 KB | n=500 |
47 | Correct | 17 ms | 23916 KB | n=500 |
48 | Correct | 17 ms | 23916 KB | n=500 |
49 | Correct | 17 ms | 23916 KB | n=500 |
50 | Correct | 17 ms | 23916 KB | n=500 |
51 | Correct | 17 ms | 23916 KB | n=500 |
52 | Correct | 17 ms | 23916 KB | n=500 |
53 | Correct | 17 ms | 23916 KB | n=500 |
54 | Correct | 17 ms | 23916 KB | n=500 |
55 | Correct | 16 ms | 23916 KB | n=278 |
56 | Correct | 17 ms | 23916 KB | n=500 |
57 | Correct | 18 ms | 24044 KB | n=500 |
58 | Correct | 17 ms | 23936 KB | n=500 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 23788 KB | n=5 |
2 | Correct | 16 ms | 23916 KB | n=100 |
3 | Correct | 16 ms | 23916 KB | n=100 |
4 | Correct | 16 ms | 23916 KB | n=100 |
5 | Correct | 18 ms | 23916 KB | n=100 |
6 | Correct | 16 ms | 23916 KB | n=100 |
7 | Correct | 16 ms | 23916 KB | n=100 |
8 | Correct | 16 ms | 23916 KB | n=100 |
9 | Correct | 16 ms | 23916 KB | n=100 |
10 | Correct | 16 ms | 23908 KB | n=100 |
11 | Correct | 16 ms | 23916 KB | n=100 |
12 | Correct | 16 ms | 23916 KB | n=100 |
13 | Correct | 16 ms | 23916 KB | n=100 |
14 | Correct | 16 ms | 23916 KB | n=100 |
15 | Correct | 16 ms | 23916 KB | n=100 |
16 | Correct | 16 ms | 23936 KB | n=100 |
17 | Correct | 17 ms | 23916 KB | n=100 |
18 | Correct | 17 ms | 23916 KB | n=100 |
19 | Correct | 16 ms | 23916 KB | n=100 |
20 | Correct | 16 ms | 23916 KB | n=100 |
21 | Correct | 16 ms | 23916 KB | n=100 |
22 | Correct | 16 ms | 23916 KB | n=100 |
23 | Correct | 16 ms | 23916 KB | n=100 |
24 | Correct | 16 ms | 23916 KB | n=100 |
25 | Correct | 16 ms | 23916 KB | n=100 |
26 | Correct | 16 ms | 23788 KB | n=12 |
27 | Correct | 16 ms | 23916 KB | n=100 |
28 | Correct | 17 ms | 23916 KB | n=500 |
29 | Correct | 17 ms | 23916 KB | n=500 |
30 | Correct | 17 ms | 23916 KB | n=500 |
31 | Correct | 17 ms | 23916 KB | n=500 |
32 | Correct | 17 ms | 23916 KB | n=500 |
33 | Correct | 17 ms | 23916 KB | n=500 |
34 | Correct | 18 ms | 23916 KB | n=500 |
35 | Correct | 18 ms | 24044 KB | n=500 |
36 | Correct | 17 ms | 23916 KB | n=500 |
37 | Correct | 17 ms | 23916 KB | n=500 |
38 | Correct | 17 ms | 23916 KB | n=500 |
39 | Correct | 17 ms | 23916 KB | n=500 |
40 | Correct | 17 ms | 23916 KB | n=500 |
41 | Correct | 17 ms | 23916 KB | n=500 |
42 | Correct | 20 ms | 23916 KB | n=500 |
43 | Correct | 18 ms | 24064 KB | n=500 |
44 | Correct | 17 ms | 23916 KB | n=500 |
45 | Correct | 17 ms | 23916 KB | n=500 |
46 | Correct | 19 ms | 23916 KB | n=500 |
47 | Correct | 17 ms | 23916 KB | n=500 |
48 | Correct | 17 ms | 23916 KB | n=500 |
49 | Correct | 17 ms | 23916 KB | n=500 |
50 | Correct | 17 ms | 23916 KB | n=500 |
51 | Correct | 17 ms | 23916 KB | n=500 |
52 | Correct | 17 ms | 23916 KB | n=500 |
53 | Correct | 17 ms | 23916 KB | n=500 |
54 | Correct | 17 ms | 23916 KB | n=500 |
55 | Correct | 16 ms | 23916 KB | n=278 |
56 | Correct | 17 ms | 23916 KB | n=500 |
57 | Correct | 18 ms | 24044 KB | n=500 |
58 | Correct | 17 ms | 23936 KB | n=500 |
59 | Correct | 20 ms | 24300 KB | n=2000 |
60 | Correct | 20 ms | 24428 KB | n=2000 |
61 | Correct | 20 ms | 24300 KB | n=2000 |
62 | Correct | 20 ms | 24300 KB | n=2000 |
63 | Correct | 20 ms | 24300 KB | n=2000 |
64 | Correct | 20 ms | 24308 KB | n=2000 |
65 | Correct | 20 ms | 24300 KB | n=2000 |
66 | Correct | 20 ms | 24428 KB | n=2000 |
67 | Correct | 21 ms | 24300 KB | n=2000 |
68 | Correct | 20 ms | 24444 KB | n=2000 |
69 | Correct | 19 ms | 24300 KB | n=2000 |
70 | Correct | 19 ms | 24300 KB | n=2000 |
71 | Correct | 19 ms | 24300 KB | n=2000 |
72 | Correct | 20 ms | 24300 KB | n=2000 |
73 | Correct | 19 ms | 24300 KB | n=2000 |
74 | Correct | 20 ms | 24300 KB | n=1844 |
75 | Correct | 19 ms | 24300 KB | n=2000 |
76 | Correct | 20 ms | 24300 KB | n=2000 |
77 | Correct | 21 ms | 24320 KB | n=2000 |
78 | Correct | 20 ms | 24300 KB | n=2000 |
79 | Correct | 20 ms | 24300 KB | n=2000 |
80 | Correct | 20 ms | 24428 KB | n=2000 |
81 | Correct | 22 ms | 24300 KB | n=2000 |
82 | Correct | 20 ms | 24300 KB | n=2000 |
83 | Correct | 21 ms | 24420 KB | n=2000 |
84 | Correct | 20 ms | 24428 KB | n=2000 |
85 | Correct | 21 ms | 24300 KB | n=2000 |
86 | Correct | 20 ms | 24300 KB | n=2000 |
87 | Correct | 20 ms | 24300 KB | n=2000 |
88 | Correct | 20 ms | 24428 KB | n=2000 |
89 | Correct | 19 ms | 24428 KB | n=2000 |
90 | Correct | 20 ms | 24428 KB | n=2000 |
91 | Correct | 19 ms | 24300 KB | n=2000 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 23788 KB | n=5 |
2 | Correct | 16 ms | 23916 KB | n=100 |
3 | Correct | 16 ms | 23916 KB | n=100 |
4 | Correct | 16 ms | 23916 KB | n=100 |
5 | Correct | 18 ms | 23916 KB | n=100 |
6 | Correct | 16 ms | 23916 KB | n=100 |
7 | Correct | 16 ms | 23916 KB | n=100 |
8 | Correct | 16 ms | 23916 KB | n=100 |
9 | Correct | 16 ms | 23916 KB | n=100 |
10 | Correct | 16 ms | 23908 KB | n=100 |
11 | Correct | 16 ms | 23916 KB | n=100 |
12 | Correct | 16 ms | 23916 KB | n=100 |
13 | Correct | 16 ms | 23916 KB | n=100 |
14 | Correct | 16 ms | 23916 KB | n=100 |
15 | Correct | 16 ms | 23916 KB | n=100 |
16 | Correct | 16 ms | 23936 KB | n=100 |
17 | Correct | 17 ms | 23916 KB | n=100 |
18 | Correct | 17 ms | 23916 KB | n=100 |
19 | Correct | 16 ms | 23916 KB | n=100 |
20 | Correct | 16 ms | 23916 KB | n=100 |
21 | Correct | 16 ms | 23916 KB | n=100 |
22 | Correct | 16 ms | 23916 KB | n=100 |
23 | Correct | 16 ms | 23916 KB | n=100 |
24 | Correct | 16 ms | 23916 KB | n=100 |
25 | Correct | 16 ms | 23916 KB | n=100 |
26 | Correct | 16 ms | 23788 KB | n=12 |
27 | Correct | 16 ms | 23916 KB | n=100 |
28 | Correct | 17 ms | 23916 KB | n=500 |
29 | Correct | 17 ms | 23916 KB | n=500 |
30 | Correct | 17 ms | 23916 KB | n=500 |
31 | Correct | 17 ms | 23916 KB | n=500 |
32 | Correct | 17 ms | 23916 KB | n=500 |
33 | Correct | 17 ms | 23916 KB | n=500 |
34 | Correct | 18 ms | 23916 KB | n=500 |
35 | Correct | 18 ms | 24044 KB | n=500 |
36 | Correct | 17 ms | 23916 KB | n=500 |
37 | Correct | 17 ms | 23916 KB | n=500 |
38 | Correct | 17 ms | 23916 KB | n=500 |
39 | Correct | 17 ms | 23916 KB | n=500 |
40 | Correct | 17 ms | 23916 KB | n=500 |
41 | Correct | 17 ms | 23916 KB | n=500 |
42 | Correct | 20 ms | 23916 KB | n=500 |
43 | Correct | 18 ms | 24064 KB | n=500 |
44 | Correct | 17 ms | 23916 KB | n=500 |
45 | Correct | 17 ms | 23916 KB | n=500 |
46 | Correct | 19 ms | 23916 KB | n=500 |
47 | Correct | 17 ms | 23916 KB | n=500 |
48 | Correct | 17 ms | 23916 KB | n=500 |
49 | Correct | 17 ms | 23916 KB | n=500 |
50 | Correct | 17 ms | 23916 KB | n=500 |
51 | Correct | 17 ms | 23916 KB | n=500 |
52 | Correct | 17 ms | 23916 KB | n=500 |
53 | Correct | 17 ms | 23916 KB | n=500 |
54 | Correct | 17 ms | 23916 KB | n=500 |
55 | Correct | 16 ms | 23916 KB | n=278 |
56 | Correct | 17 ms | 23916 KB | n=500 |
57 | Correct | 18 ms | 24044 KB | n=500 |
58 | Correct | 17 ms | 23936 KB | n=500 |
59 | Correct | 20 ms | 24300 KB | n=2000 |
60 | Correct | 20 ms | 24428 KB | n=2000 |
61 | Correct | 20 ms | 24300 KB | n=2000 |
62 | Correct | 20 ms | 24300 KB | n=2000 |
63 | Correct | 20 ms | 24300 KB | n=2000 |
64 | Correct | 20 ms | 24308 KB | n=2000 |
65 | Correct | 20 ms | 24300 KB | n=2000 |
66 | Correct | 20 ms | 24428 KB | n=2000 |
67 | Correct | 21 ms | 24300 KB | n=2000 |
68 | Correct | 20 ms | 24444 KB | n=2000 |
69 | Correct | 19 ms | 24300 KB | n=2000 |
70 | Correct | 19 ms | 24300 KB | n=2000 |
71 | Correct | 19 ms | 24300 KB | n=2000 |
72 | Correct | 20 ms | 24300 KB | n=2000 |
73 | Correct | 19 ms | 24300 KB | n=2000 |
74 | Correct | 20 ms | 24300 KB | n=1844 |
75 | Correct | 19 ms | 24300 KB | n=2000 |
76 | Correct | 20 ms | 24300 KB | n=2000 |
77 | Correct | 21 ms | 24320 KB | n=2000 |
78 | Correct | 20 ms | 24300 KB | n=2000 |
79 | Correct | 20 ms | 24300 KB | n=2000 |
80 | Correct | 20 ms | 24428 KB | n=2000 |
81 | Correct | 22 ms | 24300 KB | n=2000 |
82 | Correct | 20 ms | 24300 KB | n=2000 |
83 | Correct | 21 ms | 24420 KB | n=2000 |
84 | Correct | 20 ms | 24428 KB | n=2000 |
85 | Correct | 21 ms | 24300 KB | n=2000 |
86 | Correct | 20 ms | 24300 KB | n=2000 |
87 | Correct | 20 ms | 24300 KB | n=2000 |
88 | Correct | 20 ms | 24428 KB | n=2000 |
89 | Correct | 19 ms | 24428 KB | n=2000 |
90 | Correct | 20 ms | 24428 KB | n=2000 |
91 | Correct | 19 ms | 24300 KB | n=2000 |
92 | Correct | 879 ms | 69456 KB | n=200000 |
93 | Correct | 1180 ms | 81900 KB | n=200000 |
94 | Correct | 1136 ms | 87492 KB | n=200000 |
95 | Correct | 823 ms | 73600 KB | n=200000 |
96 | Correct | 832 ms | 73776 KB | n=200000 |
97 | Correct | 1197 ms | 80300 KB | n=200000 |
98 | Correct | 841 ms | 73816 KB | n=200000 |
99 | Correct | 1033 ms | 73960 KB | n=200000 |
100 | Correct | 847 ms | 73692 KB | n=200000 |
101 | Correct | 1110 ms | 89444 KB | n=200000 |
102 | Correct | 492 ms | 74852 KB | n=200000 |
103 | Correct | 496 ms | 74828 KB | n=200000 |
104 | Correct | 500 ms | 74856 KB | n=200000 |
105 | Correct | 518 ms | 75236 KB | n=200000 |
106 | Correct | 506 ms | 75364 KB | n=200000 |
107 | Correct | 513 ms | 75364 KB | n=200000 |
108 | Correct | 920 ms | 73828 KB | n=200000 |
109 | Correct | 916 ms | 73828 KB | n=200000 |
110 | Correct | 942 ms | 73828 KB | n=200000 |
111 | Correct | 888 ms | 73304 KB | n=200000 |
112 | Correct | 1121 ms | 88036 KB | n=200000 |
113 | Correct | 1212 ms | 80488 KB | n=200000 |
114 | Correct | 879 ms | 73300 KB | n=200000 |
115 | Correct | 1252 ms | 76900 KB | n=200000 |
116 | Correct | 773 ms | 73848 KB | n=200000 |
117 | Correct | 1107 ms | 88700 KB | n=200000 |
118 | Correct | 1202 ms | 78564 KB | n=200000 |
119 | Correct | 769 ms | 73812 KB | n=200000 |
120 | Correct | 1074 ms | 88548 KB | n=200000 |
121 | Correct | 1065 ms | 88588 KB | n=200000 |
122 | Correct | 1058 ms | 88932 KB | n=200000 |
123 | Correct | 519 ms | 74980 KB | n=200000 |
124 | Correct | 269 ms | 39268 KB | n=25264 |