# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
92144 | 2019-01-01T16:31:10 Z | emil_physmath | Birthday gift (IZhO18_treearray) | C++17 | 4000 ms | 55904 KB |
#include <iostream> #include <stdio.h> #include <vector> using namespace std; const int MAXN=200005; int n, l, timer, a[MAXN], tin[MAXN], tout[MAXN], lca[MAXN]; vector<int> nei[MAXN], up[MAXN]; int LCA(int u, int v); void dfs (int u, int p=1); inline bool upper (int u, int v); int main() { int m, q; cin>>n>>m>>q; for (int i=1; i<n; i++) { int u, v; scanf("%d%d", &u, &v); nei[u].push_back(v); nei[v].push_back(u); } l=1; while((1<<l)<=n) l++; for(int i=1; i<=n; i++) up[i].resize(l+1); dfs(1); for (int i=1; i<=m; i++) scanf("%d", a+i); for (int i=1; i<m; i++) lca[i]=LCA(a[i], a[i+1]); int type, pos, L, R, v, ans; while (q--) { scanf("%d", &type); if (type==1) { scanf("%d%d", &pos, &v); a[pos]=v; if (pos-1>=1) lca[pos-1]=LCA(a[pos-1], a[pos]); if (pos+1<=m) lca[pos]=LCA(a[pos], a[pos+1]); } else { scanf("%d%d%d", &L, &R, &v); ans=-1; for (int i=L; i<R; i++) if (lca[i]==v) { ans=i; break; } if (ans==-1) { for (int i=L; i<=R; i++) if (a[i]==v) { ans=i; break; } if (ans==-1) printf("-1 -1\n"); else printf("%d %d\n", ans, ans); } else printf("%d %d\n", ans, ans+1); } } char I; cin >> I; return 0; } void dfs(int u, int p) { tin[u]=++timer; up[u][0]=p; for (int i=1; i<=l; i++) up[u][i]=up[up[u][i-1]][i-1]; for (int i=0; i<nei[u].size(); i++) if (nei[u][i]!=p) dfs(nei[u][i], u); tout[u]=++timer; } inline bool upper(int u, int v) { return tin[u]<=tin[v] && tout[u]>=tout[v]; } int LCA(int u, int v) { if (upper(u, v)) return u; if (upper(v, u)) return v; for (int i=l; i>=0; i--) if (!upper (up[u][i], v)) u=up[u][i]; return up[u][0]; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 9720 KB | n=5 |
2 | Correct | 10 ms | 9720 KB | n=100 |
3 | Correct | 9 ms | 9720 KB | n=100 |
4 | Correct | 10 ms | 9720 KB | n=100 |
5 | Correct | 10 ms | 9720 KB | n=100 |
6 | Correct | 10 ms | 9720 KB | n=100 |
7 | Correct | 10 ms | 9720 KB | n=100 |
8 | Correct | 10 ms | 9724 KB | n=100 |
9 | Correct | 10 ms | 9720 KB | n=100 |
10 | Correct | 10 ms | 9720 KB | n=100 |
11 | Correct | 10 ms | 9724 KB | n=100 |
12 | Correct | 10 ms | 9720 KB | n=100 |
13 | Correct | 10 ms | 9724 KB | n=100 |
14 | Correct | 10 ms | 9720 KB | n=100 |
15 | Correct | 10 ms | 9720 KB | n=100 |
16 | Correct | 10 ms | 9720 KB | n=100 |
17 | Correct | 10 ms | 9720 KB | n=100 |
18 | Correct | 10 ms | 9720 KB | n=100 |
19 | Correct | 9 ms | 9848 KB | n=100 |
20 | Correct | 9 ms | 9720 KB | n=100 |
21 | Correct | 9 ms | 9720 KB | n=100 |
22 | Correct | 9 ms | 9720 KB | n=100 |
23 | Correct | 9 ms | 9720 KB | n=100 |
24 | Correct | 10 ms | 9720 KB | n=100 |
25 | Correct | 8 ms | 9720 KB | n=100 |
26 | Correct | 8 ms | 9720 KB | n=12 |
27 | Correct | 10 ms | 9720 KB | n=100 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 9720 KB | n=5 |
2 | Correct | 10 ms | 9720 KB | n=100 |
3 | Correct | 9 ms | 9720 KB | n=100 |
4 | Correct | 10 ms | 9720 KB | n=100 |
5 | Correct | 10 ms | 9720 KB | n=100 |
6 | Correct | 10 ms | 9720 KB | n=100 |
7 | Correct | 10 ms | 9720 KB | n=100 |
8 | Correct | 10 ms | 9724 KB | n=100 |
9 | Correct | 10 ms | 9720 KB | n=100 |
10 | Correct | 10 ms | 9720 KB | n=100 |
11 | Correct | 10 ms | 9724 KB | n=100 |
12 | Correct | 10 ms | 9720 KB | n=100 |
13 | Correct | 10 ms | 9724 KB | n=100 |
14 | Correct | 10 ms | 9720 KB | n=100 |
15 | Correct | 10 ms | 9720 KB | n=100 |
16 | Correct | 10 ms | 9720 KB | n=100 |
17 | Correct | 10 ms | 9720 KB | n=100 |
18 | Correct | 10 ms | 9720 KB | n=100 |
19 | Correct | 9 ms | 9848 KB | n=100 |
20 | Correct | 9 ms | 9720 KB | n=100 |
21 | Correct | 9 ms | 9720 KB | n=100 |
22 | Correct | 9 ms | 9720 KB | n=100 |
23 | Correct | 9 ms | 9720 KB | n=100 |
24 | Correct | 10 ms | 9720 KB | n=100 |
25 | Correct | 8 ms | 9720 KB | n=100 |
26 | Correct | 8 ms | 9720 KB | n=12 |
27 | Correct | 10 ms | 9720 KB | n=100 |
28 | Correct | 8 ms | 9720 KB | n=500 |
29 | Correct | 10 ms | 9828 KB | n=500 |
30 | Correct | 10 ms | 9720 KB | n=500 |
31 | Correct | 10 ms | 9720 KB | n=500 |
32 | Correct | 10 ms | 9720 KB | n=500 |
33 | Correct | 10 ms | 9848 KB | n=500 |
34 | Correct | 10 ms | 9724 KB | n=500 |
35 | Correct | 10 ms | 9848 KB | n=500 |
36 | Correct | 10 ms | 9720 KB | n=500 |
37 | Correct | 10 ms | 9720 KB | n=500 |
38 | Correct | 10 ms | 9848 KB | n=500 |
39 | Correct | 9 ms | 9848 KB | n=500 |
40 | Correct | 10 ms | 9720 KB | n=500 |
41 | Correct | 10 ms | 9720 KB | n=500 |
42 | Correct | 11 ms | 9848 KB | n=500 |
43 | Correct | 9 ms | 9720 KB | n=500 |
44 | Correct | 11 ms | 9720 KB | n=500 |
45 | Correct | 9 ms | 9848 KB | n=500 |
46 | Correct | 9 ms | 9848 KB | n=500 |
47 | Correct | 9 ms | 9848 KB | n=500 |
48 | Correct | 8 ms | 9720 KB | n=500 |
49 | Correct | 10 ms | 9720 KB | n=500 |
50 | Correct | 9 ms | 9720 KB | n=500 |
51 | Correct | 9 ms | 9848 KB | n=500 |
52 | Correct | 8 ms | 9720 KB | n=500 |
53 | Correct | 10 ms | 9848 KB | n=500 |
54 | Correct | 10 ms | 9848 KB | n=500 |
55 | Correct | 10 ms | 9720 KB | n=278 |
56 | Correct | 10 ms | 9848 KB | n=500 |
57 | Correct | 10 ms | 9720 KB | n=500 |
58 | Correct | 11 ms | 9848 KB | n=500 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 9720 KB | n=5 |
2 | Correct | 10 ms | 9720 KB | n=100 |
3 | Correct | 9 ms | 9720 KB | n=100 |
4 | Correct | 10 ms | 9720 KB | n=100 |
5 | Correct | 10 ms | 9720 KB | n=100 |
6 | Correct | 10 ms | 9720 KB | n=100 |
7 | Correct | 10 ms | 9720 KB | n=100 |
8 | Correct | 10 ms | 9724 KB | n=100 |
9 | Correct | 10 ms | 9720 KB | n=100 |
10 | Correct | 10 ms | 9720 KB | n=100 |
11 | Correct | 10 ms | 9724 KB | n=100 |
12 | Correct | 10 ms | 9720 KB | n=100 |
13 | Correct | 10 ms | 9724 KB | n=100 |
14 | Correct | 10 ms | 9720 KB | n=100 |
15 | Correct | 10 ms | 9720 KB | n=100 |
16 | Correct | 10 ms | 9720 KB | n=100 |
17 | Correct | 10 ms | 9720 KB | n=100 |
18 | Correct | 10 ms | 9720 KB | n=100 |
19 | Correct | 9 ms | 9848 KB | n=100 |
20 | Correct | 9 ms | 9720 KB | n=100 |
21 | Correct | 9 ms | 9720 KB | n=100 |
22 | Correct | 9 ms | 9720 KB | n=100 |
23 | Correct | 9 ms | 9720 KB | n=100 |
24 | Correct | 10 ms | 9720 KB | n=100 |
25 | Correct | 8 ms | 9720 KB | n=100 |
26 | Correct | 8 ms | 9720 KB | n=12 |
27 | Correct | 10 ms | 9720 KB | n=100 |
28 | Correct | 8 ms | 9720 KB | n=500 |
29 | Correct | 10 ms | 9828 KB | n=500 |
30 | Correct | 10 ms | 9720 KB | n=500 |
31 | Correct | 10 ms | 9720 KB | n=500 |
32 | Correct | 10 ms | 9720 KB | n=500 |
33 | Correct | 10 ms | 9848 KB | n=500 |
34 | Correct | 10 ms | 9724 KB | n=500 |
35 | Correct | 10 ms | 9848 KB | n=500 |
36 | Correct | 10 ms | 9720 KB | n=500 |
37 | Correct | 10 ms | 9720 KB | n=500 |
38 | Correct | 10 ms | 9848 KB | n=500 |
39 | Correct | 9 ms | 9848 KB | n=500 |
40 | Correct | 10 ms | 9720 KB | n=500 |
41 | Correct | 10 ms | 9720 KB | n=500 |
42 | Correct | 11 ms | 9848 KB | n=500 |
43 | Correct | 9 ms | 9720 KB | n=500 |
44 | Correct | 11 ms | 9720 KB | n=500 |
45 | Correct | 9 ms | 9848 KB | n=500 |
46 | Correct | 9 ms | 9848 KB | n=500 |
47 | Correct | 9 ms | 9848 KB | n=500 |
48 | Correct | 8 ms | 9720 KB | n=500 |
49 | Correct | 10 ms | 9720 KB | n=500 |
50 | Correct | 9 ms | 9720 KB | n=500 |
51 | Correct | 9 ms | 9848 KB | n=500 |
52 | Correct | 8 ms | 9720 KB | n=500 |
53 | Correct | 10 ms | 9848 KB | n=500 |
54 | Correct | 10 ms | 9848 KB | n=500 |
55 | Correct | 10 ms | 9720 KB | n=278 |
56 | Correct | 10 ms | 9848 KB | n=500 |
57 | Correct | 10 ms | 9720 KB | n=500 |
58 | Correct | 11 ms | 9848 KB | n=500 |
59 | Correct | 10 ms | 9976 KB | n=2000 |
60 | Correct | 13 ms | 10104 KB | n=2000 |
61 | Correct | 13 ms | 9976 KB | n=2000 |
62 | Correct | 13 ms | 9964 KB | n=2000 |
63 | Correct | 12 ms | 9980 KB | n=2000 |
64 | Correct | 13 ms | 10076 KB | n=2000 |
65 | Correct | 32 ms | 9976 KB | n=2000 |
66 | Correct | 11 ms | 10104 KB | n=2000 |
67 | Correct | 11 ms | 9976 KB | n=2000 |
68 | Correct | 11 ms | 10104 KB | n=2000 |
69 | Correct | 13 ms | 9976 KB | n=2000 |
70 | Correct | 14 ms | 9976 KB | n=2000 |
71 | Correct | 14 ms | 9976 KB | n=2000 |
72 | Correct | 13 ms | 9976 KB | n=2000 |
73 | Correct | 13 ms | 9976 KB | n=2000 |
74 | Correct | 12 ms | 9976 KB | n=1844 |
75 | Correct | 14 ms | 9976 KB | n=2000 |
76 | Correct | 13 ms | 9976 KB | n=2000 |
77 | Correct | 13 ms | 9976 KB | n=2000 |
78 | Correct | 13 ms | 9976 KB | n=2000 |
79 | Correct | 12 ms | 9976 KB | n=2000 |
80 | Correct | 12 ms | 10104 KB | n=2000 |
81 | Correct | 13 ms | 9976 KB | n=2000 |
82 | Correct | 10 ms | 9976 KB | n=2000 |
83 | Correct | 12 ms | 9976 KB | n=2000 |
84 | Correct | 13 ms | 9976 KB | n=2000 |
85 | Correct | 12 ms | 9976 KB | n=2000 |
86 | Correct | 13 ms | 9976 KB | n=2000 |
87 | Correct | 12 ms | 9976 KB | n=2000 |
88 | Correct | 15 ms | 10104 KB | n=2000 |
89 | Correct | 15 ms | 10232 KB | n=2000 |
90 | Correct | 13 ms | 10104 KB | n=2000 |
91 | Correct | 13 ms | 9976 KB | n=2000 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 9720 KB | n=5 |
2 | Correct | 10 ms | 9720 KB | n=100 |
3 | Correct | 9 ms | 9720 KB | n=100 |
4 | Correct | 10 ms | 9720 KB | n=100 |
5 | Correct | 10 ms | 9720 KB | n=100 |
6 | Correct | 10 ms | 9720 KB | n=100 |
7 | Correct | 10 ms | 9720 KB | n=100 |
8 | Correct | 10 ms | 9724 KB | n=100 |
9 | Correct | 10 ms | 9720 KB | n=100 |
10 | Correct | 10 ms | 9720 KB | n=100 |
11 | Correct | 10 ms | 9724 KB | n=100 |
12 | Correct | 10 ms | 9720 KB | n=100 |
13 | Correct | 10 ms | 9724 KB | n=100 |
14 | Correct | 10 ms | 9720 KB | n=100 |
15 | Correct | 10 ms | 9720 KB | n=100 |
16 | Correct | 10 ms | 9720 KB | n=100 |
17 | Correct | 10 ms | 9720 KB | n=100 |
18 | Correct | 10 ms | 9720 KB | n=100 |
19 | Correct | 9 ms | 9848 KB | n=100 |
20 | Correct | 9 ms | 9720 KB | n=100 |
21 | Correct | 9 ms | 9720 KB | n=100 |
22 | Correct | 9 ms | 9720 KB | n=100 |
23 | Correct | 9 ms | 9720 KB | n=100 |
24 | Correct | 10 ms | 9720 KB | n=100 |
25 | Correct | 8 ms | 9720 KB | n=100 |
26 | Correct | 8 ms | 9720 KB | n=12 |
27 | Correct | 10 ms | 9720 KB | n=100 |
28 | Correct | 8 ms | 9720 KB | n=500 |
29 | Correct | 10 ms | 9828 KB | n=500 |
30 | Correct | 10 ms | 9720 KB | n=500 |
31 | Correct | 10 ms | 9720 KB | n=500 |
32 | Correct | 10 ms | 9720 KB | n=500 |
33 | Correct | 10 ms | 9848 KB | n=500 |
34 | Correct | 10 ms | 9724 KB | n=500 |
35 | Correct | 10 ms | 9848 KB | n=500 |
36 | Correct | 10 ms | 9720 KB | n=500 |
37 | Correct | 10 ms | 9720 KB | n=500 |
38 | Correct | 10 ms | 9848 KB | n=500 |
39 | Correct | 9 ms | 9848 KB | n=500 |
40 | Correct | 10 ms | 9720 KB | n=500 |
41 | Correct | 10 ms | 9720 KB | n=500 |
42 | Correct | 11 ms | 9848 KB | n=500 |
43 | Correct | 9 ms | 9720 KB | n=500 |
44 | Correct | 11 ms | 9720 KB | n=500 |
45 | Correct | 9 ms | 9848 KB | n=500 |
46 | Correct | 9 ms | 9848 KB | n=500 |
47 | Correct | 9 ms | 9848 KB | n=500 |
48 | Correct | 8 ms | 9720 KB | n=500 |
49 | Correct | 10 ms | 9720 KB | n=500 |
50 | Correct | 9 ms | 9720 KB | n=500 |
51 | Correct | 9 ms | 9848 KB | n=500 |
52 | Correct | 8 ms | 9720 KB | n=500 |
53 | Correct | 10 ms | 9848 KB | n=500 |
54 | Correct | 10 ms | 9848 KB | n=500 |
55 | Correct | 10 ms | 9720 KB | n=278 |
56 | Correct | 10 ms | 9848 KB | n=500 |
57 | Correct | 10 ms | 9720 KB | n=500 |
58 | Correct | 11 ms | 9848 KB | n=500 |
59 | Correct | 10 ms | 9976 KB | n=2000 |
60 | Correct | 13 ms | 10104 KB | n=2000 |
61 | Correct | 13 ms | 9976 KB | n=2000 |
62 | Correct | 13 ms | 9964 KB | n=2000 |
63 | Correct | 12 ms | 9980 KB | n=2000 |
64 | Correct | 13 ms | 10076 KB | n=2000 |
65 | Correct | 32 ms | 9976 KB | n=2000 |
66 | Correct | 11 ms | 10104 KB | n=2000 |
67 | Correct | 11 ms | 9976 KB | n=2000 |
68 | Correct | 11 ms | 10104 KB | n=2000 |
69 | Correct | 13 ms | 9976 KB | n=2000 |
70 | Correct | 14 ms | 9976 KB | n=2000 |
71 | Correct | 14 ms | 9976 KB | n=2000 |
72 | Correct | 13 ms | 9976 KB | n=2000 |
73 | Correct | 13 ms | 9976 KB | n=2000 |
74 | Correct | 12 ms | 9976 KB | n=1844 |
75 | Correct | 14 ms | 9976 KB | n=2000 |
76 | Correct | 13 ms | 9976 KB | n=2000 |
77 | Correct | 13 ms | 9976 KB | n=2000 |
78 | Correct | 13 ms | 9976 KB | n=2000 |
79 | Correct | 12 ms | 9976 KB | n=2000 |
80 | Correct | 12 ms | 10104 KB | n=2000 |
81 | Correct | 13 ms | 9976 KB | n=2000 |
82 | Correct | 10 ms | 9976 KB | n=2000 |
83 | Correct | 12 ms | 9976 KB | n=2000 |
84 | Correct | 13 ms | 9976 KB | n=2000 |
85 | Correct | 12 ms | 9976 KB | n=2000 |
86 | Correct | 13 ms | 9976 KB | n=2000 |
87 | Correct | 12 ms | 9976 KB | n=2000 |
88 | Correct | 15 ms | 10104 KB | n=2000 |
89 | Correct | 15 ms | 10232 KB | n=2000 |
90 | Correct | 13 ms | 10104 KB | n=2000 |
91 | Correct | 13 ms | 9976 KB | n=2000 |
92 | Correct | 489 ms | 46428 KB | n=200000 |
93 | Correct | 3321 ms | 51532 KB | n=200000 |
94 | Correct | 3501 ms | 54776 KB | n=200000 |
95 | Correct | 405 ms | 46060 KB | n=200000 |
96 | Correct | 383 ms | 46056 KB | n=200000 |
97 | Correct | 2825 ms | 50568 KB | n=200000 |
98 | Correct | 587 ms | 46184 KB | n=200000 |
99 | Correct | 469 ms | 46348 KB | n=200000 |
100 | Correct | 425 ms | 46252 KB | n=200000 |
101 | Correct | 3590 ms | 55904 KB | n=200000 |
102 | Execution timed out | 4027 ms | 43828 KB | Time limit exceeded |
103 | Halted | 0 ms | 0 KB | - |