# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
40368 | 2018-01-31T12:06:17 Z | model_code | Birthday gift (IZhO18_treearray) | C++11 | 1862 ms | 94912 KB |
#include <iostream> #include <cstdio> #include <cstring> #include <string> #include <vector> #include <cmath> #include <algorithm> #include <set> #include <map> #include <queue> #include <ctime> #define pb push_back #define ll long long #define mp make_pair #define f first #define s second #define pii pair < int, int > #define ull unsigned long long #define pll pair < ll, ll > #define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it ++) #define all(s) s.begin(), s.end() #define sz(a) (int)a.size() const int inf = (1ll << 30) - 1; const int maxn = (int) 1e5 + 10; using namespace std; int p[20][200200]; int lev[200200]; vector<int> g[200200]; int n, k, q; void dfs(int v, int pa){ p[0][v] = pa; for(int i = 1; i < 19; i++){ p[i][v] = p[i-1][p[i-1][v]]; } lev[v] = lev[pa] + 1; for(int i = 0; i < g[v].size(); ++i){ int to = g[v][i]; if(to == pa) continue; dfs(to, v); } } int a[200200]; set<int> S[200200]; set<int> T[200200]; int lca(int u, int v){ if(lev[u] < lev[v]) swap(u, v); for(int i = 18; i >= 0; i--){ if(lev[u] - (1<<i) >= lev[v]) { u = p[i][u]; } } if(u == v) return u; for(int i = 18; i >= 0; i--){ if(p[i][u] != p[i][v]) { u = p[i][u]; v = p[i][v]; } } return p[0][v]; } void solve(){ scanf("%d%d%d", &n, &k, &q); for(int i = 1, x, y; i < n; i++){ scanf("%d%d", &x, &y); g[x].pb(y); g[y].pb(x); } for(int i = 1; i <= k;i++) scanf("%d", &a[i]); dfs(1, 0); for(int i = 1; i <= k;i++) S[a[i]].insert(i); for(int i = 2; i <= k; i++) T[lca(a[i], a[i-1])].insert(i); for(int i = 1; i <= n; i++) { S[i].insert(inf); T[i].insert(inf); } for(int i = 0, ty, l, r, x; i < q; i++){ scanf("%d", &ty); if(ty == 1){ scanf("%d%d", &l, &x); S[a[l]].erase(l); if(l > 1) T[lca(a[l], a[l-1])].erase(l); if(l < k) T[lca(a[l], a[l+1])].erase(l+1); a[l] = x; S[a[l]].insert(l); if(l > 1) T[lca(a[l], a[l-1])].insert(l); if(l < k) T[lca(a[l], a[l+1])].insert(l+1); } else{ scanf("%d%d%d", &l, &r, &x); int d = *S[x].lower_bound(l); int e = *T[x].lower_bound(l+1); if(d <= r){ printf("%d %d\n", d, d); } else if(e <= r){ printf("%d %d\n", e-1, e); } else{ printf("-1 -1\n"); } } } } int main () { #ifdef LOCAL freopen("a.in", "r", stdin); freopen("a.out", "w", stdout); #endif int t=1; //scanf("%d", &t); for(int i=1; i <= t; i++){ //printf("Case #%d\n", i); solve(); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 20 ms | 23924 KB | n=5 |
2 | Correct | 20 ms | 24032 KB | n=100 |
3 | Correct | 20 ms | 24032 KB | n=100 |
4 | Correct | 20 ms | 24032 KB | n=100 |
5 | Correct | 25 ms | 24140 KB | n=100 |
6 | Correct | 20 ms | 24140 KB | n=100 |
7 | Correct | 24 ms | 24140 KB | n=100 |
8 | Correct | 21 ms | 24140 KB | n=100 |
9 | Correct | 21 ms | 24140 KB | n=100 |
10 | Correct | 20 ms | 24140 KB | n=100 |
11 | Correct | 21 ms | 24140 KB | n=100 |
12 | Correct | 20 ms | 24140 KB | n=100 |
13 | Correct | 20 ms | 24140 KB | n=100 |
14 | Correct | 23 ms | 24140 KB | n=100 |
15 | Correct | 21 ms | 24140 KB | n=100 |
16 | Correct | 21 ms | 24212 KB | n=100 |
17 | Correct | 22 ms | 24236 KB | n=100 |
18 | Correct | 23 ms | 24236 KB | n=100 |
19 | Correct | 20 ms | 24236 KB | n=100 |
20 | Correct | 20 ms | 24236 KB | n=100 |
21 | Correct | 21 ms | 24236 KB | n=100 |
22 | Correct | 20 ms | 24236 KB | n=100 |
23 | Correct | 25 ms | 24236 KB | n=100 |
24 | Correct | 21 ms | 24236 KB | n=100 |
25 | Correct | 22 ms | 24236 KB | n=100 |
26 | Correct | 23 ms | 24236 KB | n=12 |
27 | Correct | 19 ms | 24236 KB | n=100 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 20 ms | 23924 KB | n=5 |
2 | Correct | 20 ms | 24032 KB | n=100 |
3 | Correct | 20 ms | 24032 KB | n=100 |
4 | Correct | 20 ms | 24032 KB | n=100 |
5 | Correct | 25 ms | 24140 KB | n=100 |
6 | Correct | 20 ms | 24140 KB | n=100 |
7 | Correct | 24 ms | 24140 KB | n=100 |
8 | Correct | 21 ms | 24140 KB | n=100 |
9 | Correct | 21 ms | 24140 KB | n=100 |
10 | Correct | 20 ms | 24140 KB | n=100 |
11 | Correct | 21 ms | 24140 KB | n=100 |
12 | Correct | 20 ms | 24140 KB | n=100 |
13 | Correct | 20 ms | 24140 KB | n=100 |
14 | Correct | 23 ms | 24140 KB | n=100 |
15 | Correct | 21 ms | 24140 KB | n=100 |
16 | Correct | 21 ms | 24212 KB | n=100 |
17 | Correct | 22 ms | 24236 KB | n=100 |
18 | Correct | 23 ms | 24236 KB | n=100 |
19 | Correct | 20 ms | 24236 KB | n=100 |
20 | Correct | 20 ms | 24236 KB | n=100 |
21 | Correct | 21 ms | 24236 KB | n=100 |
22 | Correct | 20 ms | 24236 KB | n=100 |
23 | Correct | 25 ms | 24236 KB | n=100 |
24 | Correct | 21 ms | 24236 KB | n=100 |
25 | Correct | 22 ms | 24236 KB | n=100 |
26 | Correct | 23 ms | 24236 KB | n=12 |
27 | Correct | 19 ms | 24236 KB | n=100 |
28 | Correct | 21 ms | 24284 KB | n=500 |
29 | Correct | 22 ms | 24284 KB | n=500 |
30 | Correct | 25 ms | 24284 KB | n=500 |
31 | Correct | 22 ms | 24284 KB | n=500 |
32 | Correct | 21 ms | 24284 KB | n=500 |
33 | Correct | 21 ms | 24284 KB | n=500 |
34 | Correct | 23 ms | 24284 KB | n=500 |
35 | Correct | 21 ms | 24284 KB | n=500 |
36 | Correct | 21 ms | 24284 KB | n=500 |
37 | Correct | 21 ms | 24284 KB | n=500 |
38 | Correct | 20 ms | 24284 KB | n=500 |
39 | Correct | 20 ms | 24284 KB | n=500 |
40 | Correct | 21 ms | 24284 KB | n=500 |
41 | Correct | 21 ms | 24284 KB | n=500 |
42 | Correct | 22 ms | 24284 KB | n=500 |
43 | Correct | 22 ms | 24284 KB | n=500 |
44 | Correct | 21 ms | 24284 KB | n=500 |
45 | Correct | 21 ms | 24368 KB | n=500 |
46 | Correct | 21 ms | 24368 KB | n=500 |
47 | Correct | 21 ms | 24368 KB | n=500 |
48 | Correct | 21 ms | 24368 KB | n=500 |
49 | Correct | 22 ms | 24368 KB | n=500 |
50 | Correct | 21 ms | 24368 KB | n=500 |
51 | Correct | 21 ms | 24368 KB | n=500 |
52 | Correct | 26 ms | 24368 KB | n=500 |
53 | Correct | 26 ms | 24368 KB | n=500 |
54 | Correct | 21 ms | 24368 KB | n=500 |
55 | Correct | 20 ms | 24368 KB | n=278 |
56 | Correct | 25 ms | 24368 KB | n=500 |
57 | Correct | 22 ms | 24368 KB | n=500 |
58 | Correct | 21 ms | 24368 KB | n=500 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 20 ms | 23924 KB | n=5 |
2 | Correct | 20 ms | 24032 KB | n=100 |
3 | Correct | 20 ms | 24032 KB | n=100 |
4 | Correct | 20 ms | 24032 KB | n=100 |
5 | Correct | 25 ms | 24140 KB | n=100 |
6 | Correct | 20 ms | 24140 KB | n=100 |
7 | Correct | 24 ms | 24140 KB | n=100 |
8 | Correct | 21 ms | 24140 KB | n=100 |
9 | Correct | 21 ms | 24140 KB | n=100 |
10 | Correct | 20 ms | 24140 KB | n=100 |
11 | Correct | 21 ms | 24140 KB | n=100 |
12 | Correct | 20 ms | 24140 KB | n=100 |
13 | Correct | 20 ms | 24140 KB | n=100 |
14 | Correct | 23 ms | 24140 KB | n=100 |
15 | Correct | 21 ms | 24140 KB | n=100 |
16 | Correct | 21 ms | 24212 KB | n=100 |
17 | Correct | 22 ms | 24236 KB | n=100 |
18 | Correct | 23 ms | 24236 KB | n=100 |
19 | Correct | 20 ms | 24236 KB | n=100 |
20 | Correct | 20 ms | 24236 KB | n=100 |
21 | Correct | 21 ms | 24236 KB | n=100 |
22 | Correct | 20 ms | 24236 KB | n=100 |
23 | Correct | 25 ms | 24236 KB | n=100 |
24 | Correct | 21 ms | 24236 KB | n=100 |
25 | Correct | 22 ms | 24236 KB | n=100 |
26 | Correct | 23 ms | 24236 KB | n=12 |
27 | Correct | 19 ms | 24236 KB | n=100 |
28 | Correct | 21 ms | 24284 KB | n=500 |
29 | Correct | 22 ms | 24284 KB | n=500 |
30 | Correct | 25 ms | 24284 KB | n=500 |
31 | Correct | 22 ms | 24284 KB | n=500 |
32 | Correct | 21 ms | 24284 KB | n=500 |
33 | Correct | 21 ms | 24284 KB | n=500 |
34 | Correct | 23 ms | 24284 KB | n=500 |
35 | Correct | 21 ms | 24284 KB | n=500 |
36 | Correct | 21 ms | 24284 KB | n=500 |
37 | Correct | 21 ms | 24284 KB | n=500 |
38 | Correct | 20 ms | 24284 KB | n=500 |
39 | Correct | 20 ms | 24284 KB | n=500 |
40 | Correct | 21 ms | 24284 KB | n=500 |
41 | Correct | 21 ms | 24284 KB | n=500 |
42 | Correct | 22 ms | 24284 KB | n=500 |
43 | Correct | 22 ms | 24284 KB | n=500 |
44 | Correct | 21 ms | 24284 KB | n=500 |
45 | Correct | 21 ms | 24368 KB | n=500 |
46 | Correct | 21 ms | 24368 KB | n=500 |
47 | Correct | 21 ms | 24368 KB | n=500 |
48 | Correct | 21 ms | 24368 KB | n=500 |
49 | Correct | 22 ms | 24368 KB | n=500 |
50 | Correct | 21 ms | 24368 KB | n=500 |
51 | Correct | 21 ms | 24368 KB | n=500 |
52 | Correct | 26 ms | 24368 KB | n=500 |
53 | Correct | 26 ms | 24368 KB | n=500 |
54 | Correct | 21 ms | 24368 KB | n=500 |
55 | Correct | 20 ms | 24368 KB | n=278 |
56 | Correct | 25 ms | 24368 KB | n=500 |
57 | Correct | 22 ms | 24368 KB | n=500 |
58 | Correct | 21 ms | 24368 KB | n=500 |
59 | Correct | 25 ms | 24792 KB | n=2000 |
60 | Correct | 27 ms | 24928 KB | n=2000 |
61 | Correct | 25 ms | 24928 KB | n=2000 |
62 | Correct | 26 ms | 24928 KB | n=2000 |
63 | Correct | 26 ms | 24928 KB | n=2000 |
64 | Correct | 25 ms | 24928 KB | n=2000 |
65 | Correct | 26 ms | 24928 KB | n=2000 |
66 | Correct | 26 ms | 24928 KB | n=2000 |
67 | Correct | 25 ms | 24928 KB | n=2000 |
68 | Correct | 26 ms | 24928 KB | n=2000 |
69 | Correct | 25 ms | 24928 KB | n=2000 |
70 | Correct | 24 ms | 24928 KB | n=2000 |
71 | Correct | 25 ms | 24928 KB | n=2000 |
72 | Correct | 24 ms | 24928 KB | n=2000 |
73 | Correct | 26 ms | 24928 KB | n=2000 |
74 | Correct | 24 ms | 24928 KB | n=1844 |
75 | Correct | 23 ms | 24928 KB | n=2000 |
76 | Correct | 27 ms | 24928 KB | n=2000 |
77 | Correct | 25 ms | 24928 KB | n=2000 |
78 | Correct | 25 ms | 24928 KB | n=2000 |
79 | Correct | 27 ms | 24928 KB | n=2000 |
80 | Correct | 25 ms | 24928 KB | n=2000 |
81 | Correct | 30 ms | 25028 KB | n=2000 |
82 | Correct | 30 ms | 25028 KB | n=2000 |
83 | Correct | 25 ms | 25028 KB | n=2000 |
84 | Correct | 25 ms | 25028 KB | n=2000 |
85 | Correct | 25 ms | 25028 KB | n=2000 |
86 | Correct | 26 ms | 25028 KB | n=2000 |
87 | Correct | 25 ms | 25028 KB | n=2000 |
88 | Correct | 25 ms | 25028 KB | n=2000 |
89 | Correct | 25 ms | 25028 KB | n=2000 |
90 | Correct | 26 ms | 25028 KB | n=2000 |
91 | Correct | 26 ms | 25028 KB | n=2000 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 20 ms | 23924 KB | n=5 |
2 | Correct | 20 ms | 24032 KB | n=100 |
3 | Correct | 20 ms | 24032 KB | n=100 |
4 | Correct | 20 ms | 24032 KB | n=100 |
5 | Correct | 25 ms | 24140 KB | n=100 |
6 | Correct | 20 ms | 24140 KB | n=100 |
7 | Correct | 24 ms | 24140 KB | n=100 |
8 | Correct | 21 ms | 24140 KB | n=100 |
9 | Correct | 21 ms | 24140 KB | n=100 |
10 | Correct | 20 ms | 24140 KB | n=100 |
11 | Correct | 21 ms | 24140 KB | n=100 |
12 | Correct | 20 ms | 24140 KB | n=100 |
13 | Correct | 20 ms | 24140 KB | n=100 |
14 | Correct | 23 ms | 24140 KB | n=100 |
15 | Correct | 21 ms | 24140 KB | n=100 |
16 | Correct | 21 ms | 24212 KB | n=100 |
17 | Correct | 22 ms | 24236 KB | n=100 |
18 | Correct | 23 ms | 24236 KB | n=100 |
19 | Correct | 20 ms | 24236 KB | n=100 |
20 | Correct | 20 ms | 24236 KB | n=100 |
21 | Correct | 21 ms | 24236 KB | n=100 |
22 | Correct | 20 ms | 24236 KB | n=100 |
23 | Correct | 25 ms | 24236 KB | n=100 |
24 | Correct | 21 ms | 24236 KB | n=100 |
25 | Correct | 22 ms | 24236 KB | n=100 |
26 | Correct | 23 ms | 24236 KB | n=12 |
27 | Correct | 19 ms | 24236 KB | n=100 |
28 | Correct | 21 ms | 24284 KB | n=500 |
29 | Correct | 22 ms | 24284 KB | n=500 |
30 | Correct | 25 ms | 24284 KB | n=500 |
31 | Correct | 22 ms | 24284 KB | n=500 |
32 | Correct | 21 ms | 24284 KB | n=500 |
33 | Correct | 21 ms | 24284 KB | n=500 |
34 | Correct | 23 ms | 24284 KB | n=500 |
35 | Correct | 21 ms | 24284 KB | n=500 |
36 | Correct | 21 ms | 24284 KB | n=500 |
37 | Correct | 21 ms | 24284 KB | n=500 |
38 | Correct | 20 ms | 24284 KB | n=500 |
39 | Correct | 20 ms | 24284 KB | n=500 |
40 | Correct | 21 ms | 24284 KB | n=500 |
41 | Correct | 21 ms | 24284 KB | n=500 |
42 | Correct | 22 ms | 24284 KB | n=500 |
43 | Correct | 22 ms | 24284 KB | n=500 |
44 | Correct | 21 ms | 24284 KB | n=500 |
45 | Correct | 21 ms | 24368 KB | n=500 |
46 | Correct | 21 ms | 24368 KB | n=500 |
47 | Correct | 21 ms | 24368 KB | n=500 |
48 | Correct | 21 ms | 24368 KB | n=500 |
49 | Correct | 22 ms | 24368 KB | n=500 |
50 | Correct | 21 ms | 24368 KB | n=500 |
51 | Correct | 21 ms | 24368 KB | n=500 |
52 | Correct | 26 ms | 24368 KB | n=500 |
53 | Correct | 26 ms | 24368 KB | n=500 |
54 | Correct | 21 ms | 24368 KB | n=500 |
55 | Correct | 20 ms | 24368 KB | n=278 |
56 | Correct | 25 ms | 24368 KB | n=500 |
57 | Correct | 22 ms | 24368 KB | n=500 |
58 | Correct | 21 ms | 24368 KB | n=500 |
59 | Correct | 25 ms | 24792 KB | n=2000 |
60 | Correct | 27 ms | 24928 KB | n=2000 |
61 | Correct | 25 ms | 24928 KB | n=2000 |
62 | Correct | 26 ms | 24928 KB | n=2000 |
63 | Correct | 26 ms | 24928 KB | n=2000 |
64 | Correct | 25 ms | 24928 KB | n=2000 |
65 | Correct | 26 ms | 24928 KB | n=2000 |
66 | Correct | 26 ms | 24928 KB | n=2000 |
67 | Correct | 25 ms | 24928 KB | n=2000 |
68 | Correct | 26 ms | 24928 KB | n=2000 |
69 | Correct | 25 ms | 24928 KB | n=2000 |
70 | Correct | 24 ms | 24928 KB | n=2000 |
71 | Correct | 25 ms | 24928 KB | n=2000 |
72 | Correct | 24 ms | 24928 KB | n=2000 |
73 | Correct | 26 ms | 24928 KB | n=2000 |
74 | Correct | 24 ms | 24928 KB | n=1844 |
75 | Correct | 23 ms | 24928 KB | n=2000 |
76 | Correct | 27 ms | 24928 KB | n=2000 |
77 | Correct | 25 ms | 24928 KB | n=2000 |
78 | Correct | 25 ms | 24928 KB | n=2000 |
79 | Correct | 27 ms | 24928 KB | n=2000 |
80 | Correct | 25 ms | 24928 KB | n=2000 |
81 | Correct | 30 ms | 25028 KB | n=2000 |
82 | Correct | 30 ms | 25028 KB | n=2000 |
83 | Correct | 25 ms | 25028 KB | n=2000 |
84 | Correct | 25 ms | 25028 KB | n=2000 |
85 | Correct | 25 ms | 25028 KB | n=2000 |
86 | Correct | 26 ms | 25028 KB | n=2000 |
87 | Correct | 25 ms | 25028 KB | n=2000 |
88 | Correct | 25 ms | 25028 KB | n=2000 |
89 | Correct | 25 ms | 25028 KB | n=2000 |
90 | Correct | 26 ms | 25028 KB | n=2000 |
91 | Correct | 26 ms | 25028 KB | n=2000 |
92 | Correct | 1329 ms | 86348 KB | n=200000 |
93 | Correct | 1774 ms | 90224 KB | n=200000 |
94 | Correct | 1666 ms | 93524 KB | n=200000 |
95 | Correct | 1329 ms | 93524 KB | n=200000 |
96 | Correct | 1305 ms | 93524 KB | n=200000 |
97 | Correct | 1710 ms | 93524 KB | n=200000 |
98 | Correct | 1315 ms | 93524 KB | n=200000 |
99 | Correct | 1594 ms | 93524 KB | n=200000 |
100 | Correct | 1418 ms | 93524 KB | n=200000 |
101 | Correct | 1632 ms | 94788 KB | n=200000 |
102 | Correct | 752 ms | 94788 KB | n=200000 |
103 | Correct | 715 ms | 94788 KB | n=200000 |
104 | Correct | 715 ms | 94788 KB | n=200000 |
105 | Correct | 719 ms | 94788 KB | n=200000 |
106 | Correct | 735 ms | 94788 KB | n=200000 |
107 | Correct | 706 ms | 94788 KB | n=200000 |
108 | Correct | 1411 ms | 94788 KB | n=200000 |
109 | Correct | 1339 ms | 94788 KB | n=200000 |
110 | Correct | 1464 ms | 94788 KB | n=200000 |
111 | Correct | 1293 ms | 94788 KB | n=200000 |
112 | Correct | 1656 ms | 94788 KB | n=200000 |
113 | Correct | 1789 ms | 94788 KB | n=200000 |
114 | Correct | 1294 ms | 94788 KB | n=200000 |
115 | Correct | 1862 ms | 94788 KB | n=200000 |
116 | Correct | 1290 ms | 94788 KB | n=200000 |
117 | Correct | 1605 ms | 94788 KB | n=200000 |
118 | Correct | 1711 ms | 94788 KB | n=200000 |
119 | Correct | 1206 ms | 94788 KB | n=200000 |
120 | Correct | 1633 ms | 94788 KB | n=200000 |
121 | Correct | 1544 ms | 94788 KB | n=200000 |
122 | Correct | 1475 ms | 94912 KB | n=200000 |
123 | Correct | 747 ms | 94912 KB | n=200000 |
124 | Correct | 333 ms | 94912 KB | n=25264 |