# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
133834 | 2019-07-21T13:48:39 Z | Kastanda | Birthday gift (IZhO18_treearray) | C++11 | 26 ms | 23928 KB |
// ItnoE #include<bits/stdc++.h> using namespace std; const int N = 200005, LG = 18; int n, m, q, A[N], H[N], P[N][LG]; vector < int > Adj[N]; set < int > S[N], T[N]; void DFS(int v, int p) { for (int i = 1; i < LG; i ++) P[v][i] = P[P[v][i - 1]][i - 1]; for (int u : Adj[v]) if (u != p) { H[u] = H[v] + 1; P[u][0] = v; DFS(u, v); } } inline int LCA(int v, int u) { if (H[v] < H[u]) return (LCA(u, v)); for (int i = 0; i < LG; i ++) if ((H[v] - H[u]) & (1 << i)) v = P[v][i]; if (v == u) return (v); for (int i = LG - 1; ~ i; i --) if (P[v][i] != P[u][i]) v = P[v][i], u = P[u][i]; return (P[v][0]); } int main() { scanf("%d%d%d", &n, &m, &q); for (int i = 1; i < n; i ++) { int v, u; scanf("%d%d", &v, &u); Adj[v].push_back(u); Adj[u].push_back(v); } DFS(1, 0); for (int i = 1; i <= m; i ++) { scanf("%d", &A[i]); S[A[i]].insert(i); if (i > 1) T[LCA(A[i], A[i - 1])].insert(i - 1); } for (; q; q --) { int tp, l, r, v; scanf("%d", &tp); if (tp == 1) { scanf("%d%d", &l, &v); S[A[l]].erase(l); if (l > 1) T[LCA(A[l], A[l - 1])].erase(l - 1); if (l < m) T[LCA(A[l], A[l + 1])].erase(l); A[l] = v; S[A[l]].insert(l); if (l > 1) T[LCA(A[l], A[l - 1])].insert(l - 1); if (l < m) T[LCA(A[l], A[l + 1])].insert(l); } else { scanf("%d%d%d", &l, &r, &v); auto it = S[v].lower_bound(l); if (it != S[v].end() && (* it) <= r) { printf("%d %d\n", * it, * it); continue; } it = T[v].lower_bound(l); if (it != T[v].end() && (* it) <= r) printf("%d %d\n", * it, (* it) + 1); else printf("-1 -1\n"); } } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 23928 KB | n=5 |
2 | Correct | 23 ms | 23800 KB | n=100 |
3 | Correct | 24 ms | 23800 KB | n=100 |
4 | Correct | 24 ms | 23800 KB | n=100 |
5 | Correct | 24 ms | 23800 KB | n=100 |
6 | Correct | 23 ms | 23800 KB | n=100 |
7 | Correct | 24 ms | 23800 KB | n=100 |
8 | Correct | 23 ms | 23800 KB | n=100 |
9 | Correct | 23 ms | 23800 KB | n=100 |
10 | Correct | 24 ms | 23928 KB | n=100 |
11 | Correct | 26 ms | 23800 KB | n=100 |
12 | Incorrect | 24 ms | 23800 KB | Wrong output format. |
13 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 23928 KB | n=5 |
2 | Correct | 23 ms | 23800 KB | n=100 |
3 | Correct | 24 ms | 23800 KB | n=100 |
4 | Correct | 24 ms | 23800 KB | n=100 |
5 | Correct | 24 ms | 23800 KB | n=100 |
6 | Correct | 23 ms | 23800 KB | n=100 |
7 | Correct | 24 ms | 23800 KB | n=100 |
8 | Correct | 23 ms | 23800 KB | n=100 |
9 | Correct | 23 ms | 23800 KB | n=100 |
10 | Correct | 24 ms | 23928 KB | n=100 |
11 | Correct | 26 ms | 23800 KB | n=100 |
12 | Incorrect | 24 ms | 23800 KB | Wrong output format. |
13 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 23928 KB | n=5 |
2 | Correct | 23 ms | 23800 KB | n=100 |
3 | Correct | 24 ms | 23800 KB | n=100 |
4 | Correct | 24 ms | 23800 KB | n=100 |
5 | Correct | 24 ms | 23800 KB | n=100 |
6 | Correct | 23 ms | 23800 KB | n=100 |
7 | Correct | 24 ms | 23800 KB | n=100 |
8 | Correct | 23 ms | 23800 KB | n=100 |
9 | Correct | 23 ms | 23800 KB | n=100 |
10 | Correct | 24 ms | 23928 KB | n=100 |
11 | Correct | 26 ms | 23800 KB | n=100 |
12 | Incorrect | 24 ms | 23800 KB | Wrong output format. |
13 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 23928 KB | n=5 |
2 | Correct | 23 ms | 23800 KB | n=100 |
3 | Correct | 24 ms | 23800 KB | n=100 |
4 | Correct | 24 ms | 23800 KB | n=100 |
5 | Correct | 24 ms | 23800 KB | n=100 |
6 | Correct | 23 ms | 23800 KB | n=100 |
7 | Correct | 24 ms | 23800 KB | n=100 |
8 | Correct | 23 ms | 23800 KB | n=100 |
9 | Correct | 23 ms | 23800 KB | n=100 |
10 | Correct | 24 ms | 23928 KB | n=100 |
11 | Correct | 26 ms | 23800 KB | n=100 |
12 | Incorrect | 24 ms | 23800 KB | Wrong output format. |
13 | Halted | 0 ms | 0 KB | - |