//bit chass 1
#include <bits/stdc++.h>
#define x first
#define y second
#define el "\n"
#define ll long long
#define pb push_back
#define pll pair <ll, ll>
#define pii pair <int, int>
#define all(x) x.begin(), x.end()
#define lcm(x,y) x * y / __gcd(x, y)
#define ibase ios_base::sync_with_stdio(0), cin.tie(0)
using namespace std;
const int N = 2e5 + 5, inf = 1e9 + 7, M = 2e6, MM = 2e6 + 5, K = 300;
const ll MI = 2e18;
const double P = 3.14;
int a[N], tim, tin[N], tout[N], u[N][25], t[4 * N];
vector <int> g[N];
void dfs(int v, int pr) {
tin[v] = tim++;
u[v][0] = pr;
for (int i = 1; i <= 24; i++)
u[v][i] = u[u[v][i - 1]][i - 1];
for (int to : g[v]) {
if (to != pr)
dfs(to, v);
}
tout[v] = tim++;
}
bool up(int x, int y) {
if (tin[x] <= tin[y] && tin[y] <= tout[x])
return 1;
return 0;
}
int lca(int x, int y) {
if (up(x, y))
return x;
if (up(y, x))
return y;
for (int i = 24; i >= 0; i--) {
if (u[x][i] != 0 && !up(u[x][i], y))
x = u[x][i];
}
return u[x][0];
}
void build(int v, int tl, int tr) {
if (tl == tr) {
t[v] = a[tl];
return;
}
int tm = (tl + tr) >> 1;
build(v + v, tl, tm);
build(v + v + 1, tm + 1, tr);
t[v] = lca(t[v + v], t[v + v + 1]);
}
void upd(int v, int tl, int tr, int pos, int val) {
if (tl == tr) {
t[v] = val;
return;
}
int tm = (tl + tr) >> 1;
if (pos <= tm)
upd(v + v, tl, tm, pos, val);
else
upd(v + v + 1, tm + 1, tr, pos, val);
t[v] = lca(t[v + v], t[v + v + 1]);
}
int get(int v, int tl, int tr, int l, int r) {
if (l <= tl && tr <= r)
return t[v];
if (r < tl || tr < l)
return -1;
int tm = (tl + tr) >> 1;
int pl = get(v + v, tl, tm, l, r), pr = get(v + v + 1, tm + 1, tr, l, r);
if (pl == pr && pr == -1)
return -1;
else if (pl == -1)
return pr;
else if (pr == -1)
return pl;
else
return (lca(pl, pr));
}
void solve() {
int n, m, q;
cin >> n >> m >> q;
for (int i = 1, x, y; i < n; i++) {
cin >> x >> y;
g[x].pb(y);
g[y].pb(x);
}
tim = 1;
dfs(1, 0);
tout[0] = N;
for (int i = 1; i <= m; i++)
cin >> a[i];
build(1, 1, m);
while (q--) {
int tp;
cin >> tp;
if (tp == 1) {
int pos, v;
cin >> pos >> v;
upd(1, 1, m, pos, v);
}
else {
int l, r, v;
bool ok = 0;
cin >> l >> r >> v;
for (int i = l; i <= r; i++) {
int tl = i, tr = r + 1, tm;
while (tr - tl > 1) {
tm = (tl + tr) >> 1;
int gt = get(1, 1, m, tl, tm);
if (up(v, gt))
tl = tm;
else
tr = tm;
}
if (get(1, 1, m, i, tl) == v) {
cout << i << ' ' << tl << el;
ok = 1;
break;
}
}
if (!ok)
cout << "-1 -1" << el;
}
}
}
int main() {
ibase;
int T = 1;
// cin >> T;
for (int i = 1; i <= T; i++) {
// cout << "Case " << i << ": ";
solve();
cout << el;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4940 KB |
n=5 |
2 |
Correct |
4 ms |
4940 KB |
n=100 |
3 |
Correct |
4 ms |
4940 KB |
n=100 |
4 |
Correct |
3 ms |
4940 KB |
n=100 |
5 |
Correct |
3 ms |
4940 KB |
n=100 |
6 |
Correct |
6 ms |
5052 KB |
n=100 |
7 |
Correct |
6 ms |
4940 KB |
n=100 |
8 |
Correct |
4 ms |
4940 KB |
n=100 |
9 |
Correct |
3 ms |
4940 KB |
n=100 |
10 |
Correct |
4 ms |
4940 KB |
n=100 |
11 |
Correct |
5 ms |
4940 KB |
n=100 |
12 |
Correct |
3 ms |
4940 KB |
n=100 |
13 |
Correct |
3 ms |
4940 KB |
n=100 |
14 |
Correct |
3 ms |
4940 KB |
n=100 |
15 |
Correct |
2 ms |
4940 KB |
n=100 |
16 |
Correct |
3 ms |
4940 KB |
n=100 |
17 |
Correct |
3 ms |
4940 KB |
n=100 |
18 |
Correct |
3 ms |
4940 KB |
n=100 |
19 |
Correct |
3 ms |
4940 KB |
n=100 |
20 |
Correct |
3 ms |
4940 KB |
n=100 |
21 |
Correct |
3 ms |
4940 KB |
n=100 |
22 |
Correct |
3 ms |
4968 KB |
n=100 |
23 |
Correct |
4 ms |
4940 KB |
n=100 |
24 |
Correct |
4 ms |
4940 KB |
n=100 |
25 |
Correct |
3 ms |
4940 KB |
n=100 |
26 |
Correct |
3 ms |
4940 KB |
n=12 |
27 |
Correct |
5 ms |
4940 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4940 KB |
n=5 |
2 |
Correct |
4 ms |
4940 KB |
n=100 |
3 |
Correct |
4 ms |
4940 KB |
n=100 |
4 |
Correct |
3 ms |
4940 KB |
n=100 |
5 |
Correct |
3 ms |
4940 KB |
n=100 |
6 |
Correct |
6 ms |
5052 KB |
n=100 |
7 |
Correct |
6 ms |
4940 KB |
n=100 |
8 |
Correct |
4 ms |
4940 KB |
n=100 |
9 |
Correct |
3 ms |
4940 KB |
n=100 |
10 |
Correct |
4 ms |
4940 KB |
n=100 |
11 |
Correct |
5 ms |
4940 KB |
n=100 |
12 |
Correct |
3 ms |
4940 KB |
n=100 |
13 |
Correct |
3 ms |
4940 KB |
n=100 |
14 |
Correct |
3 ms |
4940 KB |
n=100 |
15 |
Correct |
2 ms |
4940 KB |
n=100 |
16 |
Correct |
3 ms |
4940 KB |
n=100 |
17 |
Correct |
3 ms |
4940 KB |
n=100 |
18 |
Correct |
3 ms |
4940 KB |
n=100 |
19 |
Correct |
3 ms |
4940 KB |
n=100 |
20 |
Correct |
3 ms |
4940 KB |
n=100 |
21 |
Correct |
3 ms |
4940 KB |
n=100 |
22 |
Correct |
3 ms |
4968 KB |
n=100 |
23 |
Correct |
4 ms |
4940 KB |
n=100 |
24 |
Correct |
4 ms |
4940 KB |
n=100 |
25 |
Correct |
3 ms |
4940 KB |
n=100 |
26 |
Correct |
3 ms |
4940 KB |
n=12 |
27 |
Correct |
5 ms |
4940 KB |
n=100 |
28 |
Correct |
3 ms |
5068 KB |
n=500 |
29 |
Correct |
25 ms |
5068 KB |
n=500 |
30 |
Correct |
22 ms |
5068 KB |
n=500 |
31 |
Correct |
23 ms |
5068 KB |
n=500 |
32 |
Correct |
4 ms |
5068 KB |
n=500 |
33 |
Correct |
20 ms |
5068 KB |
n=500 |
34 |
Correct |
4 ms |
5068 KB |
n=500 |
35 |
Correct |
23 ms |
5128 KB |
n=500 |
36 |
Correct |
150 ms |
5068 KB |
n=500 |
37 |
Correct |
152 ms |
5068 KB |
n=500 |
38 |
Correct |
159 ms |
5112 KB |
n=500 |
39 |
Correct |
58 ms |
5116 KB |
n=500 |
40 |
Correct |
50 ms |
5100 KB |
n=500 |
41 |
Correct |
56 ms |
5100 KB |
n=500 |
42 |
Correct |
77 ms |
5068 KB |
n=500 |
43 |
Correct |
87 ms |
5096 KB |
n=500 |
44 |
Correct |
83 ms |
5068 KB |
n=500 |
45 |
Correct |
3 ms |
5068 KB |
n=500 |
46 |
Correct |
27 ms |
5068 KB |
n=500 |
47 |
Correct |
21 ms |
5124 KB |
n=500 |
48 |
Correct |
3 ms |
5068 KB |
n=500 |
49 |
Correct |
20 ms |
5136 KB |
n=500 |
50 |
Correct |
32 ms |
5068 KB |
n=500 |
51 |
Correct |
34 ms |
5068 KB |
n=500 |
52 |
Correct |
43 ms |
5188 KB |
n=500 |
53 |
Correct |
36 ms |
5068 KB |
n=500 |
54 |
Correct |
21 ms |
5068 KB |
n=500 |
55 |
Correct |
7 ms |
5068 KB |
n=278 |
56 |
Correct |
121 ms |
5116 KB |
n=500 |
57 |
Correct |
121 ms |
5116 KB |
n=500 |
58 |
Correct |
99 ms |
5112 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4940 KB |
n=5 |
2 |
Correct |
4 ms |
4940 KB |
n=100 |
3 |
Correct |
4 ms |
4940 KB |
n=100 |
4 |
Correct |
3 ms |
4940 KB |
n=100 |
5 |
Correct |
3 ms |
4940 KB |
n=100 |
6 |
Correct |
6 ms |
5052 KB |
n=100 |
7 |
Correct |
6 ms |
4940 KB |
n=100 |
8 |
Correct |
4 ms |
4940 KB |
n=100 |
9 |
Correct |
3 ms |
4940 KB |
n=100 |
10 |
Correct |
4 ms |
4940 KB |
n=100 |
11 |
Correct |
5 ms |
4940 KB |
n=100 |
12 |
Correct |
3 ms |
4940 KB |
n=100 |
13 |
Correct |
3 ms |
4940 KB |
n=100 |
14 |
Correct |
3 ms |
4940 KB |
n=100 |
15 |
Correct |
2 ms |
4940 KB |
n=100 |
16 |
Correct |
3 ms |
4940 KB |
n=100 |
17 |
Correct |
3 ms |
4940 KB |
n=100 |
18 |
Correct |
3 ms |
4940 KB |
n=100 |
19 |
Correct |
3 ms |
4940 KB |
n=100 |
20 |
Correct |
3 ms |
4940 KB |
n=100 |
21 |
Correct |
3 ms |
4940 KB |
n=100 |
22 |
Correct |
3 ms |
4968 KB |
n=100 |
23 |
Correct |
4 ms |
4940 KB |
n=100 |
24 |
Correct |
4 ms |
4940 KB |
n=100 |
25 |
Correct |
3 ms |
4940 KB |
n=100 |
26 |
Correct |
3 ms |
4940 KB |
n=12 |
27 |
Correct |
5 ms |
4940 KB |
n=100 |
28 |
Correct |
3 ms |
5068 KB |
n=500 |
29 |
Correct |
25 ms |
5068 KB |
n=500 |
30 |
Correct |
22 ms |
5068 KB |
n=500 |
31 |
Correct |
23 ms |
5068 KB |
n=500 |
32 |
Correct |
4 ms |
5068 KB |
n=500 |
33 |
Correct |
20 ms |
5068 KB |
n=500 |
34 |
Correct |
4 ms |
5068 KB |
n=500 |
35 |
Correct |
23 ms |
5128 KB |
n=500 |
36 |
Correct |
150 ms |
5068 KB |
n=500 |
37 |
Correct |
152 ms |
5068 KB |
n=500 |
38 |
Correct |
159 ms |
5112 KB |
n=500 |
39 |
Correct |
58 ms |
5116 KB |
n=500 |
40 |
Correct |
50 ms |
5100 KB |
n=500 |
41 |
Correct |
56 ms |
5100 KB |
n=500 |
42 |
Correct |
77 ms |
5068 KB |
n=500 |
43 |
Correct |
87 ms |
5096 KB |
n=500 |
44 |
Correct |
83 ms |
5068 KB |
n=500 |
45 |
Correct |
3 ms |
5068 KB |
n=500 |
46 |
Correct |
27 ms |
5068 KB |
n=500 |
47 |
Correct |
21 ms |
5124 KB |
n=500 |
48 |
Correct |
3 ms |
5068 KB |
n=500 |
49 |
Correct |
20 ms |
5136 KB |
n=500 |
50 |
Correct |
32 ms |
5068 KB |
n=500 |
51 |
Correct |
34 ms |
5068 KB |
n=500 |
52 |
Correct |
43 ms |
5188 KB |
n=500 |
53 |
Correct |
36 ms |
5068 KB |
n=500 |
54 |
Correct |
21 ms |
5068 KB |
n=500 |
55 |
Correct |
7 ms |
5068 KB |
n=278 |
56 |
Correct |
121 ms |
5116 KB |
n=500 |
57 |
Correct |
121 ms |
5116 KB |
n=500 |
58 |
Correct |
99 ms |
5112 KB |
n=500 |
59 |
Correct |
10 ms |
5324 KB |
n=2000 |
60 |
Correct |
506 ms |
5416 KB |
n=2000 |
61 |
Correct |
536 ms |
5384 KB |
n=2000 |
62 |
Correct |
326 ms |
5324 KB |
n=2000 |
63 |
Correct |
14 ms |
5324 KB |
n=2000 |
64 |
Correct |
427 ms |
5444 KB |
n=2000 |
65 |
Correct |
7 ms |
5324 KB |
n=2000 |
66 |
Correct |
553 ms |
5392 KB |
n=2000 |
67 |
Correct |
31 ms |
5340 KB |
n=2000 |
68 |
Correct |
455 ms |
5384 KB |
n=2000 |
69 |
Correct |
3448 ms |
5468 KB |
n=2000 |
70 |
Correct |
3432 ms |
5472 KB |
n=2000 |
71 |
Correct |
3347 ms |
5344 KB |
n=2000 |
72 |
Correct |
1224 ms |
5328 KB |
n=2000 |
73 |
Correct |
1197 ms |
5444 KB |
n=2000 |
74 |
Correct |
6 ms |
5324 KB |
n=1844 |
75 |
Correct |
1233 ms |
5452 KB |
n=2000 |
76 |
Correct |
1738 ms |
5324 KB |
n=2000 |
77 |
Correct |
1798 ms |
5328 KB |
n=2000 |
78 |
Correct |
2124 ms |
5336 KB |
n=2000 |
79 |
Correct |
6 ms |
5324 KB |
n=2000 |
80 |
Correct |
537 ms |
5396 KB |
n=2000 |
81 |
Correct |
498 ms |
5356 KB |
n=2000 |
82 |
Correct |
7 ms |
5324 KB |
n=2000 |
83 |
Correct |
454 ms |
5384 KB |
n=2000 |
84 |
Correct |
828 ms |
5336 KB |
n=2000 |
85 |
Correct |
813 ms |
5356 KB |
n=2000 |
86 |
Correct |
844 ms |
5348 KB |
n=2000 |
87 |
Correct |
823 ms |
5348 KB |
n=2000 |
88 |
Correct |
3150 ms |
5540 KB |
n=2000 |
89 |
Correct |
3081 ms |
5524 KB |
n=2000 |
90 |
Correct |
446 ms |
5532 KB |
n=2000 |
91 |
Correct |
2255 ms |
5516 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4940 KB |
n=5 |
2 |
Correct |
4 ms |
4940 KB |
n=100 |
3 |
Correct |
4 ms |
4940 KB |
n=100 |
4 |
Correct |
3 ms |
4940 KB |
n=100 |
5 |
Correct |
3 ms |
4940 KB |
n=100 |
6 |
Correct |
6 ms |
5052 KB |
n=100 |
7 |
Correct |
6 ms |
4940 KB |
n=100 |
8 |
Correct |
4 ms |
4940 KB |
n=100 |
9 |
Correct |
3 ms |
4940 KB |
n=100 |
10 |
Correct |
4 ms |
4940 KB |
n=100 |
11 |
Correct |
5 ms |
4940 KB |
n=100 |
12 |
Correct |
3 ms |
4940 KB |
n=100 |
13 |
Correct |
3 ms |
4940 KB |
n=100 |
14 |
Correct |
3 ms |
4940 KB |
n=100 |
15 |
Correct |
2 ms |
4940 KB |
n=100 |
16 |
Correct |
3 ms |
4940 KB |
n=100 |
17 |
Correct |
3 ms |
4940 KB |
n=100 |
18 |
Correct |
3 ms |
4940 KB |
n=100 |
19 |
Correct |
3 ms |
4940 KB |
n=100 |
20 |
Correct |
3 ms |
4940 KB |
n=100 |
21 |
Correct |
3 ms |
4940 KB |
n=100 |
22 |
Correct |
3 ms |
4968 KB |
n=100 |
23 |
Correct |
4 ms |
4940 KB |
n=100 |
24 |
Correct |
4 ms |
4940 KB |
n=100 |
25 |
Correct |
3 ms |
4940 KB |
n=100 |
26 |
Correct |
3 ms |
4940 KB |
n=12 |
27 |
Correct |
5 ms |
4940 KB |
n=100 |
28 |
Correct |
3 ms |
5068 KB |
n=500 |
29 |
Correct |
25 ms |
5068 KB |
n=500 |
30 |
Correct |
22 ms |
5068 KB |
n=500 |
31 |
Correct |
23 ms |
5068 KB |
n=500 |
32 |
Correct |
4 ms |
5068 KB |
n=500 |
33 |
Correct |
20 ms |
5068 KB |
n=500 |
34 |
Correct |
4 ms |
5068 KB |
n=500 |
35 |
Correct |
23 ms |
5128 KB |
n=500 |
36 |
Correct |
150 ms |
5068 KB |
n=500 |
37 |
Correct |
152 ms |
5068 KB |
n=500 |
38 |
Correct |
159 ms |
5112 KB |
n=500 |
39 |
Correct |
58 ms |
5116 KB |
n=500 |
40 |
Correct |
50 ms |
5100 KB |
n=500 |
41 |
Correct |
56 ms |
5100 KB |
n=500 |
42 |
Correct |
77 ms |
5068 KB |
n=500 |
43 |
Correct |
87 ms |
5096 KB |
n=500 |
44 |
Correct |
83 ms |
5068 KB |
n=500 |
45 |
Correct |
3 ms |
5068 KB |
n=500 |
46 |
Correct |
27 ms |
5068 KB |
n=500 |
47 |
Correct |
21 ms |
5124 KB |
n=500 |
48 |
Correct |
3 ms |
5068 KB |
n=500 |
49 |
Correct |
20 ms |
5136 KB |
n=500 |
50 |
Correct |
32 ms |
5068 KB |
n=500 |
51 |
Correct |
34 ms |
5068 KB |
n=500 |
52 |
Correct |
43 ms |
5188 KB |
n=500 |
53 |
Correct |
36 ms |
5068 KB |
n=500 |
54 |
Correct |
21 ms |
5068 KB |
n=500 |
55 |
Correct |
7 ms |
5068 KB |
n=278 |
56 |
Correct |
121 ms |
5116 KB |
n=500 |
57 |
Correct |
121 ms |
5116 KB |
n=500 |
58 |
Correct |
99 ms |
5112 KB |
n=500 |
59 |
Correct |
10 ms |
5324 KB |
n=2000 |
60 |
Correct |
506 ms |
5416 KB |
n=2000 |
61 |
Correct |
536 ms |
5384 KB |
n=2000 |
62 |
Correct |
326 ms |
5324 KB |
n=2000 |
63 |
Correct |
14 ms |
5324 KB |
n=2000 |
64 |
Correct |
427 ms |
5444 KB |
n=2000 |
65 |
Correct |
7 ms |
5324 KB |
n=2000 |
66 |
Correct |
553 ms |
5392 KB |
n=2000 |
67 |
Correct |
31 ms |
5340 KB |
n=2000 |
68 |
Correct |
455 ms |
5384 KB |
n=2000 |
69 |
Correct |
3448 ms |
5468 KB |
n=2000 |
70 |
Correct |
3432 ms |
5472 KB |
n=2000 |
71 |
Correct |
3347 ms |
5344 KB |
n=2000 |
72 |
Correct |
1224 ms |
5328 KB |
n=2000 |
73 |
Correct |
1197 ms |
5444 KB |
n=2000 |
74 |
Correct |
6 ms |
5324 KB |
n=1844 |
75 |
Correct |
1233 ms |
5452 KB |
n=2000 |
76 |
Correct |
1738 ms |
5324 KB |
n=2000 |
77 |
Correct |
1798 ms |
5328 KB |
n=2000 |
78 |
Correct |
2124 ms |
5336 KB |
n=2000 |
79 |
Correct |
6 ms |
5324 KB |
n=2000 |
80 |
Correct |
537 ms |
5396 KB |
n=2000 |
81 |
Correct |
498 ms |
5356 KB |
n=2000 |
82 |
Correct |
7 ms |
5324 KB |
n=2000 |
83 |
Correct |
454 ms |
5384 KB |
n=2000 |
84 |
Correct |
828 ms |
5336 KB |
n=2000 |
85 |
Correct |
813 ms |
5356 KB |
n=2000 |
86 |
Correct |
844 ms |
5348 KB |
n=2000 |
87 |
Correct |
823 ms |
5348 KB |
n=2000 |
88 |
Correct |
3150 ms |
5540 KB |
n=2000 |
89 |
Correct |
3081 ms |
5524 KB |
n=2000 |
90 |
Correct |
446 ms |
5532 KB |
n=2000 |
91 |
Correct |
2255 ms |
5516 KB |
n=2000 |
92 |
Execution timed out |
4010 ms |
37956 KB |
Time limit exceeded |
93 |
Halted |
0 ms |
0 KB |
- |