#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 = 18;
int up[N][K], a[N], tin[N], tout[N], timer, m;
int n, q;
vector<int> g[N];
set<int> st1[N], st2[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;
}
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];
st1[a[i]].insert(i);
}
for (int i = 2;i <= m;i++) {
int x = Lca(a[i], a[i - 1]);
st2[x].insert(i);
}
while (q--) {
int t;
cin >> t;
if (t == 1) {
int i, v;
cin >> i >> v;
int lc;
if (i > 1) {
lc = Lca(a[i], a[i - 1]);
st2[lc].erase(i);
}
if (i < m) {
lc = Lca(a[i], a[i + 1]);
st2[lc].erase(i + 1);
}
st1[a[i]].erase(i);
a[i] = v;
st1[a[i]].insert(i);
if (i > 1) {
lc = Lca(a[i], a[i - 1]);
st2[lc].insert(i);
}
if (i < m) {
lc = Lca(a[i], a[i + 1]);
st2[lc].insert(i + 1);
}
}
else {
int l, r, v;
cin >> l >> r >> v;
int x = -1, y = -1;
auto u1 = st1[v].lower_bound(l);
auto u2 = st2[v].lower_bound(l + 1);
if (u1 != st1[v].end() && *u1 <= r)
x = y = *u1;
else if (u2 != st2[v].end() && *u2 <= r) {
y = *u2;
x = y - 1;
}
cout << x << ' ' << y << '\n';
}
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
29276 KB |
n=5 |
2 |
Correct |
7 ms |
29272 KB |
n=100 |
3 |
Correct |
7 ms |
29276 KB |
n=100 |
4 |
Correct |
8 ms |
29276 KB |
n=100 |
5 |
Correct |
8 ms |
29276 KB |
n=100 |
6 |
Correct |
8 ms |
29276 KB |
n=100 |
7 |
Correct |
7 ms |
29376 KB |
n=100 |
8 |
Correct |
7 ms |
29276 KB |
n=100 |
9 |
Correct |
8 ms |
29688 KB |
n=100 |
10 |
Correct |
9 ms |
29276 KB |
n=100 |
11 |
Correct |
8 ms |
29276 KB |
n=100 |
12 |
Correct |
8 ms |
29276 KB |
n=100 |
13 |
Correct |
9 ms |
29272 KB |
n=100 |
14 |
Correct |
8 ms |
29276 KB |
n=100 |
15 |
Correct |
7 ms |
29276 KB |
n=100 |
16 |
Correct |
8 ms |
29272 KB |
n=100 |
17 |
Correct |
7 ms |
29276 KB |
n=100 |
18 |
Correct |
8 ms |
29272 KB |
n=100 |
19 |
Correct |
9 ms |
29532 KB |
n=100 |
20 |
Correct |
7 ms |
29272 KB |
n=100 |
21 |
Correct |
7 ms |
29272 KB |
n=100 |
22 |
Correct |
8 ms |
29276 KB |
n=100 |
23 |
Correct |
7 ms |
29276 KB |
n=100 |
24 |
Correct |
8 ms |
29276 KB |
n=100 |
25 |
Correct |
8 ms |
29276 KB |
n=100 |
26 |
Correct |
8 ms |
29276 KB |
n=12 |
27 |
Correct |
7 ms |
29276 KB |
n=100 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
29276 KB |
n=5 |
2 |
Correct |
7 ms |
29272 KB |
n=100 |
3 |
Correct |
7 ms |
29276 KB |
n=100 |
4 |
Correct |
8 ms |
29276 KB |
n=100 |
5 |
Correct |
8 ms |
29276 KB |
n=100 |
6 |
Correct |
8 ms |
29276 KB |
n=100 |
7 |
Correct |
7 ms |
29376 KB |
n=100 |
8 |
Correct |
7 ms |
29276 KB |
n=100 |
9 |
Correct |
8 ms |
29688 KB |
n=100 |
10 |
Correct |
9 ms |
29276 KB |
n=100 |
11 |
Correct |
8 ms |
29276 KB |
n=100 |
12 |
Correct |
8 ms |
29276 KB |
n=100 |
13 |
Correct |
9 ms |
29272 KB |
n=100 |
14 |
Correct |
8 ms |
29276 KB |
n=100 |
15 |
Correct |
7 ms |
29276 KB |
n=100 |
16 |
Correct |
8 ms |
29272 KB |
n=100 |
17 |
Correct |
7 ms |
29276 KB |
n=100 |
18 |
Correct |
8 ms |
29272 KB |
n=100 |
19 |
Correct |
9 ms |
29532 KB |
n=100 |
20 |
Correct |
7 ms |
29272 KB |
n=100 |
21 |
Correct |
7 ms |
29272 KB |
n=100 |
22 |
Correct |
8 ms |
29276 KB |
n=100 |
23 |
Correct |
7 ms |
29276 KB |
n=100 |
24 |
Correct |
8 ms |
29276 KB |
n=100 |
25 |
Correct |
8 ms |
29276 KB |
n=100 |
26 |
Correct |
8 ms |
29276 KB |
n=12 |
27 |
Correct |
7 ms |
29276 KB |
n=100 |
28 |
Correct |
8 ms |
29272 KB |
n=500 |
29 |
Correct |
8 ms |
29276 KB |
n=500 |
30 |
Correct |
9 ms |
29532 KB |
n=500 |
31 |
Correct |
8 ms |
29276 KB |
n=500 |
32 |
Correct |
8 ms |
29276 KB |
n=500 |
33 |
Correct |
7 ms |
29276 KB |
n=500 |
34 |
Correct |
7 ms |
29276 KB |
n=500 |
35 |
Correct |
8 ms |
29372 KB |
n=500 |
36 |
Correct |
8 ms |
29276 KB |
n=500 |
37 |
Correct |
7 ms |
29272 KB |
n=500 |
38 |
Correct |
10 ms |
29788 KB |
n=500 |
39 |
Correct |
8 ms |
29272 KB |
n=500 |
40 |
Correct |
8 ms |
29276 KB |
n=500 |
41 |
Correct |
8 ms |
29276 KB |
n=500 |
42 |
Correct |
8 ms |
29276 KB |
n=500 |
43 |
Correct |
7 ms |
29276 KB |
n=500 |
44 |
Correct |
8 ms |
29276 KB |
n=500 |
45 |
Correct |
7 ms |
29528 KB |
n=500 |
46 |
Correct |
7 ms |
29276 KB |
n=500 |
47 |
Correct |
8 ms |
29364 KB |
n=500 |
48 |
Correct |
8 ms |
29428 KB |
n=500 |
49 |
Correct |
9 ms |
29276 KB |
n=500 |
50 |
Correct |
9 ms |
29276 KB |
n=500 |
51 |
Correct |
9 ms |
29272 KB |
n=500 |
52 |
Correct |
8 ms |
29276 KB |
n=500 |
53 |
Correct |
8 ms |
29276 KB |
n=500 |
54 |
Correct |
9 ms |
29276 KB |
n=500 |
55 |
Correct |
8 ms |
29388 KB |
n=278 |
56 |
Correct |
7 ms |
29276 KB |
n=500 |
57 |
Correct |
8 ms |
29272 KB |
n=500 |
58 |
Correct |
8 ms |
29276 KB |
n=500 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
29276 KB |
n=5 |
2 |
Correct |
7 ms |
29272 KB |
n=100 |
3 |
Correct |
7 ms |
29276 KB |
n=100 |
4 |
Correct |
8 ms |
29276 KB |
n=100 |
5 |
Correct |
8 ms |
29276 KB |
n=100 |
6 |
Correct |
8 ms |
29276 KB |
n=100 |
7 |
Correct |
7 ms |
29376 KB |
n=100 |
8 |
Correct |
7 ms |
29276 KB |
n=100 |
9 |
Correct |
8 ms |
29688 KB |
n=100 |
10 |
Correct |
9 ms |
29276 KB |
n=100 |
11 |
Correct |
8 ms |
29276 KB |
n=100 |
12 |
Correct |
8 ms |
29276 KB |
n=100 |
13 |
Correct |
9 ms |
29272 KB |
n=100 |
14 |
Correct |
8 ms |
29276 KB |
n=100 |
15 |
Correct |
7 ms |
29276 KB |
n=100 |
16 |
Correct |
8 ms |
29272 KB |
n=100 |
17 |
Correct |
7 ms |
29276 KB |
n=100 |
18 |
Correct |
8 ms |
29272 KB |
n=100 |
19 |
Correct |
9 ms |
29532 KB |
n=100 |
20 |
Correct |
7 ms |
29272 KB |
n=100 |
21 |
Correct |
7 ms |
29272 KB |
n=100 |
22 |
Correct |
8 ms |
29276 KB |
n=100 |
23 |
Correct |
7 ms |
29276 KB |
n=100 |
24 |
Correct |
8 ms |
29276 KB |
n=100 |
25 |
Correct |
8 ms |
29276 KB |
n=100 |
26 |
Correct |
8 ms |
29276 KB |
n=12 |
27 |
Correct |
7 ms |
29276 KB |
n=100 |
28 |
Correct |
8 ms |
29272 KB |
n=500 |
29 |
Correct |
8 ms |
29276 KB |
n=500 |
30 |
Correct |
9 ms |
29532 KB |
n=500 |
31 |
Correct |
8 ms |
29276 KB |
n=500 |
32 |
Correct |
8 ms |
29276 KB |
n=500 |
33 |
Correct |
7 ms |
29276 KB |
n=500 |
34 |
Correct |
7 ms |
29276 KB |
n=500 |
35 |
Correct |
8 ms |
29372 KB |
n=500 |
36 |
Correct |
8 ms |
29276 KB |
n=500 |
37 |
Correct |
7 ms |
29272 KB |
n=500 |
38 |
Correct |
10 ms |
29788 KB |
n=500 |
39 |
Correct |
8 ms |
29272 KB |
n=500 |
40 |
Correct |
8 ms |
29276 KB |
n=500 |
41 |
Correct |
8 ms |
29276 KB |
n=500 |
42 |
Correct |
8 ms |
29276 KB |
n=500 |
43 |
Correct |
7 ms |
29276 KB |
n=500 |
44 |
Correct |
8 ms |
29276 KB |
n=500 |
45 |
Correct |
7 ms |
29528 KB |
n=500 |
46 |
Correct |
7 ms |
29276 KB |
n=500 |
47 |
Correct |
8 ms |
29364 KB |
n=500 |
48 |
Correct |
8 ms |
29428 KB |
n=500 |
49 |
Correct |
9 ms |
29276 KB |
n=500 |
50 |
Correct |
9 ms |
29276 KB |
n=500 |
51 |
Correct |
9 ms |
29272 KB |
n=500 |
52 |
Correct |
8 ms |
29276 KB |
n=500 |
53 |
Correct |
8 ms |
29276 KB |
n=500 |
54 |
Correct |
9 ms |
29276 KB |
n=500 |
55 |
Correct |
8 ms |
29388 KB |
n=278 |
56 |
Correct |
7 ms |
29276 KB |
n=500 |
57 |
Correct |
8 ms |
29272 KB |
n=500 |
58 |
Correct |
8 ms |
29276 KB |
n=500 |
59 |
Correct |
9 ms |
29528 KB |
n=2000 |
60 |
Correct |
9 ms |
29588 KB |
n=2000 |
61 |
Correct |
9 ms |
29528 KB |
n=2000 |
62 |
Correct |
9 ms |
29532 KB |
n=2000 |
63 |
Correct |
10 ms |
29784 KB |
n=2000 |
64 |
Correct |
10 ms |
29532 KB |
n=2000 |
65 |
Correct |
10 ms |
29532 KB |
n=2000 |
66 |
Correct |
9 ms |
29532 KB |
n=2000 |
67 |
Correct |
10 ms |
29532 KB |
n=2000 |
68 |
Correct |
10 ms |
29528 KB |
n=2000 |
69 |
Correct |
10 ms |
29532 KB |
n=2000 |
70 |
Correct |
9 ms |
29528 KB |
n=2000 |
71 |
Correct |
10 ms |
29532 KB |
n=2000 |
72 |
Correct |
10 ms |
29532 KB |
n=2000 |
73 |
Correct |
9 ms |
29532 KB |
n=2000 |
74 |
Correct |
10 ms |
29528 KB |
n=1844 |
75 |
Correct |
10 ms |
29528 KB |
n=2000 |
76 |
Correct |
10 ms |
29532 KB |
n=2000 |
77 |
Correct |
10 ms |
29532 KB |
n=2000 |
78 |
Correct |
11 ms |
29532 KB |
n=2000 |
79 |
Correct |
10 ms |
29528 KB |
n=2000 |
80 |
Correct |
9 ms |
29532 KB |
n=2000 |
81 |
Correct |
9 ms |
29532 KB |
n=2000 |
82 |
Correct |
9 ms |
29532 KB |
n=2000 |
83 |
Correct |
9 ms |
29532 KB |
n=2000 |
84 |
Correct |
9 ms |
29532 KB |
n=2000 |
85 |
Correct |
11 ms |
29528 KB |
n=2000 |
86 |
Correct |
10 ms |
29656 KB |
n=2000 |
87 |
Correct |
10 ms |
29640 KB |
n=2000 |
88 |
Correct |
9 ms |
29532 KB |
n=2000 |
89 |
Correct |
10 ms |
29532 KB |
n=2000 |
90 |
Correct |
10 ms |
29712 KB |
n=2000 |
91 |
Correct |
10 ms |
29532 KB |
n=2000 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
29276 KB |
n=5 |
2 |
Correct |
7 ms |
29272 KB |
n=100 |
3 |
Correct |
7 ms |
29276 KB |
n=100 |
4 |
Correct |
8 ms |
29276 KB |
n=100 |
5 |
Correct |
8 ms |
29276 KB |
n=100 |
6 |
Correct |
8 ms |
29276 KB |
n=100 |
7 |
Correct |
7 ms |
29376 KB |
n=100 |
8 |
Correct |
7 ms |
29276 KB |
n=100 |
9 |
Correct |
8 ms |
29688 KB |
n=100 |
10 |
Correct |
9 ms |
29276 KB |
n=100 |
11 |
Correct |
8 ms |
29276 KB |
n=100 |
12 |
Correct |
8 ms |
29276 KB |
n=100 |
13 |
Correct |
9 ms |
29272 KB |
n=100 |
14 |
Correct |
8 ms |
29276 KB |
n=100 |
15 |
Correct |
7 ms |
29276 KB |
n=100 |
16 |
Correct |
8 ms |
29272 KB |
n=100 |
17 |
Correct |
7 ms |
29276 KB |
n=100 |
18 |
Correct |
8 ms |
29272 KB |
n=100 |
19 |
Correct |
9 ms |
29532 KB |
n=100 |
20 |
Correct |
7 ms |
29272 KB |
n=100 |
21 |
Correct |
7 ms |
29272 KB |
n=100 |
22 |
Correct |
8 ms |
29276 KB |
n=100 |
23 |
Correct |
7 ms |
29276 KB |
n=100 |
24 |
Correct |
8 ms |
29276 KB |
n=100 |
25 |
Correct |
8 ms |
29276 KB |
n=100 |
26 |
Correct |
8 ms |
29276 KB |
n=12 |
27 |
Correct |
7 ms |
29276 KB |
n=100 |
28 |
Correct |
8 ms |
29272 KB |
n=500 |
29 |
Correct |
8 ms |
29276 KB |
n=500 |
30 |
Correct |
9 ms |
29532 KB |
n=500 |
31 |
Correct |
8 ms |
29276 KB |
n=500 |
32 |
Correct |
8 ms |
29276 KB |
n=500 |
33 |
Correct |
7 ms |
29276 KB |
n=500 |
34 |
Correct |
7 ms |
29276 KB |
n=500 |
35 |
Correct |
8 ms |
29372 KB |
n=500 |
36 |
Correct |
8 ms |
29276 KB |
n=500 |
37 |
Correct |
7 ms |
29272 KB |
n=500 |
38 |
Correct |
10 ms |
29788 KB |
n=500 |
39 |
Correct |
8 ms |
29272 KB |
n=500 |
40 |
Correct |
8 ms |
29276 KB |
n=500 |
41 |
Correct |
8 ms |
29276 KB |
n=500 |
42 |
Correct |
8 ms |
29276 KB |
n=500 |
43 |
Correct |
7 ms |
29276 KB |
n=500 |
44 |
Correct |
8 ms |
29276 KB |
n=500 |
45 |
Correct |
7 ms |
29528 KB |
n=500 |
46 |
Correct |
7 ms |
29276 KB |
n=500 |
47 |
Correct |
8 ms |
29364 KB |
n=500 |
48 |
Correct |
8 ms |
29428 KB |
n=500 |
49 |
Correct |
9 ms |
29276 KB |
n=500 |
50 |
Correct |
9 ms |
29276 KB |
n=500 |
51 |
Correct |
9 ms |
29272 KB |
n=500 |
52 |
Correct |
8 ms |
29276 KB |
n=500 |
53 |
Correct |
8 ms |
29276 KB |
n=500 |
54 |
Correct |
9 ms |
29276 KB |
n=500 |
55 |
Correct |
8 ms |
29388 KB |
n=278 |
56 |
Correct |
7 ms |
29276 KB |
n=500 |
57 |
Correct |
8 ms |
29272 KB |
n=500 |
58 |
Correct |
8 ms |
29276 KB |
n=500 |
59 |
Correct |
9 ms |
29528 KB |
n=2000 |
60 |
Correct |
9 ms |
29588 KB |
n=2000 |
61 |
Correct |
9 ms |
29528 KB |
n=2000 |
62 |
Correct |
9 ms |
29532 KB |
n=2000 |
63 |
Correct |
10 ms |
29784 KB |
n=2000 |
64 |
Correct |
10 ms |
29532 KB |
n=2000 |
65 |
Correct |
10 ms |
29532 KB |
n=2000 |
66 |
Correct |
9 ms |
29532 KB |
n=2000 |
67 |
Correct |
10 ms |
29532 KB |
n=2000 |
68 |
Correct |
10 ms |
29528 KB |
n=2000 |
69 |
Correct |
10 ms |
29532 KB |
n=2000 |
70 |
Correct |
9 ms |
29528 KB |
n=2000 |
71 |
Correct |
10 ms |
29532 KB |
n=2000 |
72 |
Correct |
10 ms |
29532 KB |
n=2000 |
73 |
Correct |
9 ms |
29532 KB |
n=2000 |
74 |
Correct |
10 ms |
29528 KB |
n=1844 |
75 |
Correct |
10 ms |
29528 KB |
n=2000 |
76 |
Correct |
10 ms |
29532 KB |
n=2000 |
77 |
Correct |
10 ms |
29532 KB |
n=2000 |
78 |
Correct |
11 ms |
29532 KB |
n=2000 |
79 |
Correct |
10 ms |
29528 KB |
n=2000 |
80 |
Correct |
9 ms |
29532 KB |
n=2000 |
81 |
Correct |
9 ms |
29532 KB |
n=2000 |
82 |
Correct |
9 ms |
29532 KB |
n=2000 |
83 |
Correct |
9 ms |
29532 KB |
n=2000 |
84 |
Correct |
9 ms |
29532 KB |
n=2000 |
85 |
Correct |
11 ms |
29528 KB |
n=2000 |
86 |
Correct |
10 ms |
29656 KB |
n=2000 |
87 |
Correct |
10 ms |
29640 KB |
n=2000 |
88 |
Correct |
9 ms |
29532 KB |
n=2000 |
89 |
Correct |
10 ms |
29532 KB |
n=2000 |
90 |
Correct |
10 ms |
29712 KB |
n=2000 |
91 |
Correct |
10 ms |
29532 KB |
n=2000 |
92 |
Correct |
673 ms |
84688 KB |
n=200000 |
93 |
Correct |
819 ms |
91952 KB |
n=200000 |
94 |
Correct |
559 ms |
99136 KB |
n=200000 |
95 |
Correct |
574 ms |
90936 KB |
n=200000 |
96 |
Correct |
626 ms |
91032 KB |
n=200000 |
97 |
Correct |
847 ms |
95232 KB |
n=200000 |
98 |
Correct |
642 ms |
90984 KB |
n=200000 |
99 |
Correct |
692 ms |
91476 KB |
n=200000 |
100 |
Correct |
631 ms |
90908 KB |
n=200000 |
101 |
Correct |
523 ms |
99664 KB |
n=200000 |
102 |
Correct |
388 ms |
92364 KB |
n=200000 |
103 |
Correct |
365 ms |
92264 KB |
n=200000 |
104 |
Correct |
386 ms |
92160 KB |
n=200000 |
105 |
Correct |
356 ms |
92784 KB |
n=200000 |
106 |
Correct |
383 ms |
92752 KB |
n=200000 |
107 |
Correct |
359 ms |
92680 KB |
n=200000 |
108 |
Correct |
649 ms |
91240 KB |
n=200000 |
109 |
Correct |
636 ms |
91028 KB |
n=200000 |
110 |
Correct |
661 ms |
91256 KB |
n=200000 |
111 |
Correct |
631 ms |
90216 KB |
n=200000 |
112 |
Correct |
519 ms |
99104 KB |
n=200000 |
113 |
Correct |
833 ms |
94984 KB |
n=200000 |
114 |
Correct |
636 ms |
90304 KB |
n=200000 |
115 |
Correct |
966 ms |
93320 KB |
n=200000 |
116 |
Correct |
598 ms |
91448 KB |
n=200000 |
117 |
Correct |
518 ms |
99348 KB |
n=200000 |
118 |
Correct |
876 ms |
94036 KB |
n=200000 |
119 |
Correct |
612 ms |
91212 KB |
n=200000 |
120 |
Correct |
468 ms |
98752 KB |
n=200000 |
121 |
Correct |
447 ms |
99152 KB |
n=200000 |
122 |
Correct |
433 ms |
99068 KB |
n=200000 |
123 |
Correct |
447 ms |
92388 KB |
n=200000 |
124 |
Correct |
139 ms |
45904 KB |
n=25264 |