# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
166767 | 2019-12-04T03:10:28 Z | abil | Birthday gift (IZhO18_treearray) | C++14 | 4000 ms | 5648 KB |
#include <bits/stdc++.h> #define fr first #define sc second #define pb push_back #define mk make_pair #define all(s) s.begin(),s.end() //#define int long long using namespace std; const int N = (2e5 + 12); const int mod = (1e9 + 7); const int INF = (0x3f3f3f3f); vector<int > g[N]; int up[20][N], tin[N], tout[N], timer, a[N]; void dfs(int v,int pr){ tin[v] = ++timer; up[0][v] = pr; for(int i = 1;i <= 19; i++){ up[i][v] = up[i - 1][up[i - 1][v]]; } for(auto to : g[v]){ if(to != pr){ dfs(to, v); } } tout[v] = ++timer; } bool upper(int a,int b){ return tin[a] <= tin[b] && tout[a] >= tout[b]; } int lca(int a,int b){ if(upper(a, b)){ return a; } if(upper(b, a)){ return b; } for(int i = 19;i >= 0; i--){ if(!upper(up[i][a], b)){ a = up[i][a]; } } a = up[0][a]; return a; } main() { int n, m, q, v, u; cin >> n >> m >> q; for(int i = 1;i <= n - 1; i++){ scanf("%d%d", &v, &u); g[u].pb(v); g[v].pb(u); } for(int i = 1;i <= m; i++){ scanf("%d", &a[i]); } dfs(1, 1); int type, l, r, x; while(q--){ scanf("%d", &type); if(type == 1){ scanf("%d%d", &x, &v); a[x] = v; } else{ scanf("%d%d%d",&l, &r, &v); int xl = -1, xr = -1; for(int i = l;i <= r; i++){ int lc = a[i]; for(int j = i;j <= r; j++){ lc = lca(lc, a[j]); if(lc == v){ xl = i; xr = j; break; } } if(xl != -1){ break; } } printf("%d %d\n", xl, xr); } } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 5112 KB | n=5 |
2 | Correct | 7 ms | 5112 KB | n=100 |
3 | Correct | 7 ms | 5116 KB | n=100 |
4 | Correct | 7 ms | 5112 KB | n=100 |
5 | Correct | 7 ms | 5184 KB | n=100 |
6 | Correct | 9 ms | 5116 KB | n=100 |
7 | Correct | 9 ms | 5112 KB | n=100 |
8 | Correct | 7 ms | 5112 KB | n=100 |
9 | Correct | 7 ms | 5112 KB | n=100 |
10 | Correct | 8 ms | 5112 KB | n=100 |
11 | Correct | 8 ms | 5112 KB | n=100 |
12 | Correct | 7 ms | 5112 KB | n=100 |
13 | Correct | 7 ms | 5112 KB | n=100 |
14 | Correct | 7 ms | 5112 KB | n=100 |
15 | Correct | 7 ms | 5112 KB | n=100 |
16 | Correct | 7 ms | 5112 KB | n=100 |
17 | Correct | 6 ms | 5112 KB | n=100 |
18 | Correct | 7 ms | 5240 KB | n=100 |
19 | Correct | 7 ms | 5112 KB | n=100 |
20 | Correct | 7 ms | 5112 KB | n=100 |
21 | Correct | 6 ms | 5112 KB | n=100 |
22 | Correct | 6 ms | 5112 KB | n=100 |
23 | Correct | 7 ms | 5112 KB | n=100 |
24 | Correct | 7 ms | 5112 KB | n=100 |
25 | Correct | 8 ms | 5240 KB | n=100 |
26 | Correct | 6 ms | 5112 KB | n=12 |
27 | Correct | 8 ms | 5112 KB | n=100 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 5112 KB | n=5 |
2 | Correct | 7 ms | 5112 KB | n=100 |
3 | Correct | 7 ms | 5116 KB | n=100 |
4 | Correct | 7 ms | 5112 KB | n=100 |
5 | Correct | 7 ms | 5184 KB | n=100 |
6 | Correct | 9 ms | 5116 KB | n=100 |
7 | Correct | 9 ms | 5112 KB | n=100 |
8 | Correct | 7 ms | 5112 KB | n=100 |
9 | Correct | 7 ms | 5112 KB | n=100 |
10 | Correct | 8 ms | 5112 KB | n=100 |
11 | Correct | 8 ms | 5112 KB | n=100 |
12 | Correct | 7 ms | 5112 KB | n=100 |
13 | Correct | 7 ms | 5112 KB | n=100 |
14 | Correct | 7 ms | 5112 KB | n=100 |
15 | Correct | 7 ms | 5112 KB | n=100 |
16 | Correct | 7 ms | 5112 KB | n=100 |
17 | Correct | 6 ms | 5112 KB | n=100 |
18 | Correct | 7 ms | 5240 KB | n=100 |
19 | Correct | 7 ms | 5112 KB | n=100 |
20 | Correct | 7 ms | 5112 KB | n=100 |
21 | Correct | 6 ms | 5112 KB | n=100 |
22 | Correct | 6 ms | 5112 KB | n=100 |
23 | Correct | 7 ms | 5112 KB | n=100 |
24 | Correct | 7 ms | 5112 KB | n=100 |
25 | Correct | 8 ms | 5240 KB | n=100 |
26 | Correct | 6 ms | 5112 KB | n=12 |
27 | Correct | 8 ms | 5112 KB | n=100 |
28 | Correct | 8 ms | 5240 KB | n=500 |
29 | Correct | 24 ms | 5240 KB | n=500 |
30 | Correct | 20 ms | 5240 KB | n=500 |
31 | Correct | 22 ms | 5212 KB | n=500 |
32 | Correct | 7 ms | 5240 KB | n=500 |
33 | Correct | 20 ms | 5240 KB | n=500 |
34 | Correct | 7 ms | 5240 KB | n=500 |
35 | Correct | 22 ms | 5240 KB | n=500 |
36 | Correct | 193 ms | 5368 KB | n=500 |
37 | Correct | 191 ms | 5240 KB | n=500 |
38 | Correct | 191 ms | 5248 KB | n=500 |
39 | Correct | 36 ms | 5240 KB | n=500 |
40 | Correct | 34 ms | 5240 KB | n=500 |
41 | Correct | 34 ms | 5240 KB | n=500 |
42 | Correct | 100 ms | 5240 KB | n=500 |
43 | Correct | 100 ms | 5240 KB | n=500 |
44 | Correct | 98 ms | 5240 KB | n=500 |
45 | Correct | 7 ms | 5240 KB | n=500 |
46 | Correct | 22 ms | 5240 KB | n=500 |
47 | Correct | 21 ms | 5240 KB | n=500 |
48 | Correct | 8 ms | 5240 KB | n=500 |
49 | Correct | 20 ms | 5240 KB | n=500 |
50 | Correct | 31 ms | 5240 KB | n=500 |
51 | Correct | 33 ms | 5256 KB | n=500 |
52 | Correct | 35 ms | 5368 KB | n=500 |
53 | Correct | 33 ms | 5260 KB | n=500 |
54 | Correct | 18 ms | 5240 KB | n=500 |
55 | Correct | 9 ms | 5112 KB | n=278 |
56 | Correct | 102 ms | 5240 KB | n=500 |
57 | Correct | 105 ms | 5240 KB | n=500 |
58 | Correct | 90 ms | 5252 KB | n=500 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 5112 KB | n=5 |
2 | Correct | 7 ms | 5112 KB | n=100 |
3 | Correct | 7 ms | 5116 KB | n=100 |
4 | Correct | 7 ms | 5112 KB | n=100 |
5 | Correct | 7 ms | 5184 KB | n=100 |
6 | Correct | 9 ms | 5116 KB | n=100 |
7 | Correct | 9 ms | 5112 KB | n=100 |
8 | Correct | 7 ms | 5112 KB | n=100 |
9 | Correct | 7 ms | 5112 KB | n=100 |
10 | Correct | 8 ms | 5112 KB | n=100 |
11 | Correct | 8 ms | 5112 KB | n=100 |
12 | Correct | 7 ms | 5112 KB | n=100 |
13 | Correct | 7 ms | 5112 KB | n=100 |
14 | Correct | 7 ms | 5112 KB | n=100 |
15 | Correct | 7 ms | 5112 KB | n=100 |
16 | Correct | 7 ms | 5112 KB | n=100 |
17 | Correct | 6 ms | 5112 KB | n=100 |
18 | Correct | 7 ms | 5240 KB | n=100 |
19 | Correct | 7 ms | 5112 KB | n=100 |
20 | Correct | 7 ms | 5112 KB | n=100 |
21 | Correct | 6 ms | 5112 KB | n=100 |
22 | Correct | 6 ms | 5112 KB | n=100 |
23 | Correct | 7 ms | 5112 KB | n=100 |
24 | Correct | 7 ms | 5112 KB | n=100 |
25 | Correct | 8 ms | 5240 KB | n=100 |
26 | Correct | 6 ms | 5112 KB | n=12 |
27 | Correct | 8 ms | 5112 KB | n=100 |
28 | Correct | 8 ms | 5240 KB | n=500 |
29 | Correct | 24 ms | 5240 KB | n=500 |
30 | Correct | 20 ms | 5240 KB | n=500 |
31 | Correct | 22 ms | 5212 KB | n=500 |
32 | Correct | 7 ms | 5240 KB | n=500 |
33 | Correct | 20 ms | 5240 KB | n=500 |
34 | Correct | 7 ms | 5240 KB | n=500 |
35 | Correct | 22 ms | 5240 KB | n=500 |
36 | Correct | 193 ms | 5368 KB | n=500 |
37 | Correct | 191 ms | 5240 KB | n=500 |
38 | Correct | 191 ms | 5248 KB | n=500 |
39 | Correct | 36 ms | 5240 KB | n=500 |
40 | Correct | 34 ms | 5240 KB | n=500 |
41 | Correct | 34 ms | 5240 KB | n=500 |
42 | Correct | 100 ms | 5240 KB | n=500 |
43 | Correct | 100 ms | 5240 KB | n=500 |
44 | Correct | 98 ms | 5240 KB | n=500 |
45 | Correct | 7 ms | 5240 KB | n=500 |
46 | Correct | 22 ms | 5240 KB | n=500 |
47 | Correct | 21 ms | 5240 KB | n=500 |
48 | Correct | 8 ms | 5240 KB | n=500 |
49 | Correct | 20 ms | 5240 KB | n=500 |
50 | Correct | 31 ms | 5240 KB | n=500 |
51 | Correct | 33 ms | 5256 KB | n=500 |
52 | Correct | 35 ms | 5368 KB | n=500 |
53 | Correct | 33 ms | 5260 KB | n=500 |
54 | Correct | 18 ms | 5240 KB | n=500 |
55 | Correct | 9 ms | 5112 KB | n=278 |
56 | Correct | 102 ms | 5240 KB | n=500 |
57 | Correct | 105 ms | 5240 KB | n=500 |
58 | Correct | 90 ms | 5252 KB | n=500 |
59 | Correct | 20 ms | 5496 KB | n=2000 |
60 | Correct | 944 ms | 5624 KB | n=2000 |
61 | Correct | 913 ms | 5496 KB | n=2000 |
62 | Correct | 634 ms | 5496 KB | n=2000 |
63 | Correct | 29 ms | 5496 KB | n=2000 |
64 | Correct | 812 ms | 5624 KB | n=2000 |
65 | Correct | 11 ms | 5496 KB | n=2000 |
66 | Correct | 1031 ms | 5544 KB | n=2000 |
67 | Correct | 57 ms | 5496 KB | n=2000 |
68 | Correct | 852 ms | 5648 KB | n=2000 |
69 | Execution timed out | 4078 ms | 5496 KB | Time limit exceeded |
70 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 5112 KB | n=5 |
2 | Correct | 7 ms | 5112 KB | n=100 |
3 | Correct | 7 ms | 5116 KB | n=100 |
4 | Correct | 7 ms | 5112 KB | n=100 |
5 | Correct | 7 ms | 5184 KB | n=100 |
6 | Correct | 9 ms | 5116 KB | n=100 |
7 | Correct | 9 ms | 5112 KB | n=100 |
8 | Correct | 7 ms | 5112 KB | n=100 |
9 | Correct | 7 ms | 5112 KB | n=100 |
10 | Correct | 8 ms | 5112 KB | n=100 |
11 | Correct | 8 ms | 5112 KB | n=100 |
12 | Correct | 7 ms | 5112 KB | n=100 |
13 | Correct | 7 ms | 5112 KB | n=100 |
14 | Correct | 7 ms | 5112 KB | n=100 |
15 | Correct | 7 ms | 5112 KB | n=100 |
16 | Correct | 7 ms | 5112 KB | n=100 |
17 | Correct | 6 ms | 5112 KB | n=100 |
18 | Correct | 7 ms | 5240 KB | n=100 |
19 | Correct | 7 ms | 5112 KB | n=100 |
20 | Correct | 7 ms | 5112 KB | n=100 |
21 | Correct | 6 ms | 5112 KB | n=100 |
22 | Correct | 6 ms | 5112 KB | n=100 |
23 | Correct | 7 ms | 5112 KB | n=100 |
24 | Correct | 7 ms | 5112 KB | n=100 |
25 | Correct | 8 ms | 5240 KB | n=100 |
26 | Correct | 6 ms | 5112 KB | n=12 |
27 | Correct | 8 ms | 5112 KB | n=100 |
28 | Correct | 8 ms | 5240 KB | n=500 |
29 | Correct | 24 ms | 5240 KB | n=500 |
30 | Correct | 20 ms | 5240 KB | n=500 |
31 | Correct | 22 ms | 5212 KB | n=500 |
32 | Correct | 7 ms | 5240 KB | n=500 |
33 | Correct | 20 ms | 5240 KB | n=500 |
34 | Correct | 7 ms | 5240 KB | n=500 |
35 | Correct | 22 ms | 5240 KB | n=500 |
36 | Correct | 193 ms | 5368 KB | n=500 |
37 | Correct | 191 ms | 5240 KB | n=500 |
38 | Correct | 191 ms | 5248 KB | n=500 |
39 | Correct | 36 ms | 5240 KB | n=500 |
40 | Correct | 34 ms | 5240 KB | n=500 |
41 | Correct | 34 ms | 5240 KB | n=500 |
42 | Correct | 100 ms | 5240 KB | n=500 |
43 | Correct | 100 ms | 5240 KB | n=500 |
44 | Correct | 98 ms | 5240 KB | n=500 |
45 | Correct | 7 ms | 5240 KB | n=500 |
46 | Correct | 22 ms | 5240 KB | n=500 |
47 | Correct | 21 ms | 5240 KB | n=500 |
48 | Correct | 8 ms | 5240 KB | n=500 |
49 | Correct | 20 ms | 5240 KB | n=500 |
50 | Correct | 31 ms | 5240 KB | n=500 |
51 | Correct | 33 ms | 5256 KB | n=500 |
52 | Correct | 35 ms | 5368 KB | n=500 |
53 | Correct | 33 ms | 5260 KB | n=500 |
54 | Correct | 18 ms | 5240 KB | n=500 |
55 | Correct | 9 ms | 5112 KB | n=278 |
56 | Correct | 102 ms | 5240 KB | n=500 |
57 | Correct | 105 ms | 5240 KB | n=500 |
58 | Correct | 90 ms | 5252 KB | n=500 |
59 | Correct | 20 ms | 5496 KB | n=2000 |
60 | Correct | 944 ms | 5624 KB | n=2000 |
61 | Correct | 913 ms | 5496 KB | n=2000 |
62 | Correct | 634 ms | 5496 KB | n=2000 |
63 | Correct | 29 ms | 5496 KB | n=2000 |
64 | Correct | 812 ms | 5624 KB | n=2000 |
65 | Correct | 11 ms | 5496 KB | n=2000 |
66 | Correct | 1031 ms | 5544 KB | n=2000 |
67 | Correct | 57 ms | 5496 KB | n=2000 |
68 | Correct | 852 ms | 5648 KB | n=2000 |
69 | Execution timed out | 4078 ms | 5496 KB | Time limit exceeded |
70 | Halted | 0 ms | 0 KB | - |