# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
383667 | 2021-03-30T13:45:14 Z | BartolM | Birthday gift (IZhO18_treearray) | C++17 | 1468 ms | 82640 KB |
#include <bits/stdc++.h> using namespace std; #define X first #define Y second #define mp make_pair #define pb push_back typedef long long ll; typedef pair <int, int> pii; typedef pair <int, pii> pip; typedef pair <pii, int> ppi; typedef pair <ll, ll> pll; const int INF=0x3f3f3f3f; const int N=2e5+5; const int LOG=18; int n, m, q; int p[N]; vector <int> ls[N]; int dep[N], par[LOG][N]; set <int> S[N], gdje[N]; void build() { for (int i=1; i<LOG; ++i) { for (int j=1; j<=n; ++j) { par[i][j]=par[i-1][par[i-1][j]]; } } } int lca(int x, int y) { if (dep[x]<dep[y]) swap(x, y); for (int i=LOG-1; i>=0; --i) { if (dep[x]-(1<<i)>=dep[y]) x=par[i][x]; } if (x==y) return x; for (int i=LOG-1; i>=0; --i) { if (par[i][x]!=par[i][y]) x=par[i][x], y=par[i][y]; } return par[0][x]; } void dfs(int node, int rod) { par[0][node]=rod; dep[node]=dep[rod]+1; for (int sus:ls[node]) if (sus!=rod) dfs(sus, node); } void solve() { dfs(1, 0); build(); for (int i=0; i<m-1; ++i) S[lca(p[i], p[i+1])].insert(i); for (int i=0; i<m; ++i) gdje[p[i]].insert(i); for (int i=0; i<q; ++i) { int br, l, r, x; scanf("%d", &br); if (br==1) { scanf("%d %d", &l, &x); l--; if (l) { S[lca(p[l], p[l-1])].erase(l-1); S[lca(p[l-1], x)].insert(l-1); } if (l<m-1) { S[lca(p[l], p[l+1])].erase(l); S[lca(x, p[l+1])].insert(l); } gdje[p[l]].erase(l); gdje[x].insert(l); p[l]=x; } else { scanf("%d %d %d", &l, &r, &x); l--; r--; auto it=gdje[x].lower_bound(l); if (it!=gdje[x].end() && (*it)<=r) { printf("%d %d\n", (*it)+1, (*it)+1); continue; } it=S[x].lower_bound(l); if (it==S[x].end() || (*it)>=r) printf("-1 -1\n"); else printf("%d %d\n", (*it)+1, (*it)+2); } } } void load() { scanf("%d %d %d", &n, &m, &q); for (int i=0; i<n-1; ++i) { int a, b; scanf("%d %d", &a, &b); ls[a].pb(b); ls[b].pb(a); } for (int i=0; i<m; ++i) scanf("%d", &p[i]); } int main() { load(); solve(); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 17 ms | 23936 KB | n=5 |
2 | Correct | 17 ms | 23916 KB | n=100 |
3 | Correct | 17 ms | 23916 KB | n=100 |
4 | Correct | 17 ms | 23936 KB | n=100 |
5 | Correct | 17 ms | 23916 KB | n=100 |
6 | Correct | 18 ms | 23916 KB | n=100 |
7 | Correct | 17 ms | 23916 KB | n=100 |
8 | Correct | 17 ms | 23916 KB | n=100 |
9 | Correct | 17 ms | 23916 KB | n=100 |
10 | Correct | 17 ms | 23916 KB | n=100 |
11 | Correct | 17 ms | 23916 KB | n=100 |
12 | Correct | 17 ms | 23916 KB | n=100 |
13 | Correct | 19 ms | 23916 KB | n=100 |
14 | Correct | 20 ms | 23916 KB | n=100 |
15 | Correct | 17 ms | 24064 KB | n=100 |
16 | Correct | 17 ms | 23916 KB | n=100 |
17 | Correct | 17 ms | 23916 KB | n=100 |
18 | Correct | 18 ms | 23916 KB | n=100 |
19 | Correct | 17 ms | 23916 KB | n=100 |
20 | Correct | 17 ms | 23916 KB | n=100 |
21 | Correct | 17 ms | 23916 KB | n=100 |
22 | Correct | 17 ms | 23916 KB | n=100 |
23 | Correct | 17 ms | 23916 KB | n=100 |
24 | Correct | 17 ms | 23916 KB | n=100 |
25 | Correct | 17 ms | 23916 KB | n=100 |
26 | Correct | 17 ms | 23916 KB | n=12 |
27 | Correct | 17 ms | 23916 KB | n=100 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 17 ms | 23936 KB | n=5 |
2 | Correct | 17 ms | 23916 KB | n=100 |
3 | Correct | 17 ms | 23916 KB | n=100 |
4 | Correct | 17 ms | 23936 KB | n=100 |
5 | Correct | 17 ms | 23916 KB | n=100 |
6 | Correct | 18 ms | 23916 KB | n=100 |
7 | Correct | 17 ms | 23916 KB | n=100 |
8 | Correct | 17 ms | 23916 KB | n=100 |
9 | Correct | 17 ms | 23916 KB | n=100 |
10 | Correct | 17 ms | 23916 KB | n=100 |
11 | Correct | 17 ms | 23916 KB | n=100 |
12 | Correct | 17 ms | 23916 KB | n=100 |
13 | Correct | 19 ms | 23916 KB | n=100 |
14 | Correct | 20 ms | 23916 KB | n=100 |
15 | Correct | 17 ms | 24064 KB | n=100 |
16 | Correct | 17 ms | 23916 KB | n=100 |
17 | Correct | 17 ms | 23916 KB | n=100 |
18 | Correct | 18 ms | 23916 KB | n=100 |
19 | Correct | 17 ms | 23916 KB | n=100 |
20 | Correct | 17 ms | 23916 KB | n=100 |
21 | Correct | 17 ms | 23916 KB | n=100 |
22 | Correct | 17 ms | 23916 KB | n=100 |
23 | Correct | 17 ms | 23916 KB | n=100 |
24 | Correct | 17 ms | 23916 KB | n=100 |
25 | Correct | 17 ms | 23916 KB | n=100 |
26 | Correct | 17 ms | 23916 KB | n=12 |
27 | Correct | 17 ms | 23916 KB | n=100 |
28 | Correct | 18 ms | 24044 KB | n=500 |
29 | Correct | 18 ms | 24044 KB | n=500 |
30 | Correct | 18 ms | 24044 KB | n=500 |
31 | Correct | 18 ms | 24044 KB | n=500 |
32 | Correct | 18 ms | 24044 KB | n=500 |
33 | Correct | 18 ms | 24044 KB | n=500 |
34 | Correct | 19 ms | 24044 KB | n=500 |
35 | Correct | 18 ms | 24044 KB | n=500 |
36 | Correct | 17 ms | 24044 KB | n=500 |
37 | Correct | 17 ms | 24044 KB | n=500 |
38 | Correct | 18 ms | 24044 KB | n=500 |
39 | Correct | 21 ms | 24044 KB | n=500 |
40 | Correct | 18 ms | 24044 KB | n=500 |
41 | Correct | 17 ms | 24044 KB | n=500 |
42 | Correct | 18 ms | 24044 KB | n=500 |
43 | Correct | 18 ms | 24044 KB | n=500 |
44 | Correct | 18 ms | 24044 KB | n=500 |
45 | Correct | 18 ms | 24044 KB | n=500 |
46 | Correct | 18 ms | 24044 KB | n=500 |
47 | Correct | 18 ms | 24044 KB | n=500 |
48 | Correct | 18 ms | 24044 KB | n=500 |
49 | Correct | 18 ms | 24044 KB | n=500 |
50 | Correct | 18 ms | 24044 KB | n=500 |
51 | Correct | 18 ms | 24044 KB | n=500 |
52 | Correct | 18 ms | 24044 KB | n=500 |
53 | Correct | 19 ms | 24044 KB | n=500 |
54 | Correct | 18 ms | 24064 KB | n=500 |
55 | Correct | 17 ms | 24044 KB | n=278 |
56 | Correct | 18 ms | 24044 KB | n=500 |
57 | Correct | 18 ms | 24044 KB | n=500 |
58 | Correct | 18 ms | 24044 KB | n=500 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 17 ms | 23936 KB | n=5 |
2 | Correct | 17 ms | 23916 KB | n=100 |
3 | Correct | 17 ms | 23916 KB | n=100 |
4 | Correct | 17 ms | 23936 KB | n=100 |
5 | Correct | 17 ms | 23916 KB | n=100 |
6 | Correct | 18 ms | 23916 KB | n=100 |
7 | Correct | 17 ms | 23916 KB | n=100 |
8 | Correct | 17 ms | 23916 KB | n=100 |
9 | Correct | 17 ms | 23916 KB | n=100 |
10 | Correct | 17 ms | 23916 KB | n=100 |
11 | Correct | 17 ms | 23916 KB | n=100 |
12 | Correct | 17 ms | 23916 KB | n=100 |
13 | Correct | 19 ms | 23916 KB | n=100 |
14 | Correct | 20 ms | 23916 KB | n=100 |
15 | Correct | 17 ms | 24064 KB | n=100 |
16 | Correct | 17 ms | 23916 KB | n=100 |
17 | Correct | 17 ms | 23916 KB | n=100 |
18 | Correct | 18 ms | 23916 KB | n=100 |
19 | Correct | 17 ms | 23916 KB | n=100 |
20 | Correct | 17 ms | 23916 KB | n=100 |
21 | Correct | 17 ms | 23916 KB | n=100 |
22 | Correct | 17 ms | 23916 KB | n=100 |
23 | Correct | 17 ms | 23916 KB | n=100 |
24 | Correct | 17 ms | 23916 KB | n=100 |
25 | Correct | 17 ms | 23916 KB | n=100 |
26 | Correct | 17 ms | 23916 KB | n=12 |
27 | Correct | 17 ms | 23916 KB | n=100 |
28 | Correct | 18 ms | 24044 KB | n=500 |
29 | Correct | 18 ms | 24044 KB | n=500 |
30 | Correct | 18 ms | 24044 KB | n=500 |
31 | Correct | 18 ms | 24044 KB | n=500 |
32 | Correct | 18 ms | 24044 KB | n=500 |
33 | Correct | 18 ms | 24044 KB | n=500 |
34 | Correct | 19 ms | 24044 KB | n=500 |
35 | Correct | 18 ms | 24044 KB | n=500 |
36 | Correct | 17 ms | 24044 KB | n=500 |
37 | Correct | 17 ms | 24044 KB | n=500 |
38 | Correct | 18 ms | 24044 KB | n=500 |
39 | Correct | 21 ms | 24044 KB | n=500 |
40 | Correct | 18 ms | 24044 KB | n=500 |
41 | Correct | 17 ms | 24044 KB | n=500 |
42 | Correct | 18 ms | 24044 KB | n=500 |
43 | Correct | 18 ms | 24044 KB | n=500 |
44 | Correct | 18 ms | 24044 KB | n=500 |
45 | Correct | 18 ms | 24044 KB | n=500 |
46 | Correct | 18 ms | 24044 KB | n=500 |
47 | Correct | 18 ms | 24044 KB | n=500 |
48 | Correct | 18 ms | 24044 KB | n=500 |
49 | Correct | 18 ms | 24044 KB | n=500 |
50 | Correct | 18 ms | 24044 KB | n=500 |
51 | Correct | 18 ms | 24044 KB | n=500 |
52 | Correct | 18 ms | 24044 KB | n=500 |
53 | Correct | 19 ms | 24044 KB | n=500 |
54 | Correct | 18 ms | 24064 KB | n=500 |
55 | Correct | 17 ms | 24044 KB | n=278 |
56 | Correct | 18 ms | 24044 KB | n=500 |
57 | Correct | 18 ms | 24044 KB | n=500 |
58 | Correct | 18 ms | 24044 KB | n=500 |
59 | Correct | 21 ms | 24428 KB | n=2000 |
60 | Correct | 21 ms | 24556 KB | n=2000 |
61 | Correct | 21 ms | 24428 KB | n=2000 |
62 | Correct | 21 ms | 24428 KB | n=2000 |
63 | Correct | 21 ms | 24428 KB | n=2000 |
64 | Correct | 21 ms | 24428 KB | n=2000 |
65 | Correct | 21 ms | 24448 KB | n=2000 |
66 | Correct | 22 ms | 24428 KB | n=2000 |
67 | Correct | 22 ms | 24556 KB | n=2000 |
68 | Correct | 21 ms | 24448 KB | n=2000 |
69 | Correct | 20 ms | 24428 KB | n=2000 |
70 | Correct | 20 ms | 24428 KB | n=2000 |
71 | Correct | 20 ms | 24428 KB | n=2000 |
72 | Correct | 23 ms | 24428 KB | n=2000 |
73 | Correct | 20 ms | 24428 KB | n=2000 |
74 | Correct | 20 ms | 24428 KB | n=1844 |
75 | Correct | 20 ms | 24428 KB | n=2000 |
76 | Correct | 22 ms | 24444 KB | n=2000 |
77 | Correct | 21 ms | 24428 KB | n=2000 |
78 | Correct | 21 ms | 24428 KB | n=2000 |
79 | Correct | 21 ms | 24428 KB | n=2000 |
80 | Correct | 21 ms | 24428 KB | n=2000 |
81 | Correct | 21 ms | 24428 KB | n=2000 |
82 | Correct | 21 ms | 24428 KB | n=2000 |
83 | Correct | 24 ms | 24428 KB | n=2000 |
84 | Correct | 21 ms | 24428 KB | n=2000 |
85 | Correct | 22 ms | 24428 KB | n=2000 |
86 | Correct | 21 ms | 24428 KB | n=2000 |
87 | Correct | 21 ms | 24428 KB | n=2000 |
88 | Correct | 21 ms | 24428 KB | n=2000 |
89 | Correct | 21 ms | 24556 KB | n=2000 |
90 | Correct | 22 ms | 24428 KB | n=2000 |
91 | Correct | 20 ms | 24428 KB | n=2000 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 17 ms | 23936 KB | n=5 |
2 | Correct | 17 ms | 23916 KB | n=100 |
3 | Correct | 17 ms | 23916 KB | n=100 |
4 | Correct | 17 ms | 23936 KB | n=100 |
5 | Correct | 17 ms | 23916 KB | n=100 |
6 | Correct | 18 ms | 23916 KB | n=100 |
7 | Correct | 17 ms | 23916 KB | n=100 |
8 | Correct | 17 ms | 23916 KB | n=100 |
9 | Correct | 17 ms | 23916 KB | n=100 |
10 | Correct | 17 ms | 23916 KB | n=100 |
11 | Correct | 17 ms | 23916 KB | n=100 |
12 | Correct | 17 ms | 23916 KB | n=100 |
13 | Correct | 19 ms | 23916 KB | n=100 |
14 | Correct | 20 ms | 23916 KB | n=100 |
15 | Correct | 17 ms | 24064 KB | n=100 |
16 | Correct | 17 ms | 23916 KB | n=100 |
17 | Correct | 17 ms | 23916 KB | n=100 |
18 | Correct | 18 ms | 23916 KB | n=100 |
19 | Correct | 17 ms | 23916 KB | n=100 |
20 | Correct | 17 ms | 23916 KB | n=100 |
21 | Correct | 17 ms | 23916 KB | n=100 |
22 | Correct | 17 ms | 23916 KB | n=100 |
23 | Correct | 17 ms | 23916 KB | n=100 |
24 | Correct | 17 ms | 23916 KB | n=100 |
25 | Correct | 17 ms | 23916 KB | n=100 |
26 | Correct | 17 ms | 23916 KB | n=12 |
27 | Correct | 17 ms | 23916 KB | n=100 |
28 | Correct | 18 ms | 24044 KB | n=500 |
29 | Correct | 18 ms | 24044 KB | n=500 |
30 | Correct | 18 ms | 24044 KB | n=500 |
31 | Correct | 18 ms | 24044 KB | n=500 |
32 | Correct | 18 ms | 24044 KB | n=500 |
33 | Correct | 18 ms | 24044 KB | n=500 |
34 | Correct | 19 ms | 24044 KB | n=500 |
35 | Correct | 18 ms | 24044 KB | n=500 |
36 | Correct | 17 ms | 24044 KB | n=500 |
37 | Correct | 17 ms | 24044 KB | n=500 |
38 | Correct | 18 ms | 24044 KB | n=500 |
39 | Correct | 21 ms | 24044 KB | n=500 |
40 | Correct | 18 ms | 24044 KB | n=500 |
41 | Correct | 17 ms | 24044 KB | n=500 |
42 | Correct | 18 ms | 24044 KB | n=500 |
43 | Correct | 18 ms | 24044 KB | n=500 |
44 | Correct | 18 ms | 24044 KB | n=500 |
45 | Correct | 18 ms | 24044 KB | n=500 |
46 | Correct | 18 ms | 24044 KB | n=500 |
47 | Correct | 18 ms | 24044 KB | n=500 |
48 | Correct | 18 ms | 24044 KB | n=500 |
49 | Correct | 18 ms | 24044 KB | n=500 |
50 | Correct | 18 ms | 24044 KB | n=500 |
51 | Correct | 18 ms | 24044 KB | n=500 |
52 | Correct | 18 ms | 24044 KB | n=500 |
53 | Correct | 19 ms | 24044 KB | n=500 |
54 | Correct | 18 ms | 24064 KB | n=500 |
55 | Correct | 17 ms | 24044 KB | n=278 |
56 | Correct | 18 ms | 24044 KB | n=500 |
57 | Correct | 18 ms | 24044 KB | n=500 |
58 | Correct | 18 ms | 24044 KB | n=500 |
59 | Correct | 21 ms | 24428 KB | n=2000 |
60 | Correct | 21 ms | 24556 KB | n=2000 |
61 | Correct | 21 ms | 24428 KB | n=2000 |
62 | Correct | 21 ms | 24428 KB | n=2000 |
63 | Correct | 21 ms | 24428 KB | n=2000 |
64 | Correct | 21 ms | 24428 KB | n=2000 |
65 | Correct | 21 ms | 24448 KB | n=2000 |
66 | Correct | 22 ms | 24428 KB | n=2000 |
67 | Correct | 22 ms | 24556 KB | n=2000 |
68 | Correct | 21 ms | 24448 KB | n=2000 |
69 | Correct | 20 ms | 24428 KB | n=2000 |
70 | Correct | 20 ms | 24428 KB | n=2000 |
71 | Correct | 20 ms | 24428 KB | n=2000 |
72 | Correct | 23 ms | 24428 KB | n=2000 |
73 | Correct | 20 ms | 24428 KB | n=2000 |
74 | Correct | 20 ms | 24428 KB | n=1844 |
75 | Correct | 20 ms | 24428 KB | n=2000 |
76 | Correct | 22 ms | 24444 KB | n=2000 |
77 | Correct | 21 ms | 24428 KB | n=2000 |
78 | Correct | 21 ms | 24428 KB | n=2000 |
79 | Correct | 21 ms | 24428 KB | n=2000 |
80 | Correct | 21 ms | 24428 KB | n=2000 |
81 | Correct | 21 ms | 24428 KB | n=2000 |
82 | Correct | 21 ms | 24428 KB | n=2000 |
83 | Correct | 24 ms | 24428 KB | n=2000 |
84 | Correct | 21 ms | 24428 KB | n=2000 |
85 | Correct | 22 ms | 24428 KB | n=2000 |
86 | Correct | 21 ms | 24428 KB | n=2000 |
87 | Correct | 21 ms | 24428 KB | n=2000 |
88 | Correct | 21 ms | 24428 KB | n=2000 |
89 | Correct | 21 ms | 24556 KB | n=2000 |
90 | Correct | 22 ms | 24428 KB | n=2000 |
91 | Correct | 20 ms | 24428 KB | n=2000 |
92 | Correct | 962 ms | 72940 KB | n=200000 |
93 | Correct | 1327 ms | 77856 KB | n=200000 |
94 | Correct | 1221 ms | 81516 KB | n=200000 |
95 | Correct | 949 ms | 73056 KB | n=200000 |
96 | Correct | 902 ms | 72928 KB | n=200000 |
97 | Correct | 1303 ms | 77292 KB | n=200000 |
98 | Correct | 958 ms | 72872 KB | n=200000 |
99 | Correct | 1165 ms | 73196 KB | n=200000 |
100 | Correct | 954 ms | 72928 KB | n=200000 |
101 | Correct | 1236 ms | 82640 KB | n=200000 |
102 | Correct | 570 ms | 74220 KB | n=200000 |
103 | Correct | 562 ms | 74092 KB | n=200000 |
104 | Correct | 561 ms | 74092 KB | n=200000 |
105 | Correct | 574 ms | 74476 KB | n=200000 |
106 | Correct | 577 ms | 74544 KB | n=200000 |
107 | Correct | 559 ms | 74476 KB | n=200000 |
108 | Correct | 1116 ms | 73180 KB | n=200000 |
109 | Correct | 1083 ms | 73068 KB | n=200000 |
110 | Correct | 1097 ms | 73096 KB | n=200000 |
111 | Correct | 959 ms | 72672 KB | n=200000 |
112 | Correct | 1239 ms | 81772 KB | n=200000 |
113 | Correct | 1290 ms | 77120 KB | n=200000 |
114 | Correct | 960 ms | 72500 KB | n=200000 |
115 | Correct | 1468 ms | 75116 KB | n=200000 |
116 | Correct | 925 ms | 73056 KB | n=200000 |
117 | Correct | 1219 ms | 82284 KB | n=200000 |
118 | Correct | 1419 ms | 75920 KB | n=200000 |
119 | Correct | 902 ms | 73056 KB | n=200000 |
120 | Correct | 1173 ms | 81608 KB | n=200000 |
121 | Correct | 1161 ms | 81772 KB | n=200000 |
122 | Correct | 1181 ms | 81900 KB | n=200000 |
123 | Correct | 572 ms | 74220 KB | n=200000 |
124 | Correct | 320 ms | 38636 KB | n=25264 |