#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;
}
cout << x << ' ' << y << '\n';
}
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
12892 KB |
n=5 |
2 |
Correct |
3 ms |
12892 KB |
n=100 |
3 |
Correct |
4 ms |
12888 KB |
n=100 |
4 |
Correct |
3 ms |
12908 KB |
n=100 |
5 |
Correct |
3 ms |
12892 KB |
n=100 |
6 |
Correct |
4 ms |
12892 KB |
n=100 |
7 |
Correct |
4 ms |
12888 KB |
n=100 |
8 |
Correct |
3 ms |
12892 KB |
n=100 |
9 |
Correct |
3 ms |
12892 KB |
n=100 |
10 |
Correct |
3 ms |
12892 KB |
n=100 |
11 |
Correct |
3 ms |
12892 KB |
n=100 |
12 |
Correct |
3 ms |
12892 KB |
n=100 |
13 |
Correct |
3 ms |
12892 KB |
n=100 |
14 |
Correct |
3 ms |
12892 KB |
n=100 |
15 |
Correct |
3 ms |
12892 KB |
n=100 |
16 |
Correct |
3 ms |
12888 KB |
n=100 |
17 |
Correct |
4 ms |
12892 KB |
n=100 |
18 |
Correct |
3 ms |
12888 KB |
n=100 |
19 |
Correct |
4 ms |
12892 KB |
n=100 |
20 |
Correct |
3 ms |
12892 KB |
n=100 |
21 |
Correct |
3 ms |
12892 KB |
n=100 |
22 |
Correct |
3 ms |
12892 KB |
n=100 |
23 |
Correct |
3 ms |
13144 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 |
3 ms |
12892 KB |
n=100 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
12892 KB |
n=5 |
2 |
Correct |
3 ms |
12892 KB |
n=100 |
3 |
Correct |
4 ms |
12888 KB |
n=100 |
4 |
Correct |
3 ms |
12908 KB |
n=100 |
5 |
Correct |
3 ms |
12892 KB |
n=100 |
6 |
Correct |
4 ms |
12892 KB |
n=100 |
7 |
Correct |
4 ms |
12888 KB |
n=100 |
8 |
Correct |
3 ms |
12892 KB |
n=100 |
9 |
Correct |
3 ms |
12892 KB |
n=100 |
10 |
Correct |
3 ms |
12892 KB |
n=100 |
11 |
Correct |
3 ms |
12892 KB |
n=100 |
12 |
Correct |
3 ms |
12892 KB |
n=100 |
13 |
Correct |
3 ms |
12892 KB |
n=100 |
14 |
Correct |
3 ms |
12892 KB |
n=100 |
15 |
Correct |
3 ms |
12892 KB |
n=100 |
16 |
Correct |
3 ms |
12888 KB |
n=100 |
17 |
Correct |
4 ms |
12892 KB |
n=100 |
18 |
Correct |
3 ms |
12888 KB |
n=100 |
19 |
Correct |
4 ms |
12892 KB |
n=100 |
20 |
Correct |
3 ms |
12892 KB |
n=100 |
21 |
Correct |
3 ms |
12892 KB |
n=100 |
22 |
Correct |
3 ms |
12892 KB |
n=100 |
23 |
Correct |
3 ms |
13144 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 |
3 ms |
12892 KB |
n=100 |
28 |
Correct |
9 ms |
13144 KB |
n=500 |
29 |
Correct |
6 ms |
12988 KB |
n=500 |
30 |
Correct |
6 ms |
12892 KB |
n=500 |
31 |
Correct |
7 ms |
12892 KB |
n=500 |
32 |
Correct |
9 ms |
12892 KB |
n=500 |
33 |
Correct |
7 ms |
12892 KB |
n=500 |
34 |
Correct |
10 ms |
13144 KB |
n=500 |
35 |
Correct |
6 ms |
12892 KB |
n=500 |
36 |
Correct |
30 ms |
12892 KB |
n=500 |
37 |
Correct |
31 ms |
12952 KB |
n=500 |
38 |
Correct |
30 ms |
12892 KB |
n=500 |
39 |
Correct |
9 ms |
12888 KB |
n=500 |
40 |
Correct |
10 ms |
12892 KB |
n=500 |
41 |
Correct |
10 ms |
12892 KB |
n=500 |
42 |
Correct |
16 ms |
12892 KB |
n=500 |
43 |
Correct |
16 ms |
12892 KB |
n=500 |
44 |
Correct |
16 ms |
12892 KB |
n=500 |
45 |
Correct |
7 ms |
12888 KB |
n=500 |
46 |
Correct |
6 ms |
12888 KB |
n=500 |
47 |
Correct |
6 ms |
12892 KB |
n=500 |
48 |
Correct |
7 ms |
12892 KB |
n=500 |
49 |
Correct |
6 ms |
12892 KB |
n=500 |
50 |
Correct |
8 ms |
12892 KB |
n=500 |
51 |
Correct |
7 ms |
12892 KB |
n=500 |
52 |
Correct |
7 ms |
12892 KB |
n=500 |
53 |
Correct |
7 ms |
12892 KB |
n=500 |
54 |
Correct |
12 ms |
12892 KB |
n=500 |
55 |
Correct |
4 ms |
12892 KB |
n=278 |
56 |
Correct |
10 ms |
12892 KB |
n=500 |
57 |
Correct |
11 ms |
12888 KB |
n=500 |
58 |
Correct |
15 ms |
12892 KB |
n=500 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
12892 KB |
n=5 |
2 |
Correct |
3 ms |
12892 KB |
n=100 |
3 |
Correct |
4 ms |
12888 KB |
n=100 |
4 |
Correct |
3 ms |
12908 KB |
n=100 |
5 |
Correct |
3 ms |
12892 KB |
n=100 |
6 |
Correct |
4 ms |
12892 KB |
n=100 |
7 |
Correct |
4 ms |
12888 KB |
n=100 |
8 |
Correct |
3 ms |
12892 KB |
n=100 |
9 |
Correct |
3 ms |
12892 KB |
n=100 |
10 |
Correct |
3 ms |
12892 KB |
n=100 |
11 |
Correct |
3 ms |
12892 KB |
n=100 |
12 |
Correct |
3 ms |
12892 KB |
n=100 |
13 |
Correct |
3 ms |
12892 KB |
n=100 |
14 |
Correct |
3 ms |
12892 KB |
n=100 |
15 |
Correct |
3 ms |
12892 KB |
n=100 |
16 |
Correct |
3 ms |
12888 KB |
n=100 |
17 |
Correct |
4 ms |
12892 KB |
n=100 |
18 |
Correct |
3 ms |
12888 KB |
n=100 |
19 |
Correct |
4 ms |
12892 KB |
n=100 |
20 |
Correct |
3 ms |
12892 KB |
n=100 |
21 |
Correct |
3 ms |
12892 KB |
n=100 |
22 |
Correct |
3 ms |
12892 KB |
n=100 |
23 |
Correct |
3 ms |
13144 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 |
3 ms |
12892 KB |
n=100 |
28 |
Correct |
9 ms |
13144 KB |
n=500 |
29 |
Correct |
6 ms |
12988 KB |
n=500 |
30 |
Correct |
6 ms |
12892 KB |
n=500 |
31 |
Correct |
7 ms |
12892 KB |
n=500 |
32 |
Correct |
9 ms |
12892 KB |
n=500 |
33 |
Correct |
7 ms |
12892 KB |
n=500 |
34 |
Correct |
10 ms |
13144 KB |
n=500 |
35 |
Correct |
6 ms |
12892 KB |
n=500 |
36 |
Correct |
30 ms |
12892 KB |
n=500 |
37 |
Correct |
31 ms |
12952 KB |
n=500 |
38 |
Correct |
30 ms |
12892 KB |
n=500 |
39 |
Correct |
9 ms |
12888 KB |
n=500 |
40 |
Correct |
10 ms |
12892 KB |
n=500 |
41 |
Correct |
10 ms |
12892 KB |
n=500 |
42 |
Correct |
16 ms |
12892 KB |
n=500 |
43 |
Correct |
16 ms |
12892 KB |
n=500 |
44 |
Correct |
16 ms |
12892 KB |
n=500 |
45 |
Correct |
7 ms |
12888 KB |
n=500 |
46 |
Correct |
6 ms |
12888 KB |
n=500 |
47 |
Correct |
6 ms |
12892 KB |
n=500 |
48 |
Correct |
7 ms |
12892 KB |
n=500 |
49 |
Correct |
6 ms |
12892 KB |
n=500 |
50 |
Correct |
8 ms |
12892 KB |
n=500 |
51 |
Correct |
7 ms |
12892 KB |
n=500 |
52 |
Correct |
7 ms |
12892 KB |
n=500 |
53 |
Correct |
7 ms |
12892 KB |
n=500 |
54 |
Correct |
12 ms |
12892 KB |
n=500 |
55 |
Correct |
4 ms |
12892 KB |
n=278 |
56 |
Correct |
10 ms |
12892 KB |
n=500 |
57 |
Correct |
11 ms |
12888 KB |
n=500 |
58 |
Correct |
15 ms |
12892 KB |
n=500 |
59 |
Correct |
100 ms |
12888 KB |
n=2000 |
60 |
Correct |
71 ms |
12892 KB |
n=2000 |
61 |
Correct |
84 ms |
12888 KB |
n=2000 |
62 |
Correct |
94 ms |
12908 KB |
n=2000 |
63 |
Correct |
108 ms |
13016 KB |
n=2000 |
64 |
Correct |
94 ms |
12892 KB |
n=2000 |
65 |
Correct |
109 ms |
13016 KB |
n=2000 |
66 |
Correct |
82 ms |
12888 KB |
n=2000 |
67 |
Correct |
116 ms |
13012 KB |
n=2000 |
68 |
Correct |
94 ms |
13044 KB |
n=2000 |
69 |
Correct |
589 ms |
13008 KB |
n=2000 |
70 |
Correct |
560 ms |
13136 KB |
n=2000 |
71 |
Correct |
545 ms |
12892 KB |
n=2000 |
72 |
Correct |
139 ms |
13016 KB |
n=2000 |
73 |
Correct |
135 ms |
13012 KB |
n=2000 |
74 |
Correct |
96 ms |
13008 KB |
n=1844 |
75 |
Correct |
141 ms |
12892 KB |
n=2000 |
76 |
Correct |
277 ms |
13004 KB |
n=2000 |
77 |
Correct |
278 ms |
13008 KB |
n=2000 |
78 |
Correct |
303 ms |
13168 KB |
n=2000 |
79 |
Correct |
89 ms |
13036 KB |
n=2000 |
80 |
Correct |
70 ms |
13068 KB |
n=2000 |
81 |
Correct |
87 ms |
12888 KB |
n=2000 |
82 |
Correct |
91 ms |
12892 KB |
n=2000 |
83 |
Correct |
72 ms |
12888 KB |
n=2000 |
84 |
Correct |
104 ms |
12892 KB |
n=2000 |
85 |
Correct |
102 ms |
13052 KB |
n=2000 |
86 |
Correct |
101 ms |
12888 KB |
n=2000 |
87 |
Correct |
106 ms |
13144 KB |
n=2000 |
88 |
Correct |
192 ms |
12888 KB |
n=2000 |
89 |
Correct |
196 ms |
12892 KB |
n=2000 |
90 |
Correct |
162 ms |
12892 KB |
n=2000 |
91 |
Correct |
270 ms |
13020 KB |
n=2000 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
12892 KB |
n=5 |
2 |
Correct |
3 ms |
12892 KB |
n=100 |
3 |
Correct |
4 ms |
12888 KB |
n=100 |
4 |
Correct |
3 ms |
12908 KB |
n=100 |
5 |
Correct |
3 ms |
12892 KB |
n=100 |
6 |
Correct |
4 ms |
12892 KB |
n=100 |
7 |
Correct |
4 ms |
12888 KB |
n=100 |
8 |
Correct |
3 ms |
12892 KB |
n=100 |
9 |
Correct |
3 ms |
12892 KB |
n=100 |
10 |
Correct |
3 ms |
12892 KB |
n=100 |
11 |
Correct |
3 ms |
12892 KB |
n=100 |
12 |
Correct |
3 ms |
12892 KB |
n=100 |
13 |
Correct |
3 ms |
12892 KB |
n=100 |
14 |
Correct |
3 ms |
12892 KB |
n=100 |
15 |
Correct |
3 ms |
12892 KB |
n=100 |
16 |
Correct |
3 ms |
12888 KB |
n=100 |
17 |
Correct |
4 ms |
12892 KB |
n=100 |
18 |
Correct |
3 ms |
12888 KB |
n=100 |
19 |
Correct |
4 ms |
12892 KB |
n=100 |
20 |
Correct |
3 ms |
12892 KB |
n=100 |
21 |
Correct |
3 ms |
12892 KB |
n=100 |
22 |
Correct |
3 ms |
12892 KB |
n=100 |
23 |
Correct |
3 ms |
13144 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 |
3 ms |
12892 KB |
n=100 |
28 |
Correct |
9 ms |
13144 KB |
n=500 |
29 |
Correct |
6 ms |
12988 KB |
n=500 |
30 |
Correct |
6 ms |
12892 KB |
n=500 |
31 |
Correct |
7 ms |
12892 KB |
n=500 |
32 |
Correct |
9 ms |
12892 KB |
n=500 |
33 |
Correct |
7 ms |
12892 KB |
n=500 |
34 |
Correct |
10 ms |
13144 KB |
n=500 |
35 |
Correct |
6 ms |
12892 KB |
n=500 |
36 |
Correct |
30 ms |
12892 KB |
n=500 |
37 |
Correct |
31 ms |
12952 KB |
n=500 |
38 |
Correct |
30 ms |
12892 KB |
n=500 |
39 |
Correct |
9 ms |
12888 KB |
n=500 |
40 |
Correct |
10 ms |
12892 KB |
n=500 |
41 |
Correct |
10 ms |
12892 KB |
n=500 |
42 |
Correct |
16 ms |
12892 KB |
n=500 |
43 |
Correct |
16 ms |
12892 KB |
n=500 |
44 |
Correct |
16 ms |
12892 KB |
n=500 |
45 |
Correct |
7 ms |
12888 KB |
n=500 |
46 |
Correct |
6 ms |
12888 KB |
n=500 |
47 |
Correct |
6 ms |
12892 KB |
n=500 |
48 |
Correct |
7 ms |
12892 KB |
n=500 |
49 |
Correct |
6 ms |
12892 KB |
n=500 |
50 |
Correct |
8 ms |
12892 KB |
n=500 |
51 |
Correct |
7 ms |
12892 KB |
n=500 |
52 |
Correct |
7 ms |
12892 KB |
n=500 |
53 |
Correct |
7 ms |
12892 KB |
n=500 |
54 |
Correct |
12 ms |
12892 KB |
n=500 |
55 |
Correct |
4 ms |
12892 KB |
n=278 |
56 |
Correct |
10 ms |
12892 KB |
n=500 |
57 |
Correct |
11 ms |
12888 KB |
n=500 |
58 |
Correct |
15 ms |
12892 KB |
n=500 |
59 |
Correct |
100 ms |
12888 KB |
n=2000 |
60 |
Correct |
71 ms |
12892 KB |
n=2000 |
61 |
Correct |
84 ms |
12888 KB |
n=2000 |
62 |
Correct |
94 ms |
12908 KB |
n=2000 |
63 |
Correct |
108 ms |
13016 KB |
n=2000 |
64 |
Correct |
94 ms |
12892 KB |
n=2000 |
65 |
Correct |
109 ms |
13016 KB |
n=2000 |
66 |
Correct |
82 ms |
12888 KB |
n=2000 |
67 |
Correct |
116 ms |
13012 KB |
n=2000 |
68 |
Correct |
94 ms |
13044 KB |
n=2000 |
69 |
Correct |
589 ms |
13008 KB |
n=2000 |
70 |
Correct |
560 ms |
13136 KB |
n=2000 |
71 |
Correct |
545 ms |
12892 KB |
n=2000 |
72 |
Correct |
139 ms |
13016 KB |
n=2000 |
73 |
Correct |
135 ms |
13012 KB |
n=2000 |
74 |
Correct |
96 ms |
13008 KB |
n=1844 |
75 |
Correct |
141 ms |
12892 KB |
n=2000 |
76 |
Correct |
277 ms |
13004 KB |
n=2000 |
77 |
Correct |
278 ms |
13008 KB |
n=2000 |
78 |
Correct |
303 ms |
13168 KB |
n=2000 |
79 |
Correct |
89 ms |
13036 KB |
n=2000 |
80 |
Correct |
70 ms |
13068 KB |
n=2000 |
81 |
Correct |
87 ms |
12888 KB |
n=2000 |
82 |
Correct |
91 ms |
12892 KB |
n=2000 |
83 |
Correct |
72 ms |
12888 KB |
n=2000 |
84 |
Correct |
104 ms |
12892 KB |
n=2000 |
85 |
Correct |
102 ms |
13052 KB |
n=2000 |
86 |
Correct |
101 ms |
12888 KB |
n=2000 |
87 |
Correct |
106 ms |
13144 KB |
n=2000 |
88 |
Correct |
192 ms |
12888 KB |
n=2000 |
89 |
Correct |
196 ms |
12892 KB |
n=2000 |
90 |
Correct |
162 ms |
12892 KB |
n=2000 |
91 |
Correct |
270 ms |
13020 KB |
n=2000 |
92 |
Execution timed out |
4080 ms |
53864 KB |
Time limit exceeded |
93 |
Halted |
0 ms |
0 KB |
- |