#include <bits/stdc++.h>
//ako ovaj vaso daso misli da me pobedjuje.....
using namespace std;
#define int long long
#define f first
#define s second
const int N = 2e5 + 69;
const int K = 19;
int up[N][K], a[N], tin[N], tout[N], timer, m;
int n, q, st[4 * N];
vector<int> g[N];
bool anc(int u, int v) {
return tin[u] <= tin[v] && tout[u] >= tout[v];
}
int Lca(int a, int b) {
if (anc(a, b))
return a;
else if (anc(b, a))
return b;
for (int i = K - 1;i >= 0;i--) {
if (!anc(up[a][i], b) && up[a][i] > 0)
a = up[a][i];
}
return up[a][0];
}
void dfs(int v, int p) {
tin[v] = ++timer;
up[v][0] = p;
for (int i = 1;i < K;i++)
up[v][i] = up[up[v][i - 1]][i - 1];
for (auto u : g[v]) {
if (u == p)
continue;
dfs(u, v);
}
tout[v] = timer;
}
void modify(int v, int tl, int tr, int p, int x) {
if (tl == tr)
st[v] = x;
else {
int mid = (tl + tr) / 2;
if (p <= mid)
modify(v * 2, tl, mid, p, x);
else
modify(v * 2 + 1, mid + 1, tr, p, x);
st[v] = Lca(st[v * 2], st[v * 2 + 1]);
}
}
int get(int v, int tl, int tr, int l, int r) {
if (tl > r || tr < l)
return -1;
else if (tl >= l && tr <= r)
return st[v];
else {
int mid = (tl + tr) / 2;
int left = get(v * 2, tl, mid, l, r);
int right = get(v * 2 + 1, mid + 1, tr, l, r);
assert(left != -1 || right != -1);
if (left != -1 && right != -1)
return Lca(left, right);
else if (left != -1)
return left;
else
return right;
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int tt = 1;
//cin >> tt;
while (tt--) {
cin >> n >> m >> q;
for (int i = 1;i <= n - 1;i++) {
int a, b;
cin >> a >> b;
g[a].push_back(b);
g[b].push_back(a);
}
dfs(1, 0);
for (int i = 1;i <= m;i++) {
cin >> a[i];
modify(1, 1, m, i, a[i]);
}
while (q--) {
int t;
cin >> t;
if (t == 1) {
int pos, v;
cin >> pos >> v;
modify(1, 1, m, pos, v);
a[pos] = v;
}
else {
int tl, tr, v;
cin >> tl >> tr >> v;
int x = -1, y = -1;
if (a[tl] == v)
x = y = tl;
for (int i = tl + 1;i <= tr;i++) {
if (get(1, 1, m, i - 1, i) == v)
x = i - 1, y = i;
else if (a[i] == v)
x = y = i;
if (x != -1)
break;
}
cout << x << ' ' << y << '\n';
}
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12888 KB |
n=5 |
2 |
Correct |
3 ms |
12892 KB |
n=100 |
3 |
Correct |
3 ms |
12892 KB |
n=100 |
4 |
Correct |
2 ms |
12892 KB |
n=100 |
5 |
Correct |
2 ms |
12888 KB |
n=100 |
6 |
Correct |
4 ms |
12892 KB |
n=100 |
7 |
Correct |
3 ms |
12888 KB |
n=100 |
8 |
Correct |
3 ms |
12892 KB |
n=100 |
9 |
Correct |
3 ms |
12888 KB |
n=100 |
10 |
Correct |
3 ms |
12888 KB |
n=100 |
11 |
Correct |
3 ms |
12892 KB |
n=100 |
12 |
Correct |
3 ms |
12892 KB |
n=100 |
13 |
Correct |
2 ms |
12888 KB |
n=100 |
14 |
Correct |
2 ms |
12892 KB |
n=100 |
15 |
Correct |
3 ms |
12892 KB |
n=100 |
16 |
Correct |
3 ms |
12888 KB |
n=100 |
17 |
Correct |
3 ms |
12892 KB |
n=100 |
18 |
Correct |
3 ms |
12892 KB |
n=100 |
19 |
Correct |
3 ms |
12892 KB |
n=100 |
20 |
Correct |
3 ms |
12888 KB |
n=100 |
21 |
Correct |
3 ms |
13144 KB |
n=100 |
22 |
Correct |
2 ms |
12892 KB |
n=100 |
23 |
Correct |
3 ms |
12888 KB |
n=100 |
24 |
Correct |
3 ms |
12892 KB |
n=100 |
25 |
Correct |
3 ms |
12892 KB |
n=100 |
26 |
Correct |
3 ms |
12892 KB |
n=12 |
27 |
Correct |
4 ms |
12888 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12888 KB |
n=5 |
2 |
Correct |
3 ms |
12892 KB |
n=100 |
3 |
Correct |
3 ms |
12892 KB |
n=100 |
4 |
Correct |
2 ms |
12892 KB |
n=100 |
5 |
Correct |
2 ms |
12888 KB |
n=100 |
6 |
Correct |
4 ms |
12892 KB |
n=100 |
7 |
Correct |
3 ms |
12888 KB |
n=100 |
8 |
Correct |
3 ms |
12892 KB |
n=100 |
9 |
Correct |
3 ms |
12888 KB |
n=100 |
10 |
Correct |
3 ms |
12888 KB |
n=100 |
11 |
Correct |
3 ms |
12892 KB |
n=100 |
12 |
Correct |
3 ms |
12892 KB |
n=100 |
13 |
Correct |
2 ms |
12888 KB |
n=100 |
14 |
Correct |
2 ms |
12892 KB |
n=100 |
15 |
Correct |
3 ms |
12892 KB |
n=100 |
16 |
Correct |
3 ms |
12888 KB |
n=100 |
17 |
Correct |
3 ms |
12892 KB |
n=100 |
18 |
Correct |
3 ms |
12892 KB |
n=100 |
19 |
Correct |
3 ms |
12892 KB |
n=100 |
20 |
Correct |
3 ms |
12888 KB |
n=100 |
21 |
Correct |
3 ms |
13144 KB |
n=100 |
22 |
Correct |
2 ms |
12892 KB |
n=100 |
23 |
Correct |
3 ms |
12888 KB |
n=100 |
24 |
Correct |
3 ms |
12892 KB |
n=100 |
25 |
Correct |
3 ms |
12892 KB |
n=100 |
26 |
Correct |
3 ms |
12892 KB |
n=12 |
27 |
Correct |
4 ms |
12888 KB |
n=100 |
28 |
Correct |
3 ms |
12892 KB |
n=500 |
29 |
Correct |
5 ms |
12892 KB |
n=500 |
30 |
Correct |
5 ms |
12892 KB |
n=500 |
31 |
Correct |
5 ms |
12892 KB |
n=500 |
32 |
Correct |
3 ms |
12888 KB |
n=500 |
33 |
Correct |
4 ms |
12892 KB |
n=500 |
34 |
Correct |
3 ms |
12888 KB |
n=500 |
35 |
Correct |
4 ms |
12888 KB |
n=500 |
36 |
Correct |
16 ms |
12892 KB |
n=500 |
37 |
Correct |
16 ms |
12888 KB |
n=500 |
38 |
Correct |
16 ms |
12892 KB |
n=500 |
39 |
Correct |
10 ms |
12888 KB |
n=500 |
40 |
Correct |
9 ms |
12888 KB |
n=500 |
41 |
Correct |
9 ms |
12892 KB |
n=500 |
42 |
Correct |
10 ms |
12892 KB |
n=500 |
43 |
Correct |
9 ms |
12892 KB |
n=500 |
44 |
Correct |
9 ms |
12892 KB |
n=500 |
45 |
Correct |
3 ms |
12888 KB |
n=500 |
46 |
Correct |
5 ms |
12888 KB |
n=500 |
47 |
Correct |
4 ms |
12892 KB |
n=500 |
48 |
Correct |
3 ms |
12892 KB |
n=500 |
49 |
Correct |
4 ms |
12892 KB |
n=500 |
50 |
Correct |
6 ms |
12892 KB |
n=500 |
51 |
Correct |
5 ms |
12892 KB |
n=500 |
52 |
Correct |
6 ms |
12892 KB |
n=500 |
53 |
Correct |
6 ms |
12892 KB |
n=500 |
54 |
Correct |
9 ms |
12892 KB |
n=500 |
55 |
Correct |
3 ms |
12892 KB |
n=278 |
56 |
Correct |
11 ms |
12892 KB |
n=500 |
57 |
Correct |
11 ms |
12888 KB |
n=500 |
58 |
Correct |
13 ms |
12892 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12888 KB |
n=5 |
2 |
Correct |
3 ms |
12892 KB |
n=100 |
3 |
Correct |
3 ms |
12892 KB |
n=100 |
4 |
Correct |
2 ms |
12892 KB |
n=100 |
5 |
Correct |
2 ms |
12888 KB |
n=100 |
6 |
Correct |
4 ms |
12892 KB |
n=100 |
7 |
Correct |
3 ms |
12888 KB |
n=100 |
8 |
Correct |
3 ms |
12892 KB |
n=100 |
9 |
Correct |
3 ms |
12888 KB |
n=100 |
10 |
Correct |
3 ms |
12888 KB |
n=100 |
11 |
Correct |
3 ms |
12892 KB |
n=100 |
12 |
Correct |
3 ms |
12892 KB |
n=100 |
13 |
Correct |
2 ms |
12888 KB |
n=100 |
14 |
Correct |
2 ms |
12892 KB |
n=100 |
15 |
Correct |
3 ms |
12892 KB |
n=100 |
16 |
Correct |
3 ms |
12888 KB |
n=100 |
17 |
Correct |
3 ms |
12892 KB |
n=100 |
18 |
Correct |
3 ms |
12892 KB |
n=100 |
19 |
Correct |
3 ms |
12892 KB |
n=100 |
20 |
Correct |
3 ms |
12888 KB |
n=100 |
21 |
Correct |
3 ms |
13144 KB |
n=100 |
22 |
Correct |
2 ms |
12892 KB |
n=100 |
23 |
Correct |
3 ms |
12888 KB |
n=100 |
24 |
Correct |
3 ms |
12892 KB |
n=100 |
25 |
Correct |
3 ms |
12892 KB |
n=100 |
26 |
Correct |
3 ms |
12892 KB |
n=12 |
27 |
Correct |
4 ms |
12888 KB |
n=100 |
28 |
Correct |
3 ms |
12892 KB |
n=500 |
29 |
Correct |
5 ms |
12892 KB |
n=500 |
30 |
Correct |
5 ms |
12892 KB |
n=500 |
31 |
Correct |
5 ms |
12892 KB |
n=500 |
32 |
Correct |
3 ms |
12888 KB |
n=500 |
33 |
Correct |
4 ms |
12892 KB |
n=500 |
34 |
Correct |
3 ms |
12888 KB |
n=500 |
35 |
Correct |
4 ms |
12888 KB |
n=500 |
36 |
Correct |
16 ms |
12892 KB |
n=500 |
37 |
Correct |
16 ms |
12888 KB |
n=500 |
38 |
Correct |
16 ms |
12892 KB |
n=500 |
39 |
Correct |
10 ms |
12888 KB |
n=500 |
40 |
Correct |
9 ms |
12888 KB |
n=500 |
41 |
Correct |
9 ms |
12892 KB |
n=500 |
42 |
Correct |
10 ms |
12892 KB |
n=500 |
43 |
Correct |
9 ms |
12892 KB |
n=500 |
44 |
Correct |
9 ms |
12892 KB |
n=500 |
45 |
Correct |
3 ms |
12888 KB |
n=500 |
46 |
Correct |
5 ms |
12888 KB |
n=500 |
47 |
Correct |
4 ms |
12892 KB |
n=500 |
48 |
Correct |
3 ms |
12892 KB |
n=500 |
49 |
Correct |
4 ms |
12892 KB |
n=500 |
50 |
Correct |
6 ms |
12892 KB |
n=500 |
51 |
Correct |
5 ms |
12892 KB |
n=500 |
52 |
Correct |
6 ms |
12892 KB |
n=500 |
53 |
Correct |
6 ms |
12892 KB |
n=500 |
54 |
Correct |
9 ms |
12892 KB |
n=500 |
55 |
Correct |
3 ms |
12892 KB |
n=278 |
56 |
Correct |
11 ms |
12892 KB |
n=500 |
57 |
Correct |
11 ms |
12888 KB |
n=500 |
58 |
Correct |
13 ms |
12892 KB |
n=500 |
59 |
Correct |
5 ms |
12892 KB |
n=2000 |
60 |
Correct |
39 ms |
12888 KB |
n=2000 |
61 |
Correct |
39 ms |
12892 KB |
n=2000 |
62 |
Correct |
32 ms |
12888 KB |
n=2000 |
63 |
Correct |
5 ms |
12888 KB |
n=2000 |
64 |
Correct |
39 ms |
12892 KB |
n=2000 |
65 |
Correct |
4 ms |
12892 KB |
n=2000 |
66 |
Correct |
42 ms |
12892 KB |
n=2000 |
67 |
Correct |
7 ms |
13144 KB |
n=2000 |
68 |
Correct |
38 ms |
12888 KB |
n=2000 |
69 |
Correct |
276 ms |
13008 KB |
n=2000 |
70 |
Correct |
288 ms |
13008 KB |
n=2000 |
71 |
Correct |
272 ms |
12892 KB |
n=2000 |
72 |
Correct |
141 ms |
12888 KB |
n=2000 |
73 |
Correct |
140 ms |
13000 KB |
n=2000 |
74 |
Correct |
4 ms |
12888 KB |
n=1844 |
75 |
Correct |
145 ms |
13016 KB |
n=2000 |
76 |
Correct |
139 ms |
12892 KB |
n=2000 |
77 |
Correct |
141 ms |
12888 KB |
n=2000 |
78 |
Correct |
146 ms |
13012 KB |
n=2000 |
79 |
Correct |
7 ms |
13184 KB |
n=2000 |
80 |
Correct |
35 ms |
12892 KB |
n=2000 |
81 |
Correct |
40 ms |
12888 KB |
n=2000 |
82 |
Correct |
4 ms |
12888 KB |
n=2000 |
83 |
Correct |
42 ms |
12888 KB |
n=2000 |
84 |
Correct |
82 ms |
13024 KB |
n=2000 |
85 |
Correct |
72 ms |
12888 KB |
n=2000 |
86 |
Correct |
76 ms |
12888 KB |
n=2000 |
87 |
Correct |
85 ms |
12888 KB |
n=2000 |
88 |
Correct |
201 ms |
12888 KB |
n=2000 |
89 |
Correct |
202 ms |
13084 KB |
n=2000 |
90 |
Correct |
120 ms |
13048 KB |
n=2000 |
91 |
Correct |
206 ms |
12892 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12888 KB |
n=5 |
2 |
Correct |
3 ms |
12892 KB |
n=100 |
3 |
Correct |
3 ms |
12892 KB |
n=100 |
4 |
Correct |
2 ms |
12892 KB |
n=100 |
5 |
Correct |
2 ms |
12888 KB |
n=100 |
6 |
Correct |
4 ms |
12892 KB |
n=100 |
7 |
Correct |
3 ms |
12888 KB |
n=100 |
8 |
Correct |
3 ms |
12892 KB |
n=100 |
9 |
Correct |
3 ms |
12888 KB |
n=100 |
10 |
Correct |
3 ms |
12888 KB |
n=100 |
11 |
Correct |
3 ms |
12892 KB |
n=100 |
12 |
Correct |
3 ms |
12892 KB |
n=100 |
13 |
Correct |
2 ms |
12888 KB |
n=100 |
14 |
Correct |
2 ms |
12892 KB |
n=100 |
15 |
Correct |
3 ms |
12892 KB |
n=100 |
16 |
Correct |
3 ms |
12888 KB |
n=100 |
17 |
Correct |
3 ms |
12892 KB |
n=100 |
18 |
Correct |
3 ms |
12892 KB |
n=100 |
19 |
Correct |
3 ms |
12892 KB |
n=100 |
20 |
Correct |
3 ms |
12888 KB |
n=100 |
21 |
Correct |
3 ms |
13144 KB |
n=100 |
22 |
Correct |
2 ms |
12892 KB |
n=100 |
23 |
Correct |
3 ms |
12888 KB |
n=100 |
24 |
Correct |
3 ms |
12892 KB |
n=100 |
25 |
Correct |
3 ms |
12892 KB |
n=100 |
26 |
Correct |
3 ms |
12892 KB |
n=12 |
27 |
Correct |
4 ms |
12888 KB |
n=100 |
28 |
Correct |
3 ms |
12892 KB |
n=500 |
29 |
Correct |
5 ms |
12892 KB |
n=500 |
30 |
Correct |
5 ms |
12892 KB |
n=500 |
31 |
Correct |
5 ms |
12892 KB |
n=500 |
32 |
Correct |
3 ms |
12888 KB |
n=500 |
33 |
Correct |
4 ms |
12892 KB |
n=500 |
34 |
Correct |
3 ms |
12888 KB |
n=500 |
35 |
Correct |
4 ms |
12888 KB |
n=500 |
36 |
Correct |
16 ms |
12892 KB |
n=500 |
37 |
Correct |
16 ms |
12888 KB |
n=500 |
38 |
Correct |
16 ms |
12892 KB |
n=500 |
39 |
Correct |
10 ms |
12888 KB |
n=500 |
40 |
Correct |
9 ms |
12888 KB |
n=500 |
41 |
Correct |
9 ms |
12892 KB |
n=500 |
42 |
Correct |
10 ms |
12892 KB |
n=500 |
43 |
Correct |
9 ms |
12892 KB |
n=500 |
44 |
Correct |
9 ms |
12892 KB |
n=500 |
45 |
Correct |
3 ms |
12888 KB |
n=500 |
46 |
Correct |
5 ms |
12888 KB |
n=500 |
47 |
Correct |
4 ms |
12892 KB |
n=500 |
48 |
Correct |
3 ms |
12892 KB |
n=500 |
49 |
Correct |
4 ms |
12892 KB |
n=500 |
50 |
Correct |
6 ms |
12892 KB |
n=500 |
51 |
Correct |
5 ms |
12892 KB |
n=500 |
52 |
Correct |
6 ms |
12892 KB |
n=500 |
53 |
Correct |
6 ms |
12892 KB |
n=500 |
54 |
Correct |
9 ms |
12892 KB |
n=500 |
55 |
Correct |
3 ms |
12892 KB |
n=278 |
56 |
Correct |
11 ms |
12892 KB |
n=500 |
57 |
Correct |
11 ms |
12888 KB |
n=500 |
58 |
Correct |
13 ms |
12892 KB |
n=500 |
59 |
Correct |
5 ms |
12892 KB |
n=2000 |
60 |
Correct |
39 ms |
12888 KB |
n=2000 |
61 |
Correct |
39 ms |
12892 KB |
n=2000 |
62 |
Correct |
32 ms |
12888 KB |
n=2000 |
63 |
Correct |
5 ms |
12888 KB |
n=2000 |
64 |
Correct |
39 ms |
12892 KB |
n=2000 |
65 |
Correct |
4 ms |
12892 KB |
n=2000 |
66 |
Correct |
42 ms |
12892 KB |
n=2000 |
67 |
Correct |
7 ms |
13144 KB |
n=2000 |
68 |
Correct |
38 ms |
12888 KB |
n=2000 |
69 |
Correct |
276 ms |
13008 KB |
n=2000 |
70 |
Correct |
288 ms |
13008 KB |
n=2000 |
71 |
Correct |
272 ms |
12892 KB |
n=2000 |
72 |
Correct |
141 ms |
12888 KB |
n=2000 |
73 |
Correct |
140 ms |
13000 KB |
n=2000 |
74 |
Correct |
4 ms |
12888 KB |
n=1844 |
75 |
Correct |
145 ms |
13016 KB |
n=2000 |
76 |
Correct |
139 ms |
12892 KB |
n=2000 |
77 |
Correct |
141 ms |
12888 KB |
n=2000 |
78 |
Correct |
146 ms |
13012 KB |
n=2000 |
79 |
Correct |
7 ms |
13184 KB |
n=2000 |
80 |
Correct |
35 ms |
12892 KB |
n=2000 |
81 |
Correct |
40 ms |
12888 KB |
n=2000 |
82 |
Correct |
4 ms |
12888 KB |
n=2000 |
83 |
Correct |
42 ms |
12888 KB |
n=2000 |
84 |
Correct |
82 ms |
13024 KB |
n=2000 |
85 |
Correct |
72 ms |
12888 KB |
n=2000 |
86 |
Correct |
76 ms |
12888 KB |
n=2000 |
87 |
Correct |
85 ms |
12888 KB |
n=2000 |
88 |
Correct |
201 ms |
12888 KB |
n=2000 |
89 |
Correct |
202 ms |
13084 KB |
n=2000 |
90 |
Correct |
120 ms |
13048 KB |
n=2000 |
91 |
Correct |
206 ms |
12892 KB |
n=2000 |
92 |
Correct |
1061 ms |
54832 KB |
n=200000 |
93 |
Execution timed out |
4014 ms |
57580 KB |
Time limit exceeded |
94 |
Halted |
0 ms |
0 KB |
- |