# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
91894 | 2018-12-31T10:12:58 Z | emil_physmath | Birthday gift (IZhO18_treearray) | C++17 | 4000 ms | 46072 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]; 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); int type, pos, L, R, v, ans; while (q--) { scanf("%d", &type); if (type==1) { scanf("%d%d", &pos, &v); a[pos]=v; } else { scanf("%d%d%d", &L, &R, &v); ans=-1; for (int i=L; i<R; i++) if (upper(v, a[i]) && upper(v, a[i+1]) && lca(a[i], a[i+1])==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 | 9 ms | 9720 KB | n=5 |
2 | Correct | 10 ms | 9720 KB | n=100 |
3 | Correct | 10 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 | 8 ms | 9720 KB | n=100 |
9 | Correct | 11 ms | 9720 KB | n=100 |
10 | Correct | 10 ms | 9720 KB | n=100 |
11 | Correct | 9 ms | 9720 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 | 9716 KB | n=100 |
16 | Correct | 10 ms | 9720 KB | n=100 |
17 | Correct | 10 ms | 9720 KB | n=100 |
18 | Correct | 10 ms | 9688 KB | n=100 |
19 | Correct | 9 ms | 9720 KB | n=100 |
20 | Correct | 10 ms | 9720 KB | n=100 |
21 | Correct | 10 ms | 9720 KB | n=100 |
22 | Correct | 10 ms | 9720 KB | n=100 |
23 | Correct | 12 ms | 9720 KB | n=100 |
24 | Correct | 8 ms | 9720 KB | n=100 |
25 | Correct | 9 ms | 9720 KB | n=100 |
26 | Correct | 8 ms | 9720 KB | n=12 |
27 | Correct | 9 ms | 9720 KB | n=100 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 9720 KB | n=5 |
2 | Correct | 10 ms | 9720 KB | n=100 |
3 | Correct | 10 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 | 8 ms | 9720 KB | n=100 |
9 | Correct | 11 ms | 9720 KB | n=100 |
10 | Correct | 10 ms | 9720 KB | n=100 |
11 | Correct | 9 ms | 9720 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 | 9716 KB | n=100 |
16 | Correct | 10 ms | 9720 KB | n=100 |
17 | Correct | 10 ms | 9720 KB | n=100 |
18 | Correct | 10 ms | 9688 KB | n=100 |
19 | Correct | 9 ms | 9720 KB | n=100 |
20 | Correct | 10 ms | 9720 KB | n=100 |
21 | Correct | 10 ms | 9720 KB | n=100 |
22 | Correct | 10 ms | 9720 KB | n=100 |
23 | Correct | 12 ms | 9720 KB | n=100 |
24 | Correct | 8 ms | 9720 KB | n=100 |
25 | Correct | 9 ms | 9720 KB | n=100 |
26 | Correct | 8 ms | 9720 KB | n=12 |
27 | Correct | 9 ms | 9720 KB | n=100 |
28 | Correct | 10 ms | 9820 KB | n=500 |
29 | Correct | 10 ms | 9848 KB | n=500 |
30 | Correct | 10 ms | 9848 KB | n=500 |
31 | Correct | 10 ms | 9848 KB | n=500 |
32 | Correct | 10 ms | 9848 KB | n=500 |
33 | Correct | 10 ms | 9848 KB | n=500 |
34 | Correct | 10 ms | 9720 KB | n=500 |
35 | Correct | 10 ms | 9720 KB | n=500 |
36 | Correct | 10 ms | 9720 KB | n=500 |
37 | Correct | 10 ms | 9720 KB | n=500 |
38 | Correct | 11 ms | 9892 KB | n=500 |
39 | Correct | 10 ms | 9720 KB | n=500 |
40 | Correct | 10 ms | 9852 KB | n=500 |
41 | Correct | 10 ms | 9720 KB | n=500 |
42 | Correct | 11 ms | 9848 KB | n=500 |
43 | Correct | 10 ms | 9720 KB | n=500 |
44 | Correct | 10 ms | 9720 KB | n=500 |
45 | Correct | 10 ms | 9720 KB | n=500 |
46 | Correct | 10 ms | 9848 KB | n=500 |
47 | Correct | 10 ms | 9848 KB | n=500 |
48 | Correct | 10 ms | 9848 KB | n=500 |
49 | Correct | 10 ms | 9848 KB | n=500 |
50 | Correct | 11 ms | 9720 KB | n=500 |
51 | Correct | 11 ms | 9720 KB | n=500 |
52 | Correct | 11 ms | 9848 KB | n=500 |
53 | Correct | 11 ms | 9720 KB | n=500 |
54 | Correct | 11 ms | 9720 KB | n=500 |
55 | Correct | 10 ms | 9720 KB | n=278 |
56 | Correct | 11 ms | 9848 KB | n=500 |
57 | Correct | 11 ms | 9720 KB | n=500 |
58 | Correct | 12 ms | 9848 KB | n=500 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 9720 KB | n=5 |
2 | Correct | 10 ms | 9720 KB | n=100 |
3 | Correct | 10 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 | 8 ms | 9720 KB | n=100 |
9 | Correct | 11 ms | 9720 KB | n=100 |
10 | Correct | 10 ms | 9720 KB | n=100 |
11 | Correct | 9 ms | 9720 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 | 9716 KB | n=100 |
16 | Correct | 10 ms | 9720 KB | n=100 |
17 | Correct | 10 ms | 9720 KB | n=100 |
18 | Correct | 10 ms | 9688 KB | n=100 |
19 | Correct | 9 ms | 9720 KB | n=100 |
20 | Correct | 10 ms | 9720 KB | n=100 |
21 | Correct | 10 ms | 9720 KB | n=100 |
22 | Correct | 10 ms | 9720 KB | n=100 |
23 | Correct | 12 ms | 9720 KB | n=100 |
24 | Correct | 8 ms | 9720 KB | n=100 |
25 | Correct | 9 ms | 9720 KB | n=100 |
26 | Correct | 8 ms | 9720 KB | n=12 |
27 | Correct | 9 ms | 9720 KB | n=100 |
28 | Correct | 10 ms | 9820 KB | n=500 |
29 | Correct | 10 ms | 9848 KB | n=500 |
30 | Correct | 10 ms | 9848 KB | n=500 |
31 | Correct | 10 ms | 9848 KB | n=500 |
32 | Correct | 10 ms | 9848 KB | n=500 |
33 | Correct | 10 ms | 9848 KB | n=500 |
34 | Correct | 10 ms | 9720 KB | n=500 |
35 | Correct | 10 ms | 9720 KB | n=500 |
36 | Correct | 10 ms | 9720 KB | n=500 |
37 | Correct | 10 ms | 9720 KB | n=500 |
38 | Correct | 11 ms | 9892 KB | n=500 |
39 | Correct | 10 ms | 9720 KB | n=500 |
40 | Correct | 10 ms | 9852 KB | n=500 |
41 | Correct | 10 ms | 9720 KB | n=500 |
42 | Correct | 11 ms | 9848 KB | n=500 |
43 | Correct | 10 ms | 9720 KB | n=500 |
44 | Correct | 10 ms | 9720 KB | n=500 |
45 | Correct | 10 ms | 9720 KB | n=500 |
46 | Correct | 10 ms | 9848 KB | n=500 |
47 | Correct | 10 ms | 9848 KB | n=500 |
48 | Correct | 10 ms | 9848 KB | n=500 |
49 | Correct | 10 ms | 9848 KB | n=500 |
50 | Correct | 11 ms | 9720 KB | n=500 |
51 | Correct | 11 ms | 9720 KB | n=500 |
52 | Correct | 11 ms | 9848 KB | n=500 |
53 | Correct | 11 ms | 9720 KB | n=500 |
54 | Correct | 11 ms | 9720 KB | n=500 |
55 | Correct | 10 ms | 9720 KB | n=278 |
56 | Correct | 11 ms | 9848 KB | n=500 |
57 | Correct | 11 ms | 9720 KB | n=500 |
58 | Correct | 12 ms | 9848 KB | n=500 |
59 | Correct | 13 ms | 9976 KB | n=2000 |
60 | Correct | 16 ms | 9976 KB | n=2000 |
61 | Correct | 20 ms | 9980 KB | n=2000 |
62 | Correct | 19 ms | 9980 KB | n=2000 |
63 | Correct | 13 ms | 9976 KB | n=2000 |
64 | Correct | 20 ms | 9976 KB | n=2000 |
65 | Correct | 12 ms | 9976 KB | n=2000 |
66 | Correct | 19 ms | 9976 KB | n=2000 |
67 | Correct | 12 ms | 9976 KB | n=2000 |
68 | Correct | 20 ms | 9976 KB | n=2000 |
69 | Correct | 16 ms | 9976 KB | n=2000 |
70 | Correct | 14 ms | 9976 KB | n=2000 |
71 | Correct | 14 ms | 9976 KB | n=2000 |
72 | Correct | 14 ms | 9976 KB | n=2000 |
73 | Correct | 14 ms | 9976 KB | n=2000 |
74 | Correct | 12 ms | 9976 KB | n=1844 |
75 | Correct | 14 ms | 9976 KB | n=2000 |
76 | Correct | 17 ms | 9976 KB | n=2000 |
77 | Correct | 17 ms | 9976 KB | n=2000 |
78 | Correct | 17 ms | 9976 KB | n=2000 |
79 | Correct | 12 ms | 9976 KB | n=2000 |
80 | Correct | 16 ms | 9976 KB | n=2000 |
81 | Correct | 18 ms | 9976 KB | n=2000 |
82 | Correct | 14 ms | 9964 KB | n=2000 |
83 | Correct | 18 ms | 9976 KB | n=2000 |
84 | Correct | 16 ms | 9976 KB | n=2000 |
85 | Correct | 20 ms | 9976 KB | n=2000 |
86 | Correct | 20 ms | 9976 KB | n=2000 |
87 | Correct | 14 ms | 9976 KB | n=2000 |
88 | Correct | 29 ms | 10076 KB | n=2000 |
89 | Correct | 28 ms | 10104 KB | n=2000 |
90 | Correct | 20 ms | 9976 KB | n=2000 |
91 | Correct | 20 ms | 9976 KB | n=2000 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 9720 KB | n=5 |
2 | Correct | 10 ms | 9720 KB | n=100 |
3 | Correct | 10 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 | 8 ms | 9720 KB | n=100 |
9 | Correct | 11 ms | 9720 KB | n=100 |
10 | Correct | 10 ms | 9720 KB | n=100 |
11 | Correct | 9 ms | 9720 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 | 9716 KB | n=100 |
16 | Correct | 10 ms | 9720 KB | n=100 |
17 | Correct | 10 ms | 9720 KB | n=100 |
18 | Correct | 10 ms | 9688 KB | n=100 |
19 | Correct | 9 ms | 9720 KB | n=100 |
20 | Correct | 10 ms | 9720 KB | n=100 |
21 | Correct | 10 ms | 9720 KB | n=100 |
22 | Correct | 10 ms | 9720 KB | n=100 |
23 | Correct | 12 ms | 9720 KB | n=100 |
24 | Correct | 8 ms | 9720 KB | n=100 |
25 | Correct | 9 ms | 9720 KB | n=100 |
26 | Correct | 8 ms | 9720 KB | n=12 |
27 | Correct | 9 ms | 9720 KB | n=100 |
28 | Correct | 10 ms | 9820 KB | n=500 |
29 | Correct | 10 ms | 9848 KB | n=500 |
30 | Correct | 10 ms | 9848 KB | n=500 |
31 | Correct | 10 ms | 9848 KB | n=500 |
32 | Correct | 10 ms | 9848 KB | n=500 |
33 | Correct | 10 ms | 9848 KB | n=500 |
34 | Correct | 10 ms | 9720 KB | n=500 |
35 | Correct | 10 ms | 9720 KB | n=500 |
36 | Correct | 10 ms | 9720 KB | n=500 |
37 | Correct | 10 ms | 9720 KB | n=500 |
38 | Correct | 11 ms | 9892 KB | n=500 |
39 | Correct | 10 ms | 9720 KB | n=500 |
40 | Correct | 10 ms | 9852 KB | n=500 |
41 | Correct | 10 ms | 9720 KB | n=500 |
42 | Correct | 11 ms | 9848 KB | n=500 |
43 | Correct | 10 ms | 9720 KB | n=500 |
44 | Correct | 10 ms | 9720 KB | n=500 |
45 | Correct | 10 ms | 9720 KB | n=500 |
46 | Correct | 10 ms | 9848 KB | n=500 |
47 | Correct | 10 ms | 9848 KB | n=500 |
48 | Correct | 10 ms | 9848 KB | n=500 |
49 | Correct | 10 ms | 9848 KB | n=500 |
50 | Correct | 11 ms | 9720 KB | n=500 |
51 | Correct | 11 ms | 9720 KB | n=500 |
52 | Correct | 11 ms | 9848 KB | n=500 |
53 | Correct | 11 ms | 9720 KB | n=500 |
54 | Correct | 11 ms | 9720 KB | n=500 |
55 | Correct | 10 ms | 9720 KB | n=278 |
56 | Correct | 11 ms | 9848 KB | n=500 |
57 | Correct | 11 ms | 9720 KB | n=500 |
58 | Correct | 12 ms | 9848 KB | n=500 |
59 | Correct | 13 ms | 9976 KB | n=2000 |
60 | Correct | 16 ms | 9976 KB | n=2000 |
61 | Correct | 20 ms | 9980 KB | n=2000 |
62 | Correct | 19 ms | 9980 KB | n=2000 |
63 | Correct | 13 ms | 9976 KB | n=2000 |
64 | Correct | 20 ms | 9976 KB | n=2000 |
65 | Correct | 12 ms | 9976 KB | n=2000 |
66 | Correct | 19 ms | 9976 KB | n=2000 |
67 | Correct | 12 ms | 9976 KB | n=2000 |
68 | Correct | 20 ms | 9976 KB | n=2000 |
69 | Correct | 16 ms | 9976 KB | n=2000 |
70 | Correct | 14 ms | 9976 KB | n=2000 |
71 | Correct | 14 ms | 9976 KB | n=2000 |
72 | Correct | 14 ms | 9976 KB | n=2000 |
73 | Correct | 14 ms | 9976 KB | n=2000 |
74 | Correct | 12 ms | 9976 KB | n=1844 |
75 | Correct | 14 ms | 9976 KB | n=2000 |
76 | Correct | 17 ms | 9976 KB | n=2000 |
77 | Correct | 17 ms | 9976 KB | n=2000 |
78 | Correct | 17 ms | 9976 KB | n=2000 |
79 | Correct | 12 ms | 9976 KB | n=2000 |
80 | Correct | 16 ms | 9976 KB | n=2000 |
81 | Correct | 18 ms | 9976 KB | n=2000 |
82 | Correct | 14 ms | 9964 KB | n=2000 |
83 | Correct | 18 ms | 9976 KB | n=2000 |
84 | Correct | 16 ms | 9976 KB | n=2000 |
85 | Correct | 20 ms | 9976 KB | n=2000 |
86 | Correct | 20 ms | 9976 KB | n=2000 |
87 | Correct | 14 ms | 9976 KB | n=2000 |
88 | Correct | 29 ms | 10076 KB | n=2000 |
89 | Correct | 28 ms | 10104 KB | n=2000 |
90 | Correct | 20 ms | 9976 KB | n=2000 |
91 | Correct | 20 ms | 9976 KB | n=2000 |
92 | Correct | 419 ms | 45556 KB | n=200000 |
93 | Execution timed out | 4062 ms | 46072 KB | Time limit exceeded |
94 | Halted | 0 ms | 0 KB | - |