#include <bits/stdc++.h>
using namespace std;
// #define int long long
#define all(x) x.begin(), x.end()
const int N = 200005;
const int K = __lg(N) + 1;
int n, m, q;
vector<int> adj[N], deep(N);
int jump[K][N];
set<int> s1[N], s2[N];
void dfs(int k, int pa) {
jump[0][k] = pa;
for (int i = 1; i < K; i++) {
jump[i][k] = jump[i - 1][jump[i - 1][k]];
}
for (int j : adj[k]) {
if (j == pa) {
continue;
}
deep[j] = deep[k] + 1;
dfs(j, k);
}
}
int lca(int a, int b) {
if (deep[a] < deep[b]) {
swap(a, b);
}
int p = deep[a] - deep[b];
for (int i = 0; i < K; i++) {
if ((1 << i) & p) {
a = jump[i][a];
}
}
if (a == b) {
return a;
}
for (int i = K - 1; i >= 0; i--) {
if (jump[i][a] != jump[i][b]) {
a = jump[i][a];
b = jump[i][b];
}
}
return jump[0][a];
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m >> q;
for (int i = 1; i < n; i++) {
int a, b;
cin >> a >> b;
adj[a].push_back(b);
adj[b].push_back(a);
}
dfs(1, 1);
vector<int> v(m + 1);
for (int i = 1; i <= m; i++) {
cin >> v[i];
}
for (int i = 1; i <= m; i++) {
s1[v[i]].insert(i);
}
for (int i = 1; i < m; i++) {
s2[lca(v[i],v[i+1])].insert(i);
}
for (int i = 0; i < q; i++) {
int id;
cin >> id;
if (id == 1) {
int a, b;
cin >> a >> b;
s1[v[a]].erase(a);
if(a<m){
s2[lca(v[a],v[a+1])].erase(a);
}
if(a>1){
s2[lca(v[a-1],v[a])].erase(a-1);
}
v[a] = b;
s1[v[a]].insert(a);
if(a<m){
s2[lca(v[a],v[a+1])].insert(a);
}
if(a>1){
s2[lca(v[a-1],v[a])].insert(a-1);
}
}
else {
int l,r,v;cin>>l>>r>>v;
auto it1=s1[v].lower_bound(l);
if(it1!=s1[v].end()&&*it1<=r){
cout<<*it1<<' '<<*it1<<'\n';
continue;
}
auto it2=s2[v].lower_bound(l);
if(it2!=s2[v].end()&&*it2+1<=r){
cout<<*it2<<' '<<*it2+1<<'\n';
continue;
}
cout<<-1<<' '<<-1<<'\n';
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
38744 KB |
n=5 |
2 |
Correct |
7 ms |
38828 KB |
n=100 |
3 |
Correct |
7 ms |
38744 KB |
n=100 |
4 |
Correct |
7 ms |
38744 KB |
n=100 |
5 |
Correct |
7 ms |
38744 KB |
n=100 |
6 |
Correct |
8 ms |
38744 KB |
n=100 |
7 |
Correct |
7 ms |
38744 KB |
n=100 |
8 |
Correct |
7 ms |
38744 KB |
n=100 |
9 |
Correct |
7 ms |
38812 KB |
n=100 |
10 |
Correct |
7 ms |
38744 KB |
n=100 |
11 |
Correct |
7 ms |
38744 KB |
n=100 |
12 |
Correct |
8 ms |
38744 KB |
n=100 |
13 |
Correct |
7 ms |
38748 KB |
n=100 |
14 |
Correct |
7 ms |
38744 KB |
n=100 |
15 |
Correct |
7 ms |
38784 KB |
n=100 |
16 |
Correct |
7 ms |
38808 KB |
n=100 |
17 |
Correct |
7 ms |
38744 KB |
n=100 |
18 |
Correct |
7 ms |
39000 KB |
n=100 |
19 |
Correct |
7 ms |
38744 KB |
n=100 |
20 |
Correct |
7 ms |
38744 KB |
n=100 |
21 |
Correct |
8 ms |
38748 KB |
n=100 |
22 |
Correct |
7 ms |
38744 KB |
n=100 |
23 |
Correct |
8 ms |
39000 KB |
n=100 |
24 |
Correct |
7 ms |
38744 KB |
n=100 |
25 |
Correct |
7 ms |
38744 KB |
n=100 |
26 |
Correct |
7 ms |
38744 KB |
n=12 |
27 |
Correct |
7 ms |
38748 KB |
n=100 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
38744 KB |
n=5 |
2 |
Correct |
7 ms |
38828 KB |
n=100 |
3 |
Correct |
7 ms |
38744 KB |
n=100 |
4 |
Correct |
7 ms |
38744 KB |
n=100 |
5 |
Correct |
7 ms |
38744 KB |
n=100 |
6 |
Correct |
8 ms |
38744 KB |
n=100 |
7 |
Correct |
7 ms |
38744 KB |
n=100 |
8 |
Correct |
7 ms |
38744 KB |
n=100 |
9 |
Correct |
7 ms |
38812 KB |
n=100 |
10 |
Correct |
7 ms |
38744 KB |
n=100 |
11 |
Correct |
7 ms |
38744 KB |
n=100 |
12 |
Correct |
8 ms |
38744 KB |
n=100 |
13 |
Correct |
7 ms |
38748 KB |
n=100 |
14 |
Correct |
7 ms |
38744 KB |
n=100 |
15 |
Correct |
7 ms |
38784 KB |
n=100 |
16 |
Correct |
7 ms |
38808 KB |
n=100 |
17 |
Correct |
7 ms |
38744 KB |
n=100 |
18 |
Correct |
7 ms |
39000 KB |
n=100 |
19 |
Correct |
7 ms |
38744 KB |
n=100 |
20 |
Correct |
7 ms |
38744 KB |
n=100 |
21 |
Correct |
8 ms |
38748 KB |
n=100 |
22 |
Correct |
7 ms |
38744 KB |
n=100 |
23 |
Correct |
8 ms |
39000 KB |
n=100 |
24 |
Correct |
7 ms |
38744 KB |
n=100 |
25 |
Correct |
7 ms |
38744 KB |
n=100 |
26 |
Correct |
7 ms |
38744 KB |
n=12 |
27 |
Correct |
7 ms |
38748 KB |
n=100 |
28 |
Correct |
7 ms |
38744 KB |
n=500 |
29 |
Correct |
8 ms |
38744 KB |
n=500 |
30 |
Correct |
8 ms |
38748 KB |
n=500 |
31 |
Correct |
8 ms |
38744 KB |
n=500 |
32 |
Correct |
7 ms |
38744 KB |
n=500 |
33 |
Correct |
8 ms |
38744 KB |
n=500 |
34 |
Correct |
8 ms |
38744 KB |
n=500 |
35 |
Correct |
9 ms |
38820 KB |
n=500 |
36 |
Correct |
7 ms |
38744 KB |
n=500 |
37 |
Correct |
7 ms |
38744 KB |
n=500 |
38 |
Correct |
7 ms |
38744 KB |
n=500 |
39 |
Correct |
7 ms |
38748 KB |
n=500 |
40 |
Correct |
7 ms |
38744 KB |
n=500 |
41 |
Correct |
8 ms |
38744 KB |
n=500 |
42 |
Correct |
8 ms |
38744 KB |
n=500 |
43 |
Correct |
8 ms |
38744 KB |
n=500 |
44 |
Correct |
8 ms |
38744 KB |
n=500 |
45 |
Correct |
8 ms |
39004 KB |
n=500 |
46 |
Correct |
8 ms |
38744 KB |
n=500 |
47 |
Correct |
7 ms |
38744 KB |
n=500 |
48 |
Correct |
8 ms |
39000 KB |
n=500 |
49 |
Correct |
7 ms |
38748 KB |
n=500 |
50 |
Correct |
7 ms |
38744 KB |
n=500 |
51 |
Correct |
8 ms |
38748 KB |
n=500 |
52 |
Correct |
8 ms |
38744 KB |
n=500 |
53 |
Correct |
8 ms |
38744 KB |
n=500 |
54 |
Correct |
7 ms |
38744 KB |
n=500 |
55 |
Correct |
7 ms |
38744 KB |
n=278 |
56 |
Correct |
8 ms |
38744 KB |
n=500 |
57 |
Correct |
8 ms |
39000 KB |
n=500 |
58 |
Correct |
7 ms |
38748 KB |
n=500 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
38744 KB |
n=5 |
2 |
Correct |
7 ms |
38828 KB |
n=100 |
3 |
Correct |
7 ms |
38744 KB |
n=100 |
4 |
Correct |
7 ms |
38744 KB |
n=100 |
5 |
Correct |
7 ms |
38744 KB |
n=100 |
6 |
Correct |
8 ms |
38744 KB |
n=100 |
7 |
Correct |
7 ms |
38744 KB |
n=100 |
8 |
Correct |
7 ms |
38744 KB |
n=100 |
9 |
Correct |
7 ms |
38812 KB |
n=100 |
10 |
Correct |
7 ms |
38744 KB |
n=100 |
11 |
Correct |
7 ms |
38744 KB |
n=100 |
12 |
Correct |
8 ms |
38744 KB |
n=100 |
13 |
Correct |
7 ms |
38748 KB |
n=100 |
14 |
Correct |
7 ms |
38744 KB |
n=100 |
15 |
Correct |
7 ms |
38784 KB |
n=100 |
16 |
Correct |
7 ms |
38808 KB |
n=100 |
17 |
Correct |
7 ms |
38744 KB |
n=100 |
18 |
Correct |
7 ms |
39000 KB |
n=100 |
19 |
Correct |
7 ms |
38744 KB |
n=100 |
20 |
Correct |
7 ms |
38744 KB |
n=100 |
21 |
Correct |
8 ms |
38748 KB |
n=100 |
22 |
Correct |
7 ms |
38744 KB |
n=100 |
23 |
Correct |
8 ms |
39000 KB |
n=100 |
24 |
Correct |
7 ms |
38744 KB |
n=100 |
25 |
Correct |
7 ms |
38744 KB |
n=100 |
26 |
Correct |
7 ms |
38744 KB |
n=12 |
27 |
Correct |
7 ms |
38748 KB |
n=100 |
28 |
Correct |
7 ms |
38744 KB |
n=500 |
29 |
Correct |
8 ms |
38744 KB |
n=500 |
30 |
Correct |
8 ms |
38748 KB |
n=500 |
31 |
Correct |
8 ms |
38744 KB |
n=500 |
32 |
Correct |
7 ms |
38744 KB |
n=500 |
33 |
Correct |
8 ms |
38744 KB |
n=500 |
34 |
Correct |
8 ms |
38744 KB |
n=500 |
35 |
Correct |
9 ms |
38820 KB |
n=500 |
36 |
Correct |
7 ms |
38744 KB |
n=500 |
37 |
Correct |
7 ms |
38744 KB |
n=500 |
38 |
Correct |
7 ms |
38744 KB |
n=500 |
39 |
Correct |
7 ms |
38748 KB |
n=500 |
40 |
Correct |
7 ms |
38744 KB |
n=500 |
41 |
Correct |
8 ms |
38744 KB |
n=500 |
42 |
Correct |
8 ms |
38744 KB |
n=500 |
43 |
Correct |
8 ms |
38744 KB |
n=500 |
44 |
Correct |
8 ms |
38744 KB |
n=500 |
45 |
Correct |
8 ms |
39004 KB |
n=500 |
46 |
Correct |
8 ms |
38744 KB |
n=500 |
47 |
Correct |
7 ms |
38744 KB |
n=500 |
48 |
Correct |
8 ms |
39000 KB |
n=500 |
49 |
Correct |
7 ms |
38748 KB |
n=500 |
50 |
Correct |
7 ms |
38744 KB |
n=500 |
51 |
Correct |
8 ms |
38748 KB |
n=500 |
52 |
Correct |
8 ms |
38744 KB |
n=500 |
53 |
Correct |
8 ms |
38744 KB |
n=500 |
54 |
Correct |
7 ms |
38744 KB |
n=500 |
55 |
Correct |
7 ms |
38744 KB |
n=278 |
56 |
Correct |
8 ms |
38744 KB |
n=500 |
57 |
Correct |
8 ms |
39000 KB |
n=500 |
58 |
Correct |
7 ms |
38748 KB |
n=500 |
59 |
Correct |
9 ms |
39000 KB |
n=2000 |
60 |
Correct |
9 ms |
39004 KB |
n=2000 |
61 |
Correct |
10 ms |
39000 KB |
n=2000 |
62 |
Correct |
9 ms |
39000 KB |
n=2000 |
63 |
Correct |
9 ms |
39000 KB |
n=2000 |
64 |
Correct |
9 ms |
39000 KB |
n=2000 |
65 |
Correct |
9 ms |
39000 KB |
n=2000 |
66 |
Correct |
9 ms |
39000 KB |
n=2000 |
67 |
Correct |
9 ms |
39000 KB |
n=2000 |
68 |
Correct |
10 ms |
39000 KB |
n=2000 |
69 |
Correct |
9 ms |
39000 KB |
n=2000 |
70 |
Correct |
9 ms |
39000 KB |
n=2000 |
71 |
Correct |
9 ms |
39000 KB |
n=2000 |
72 |
Correct |
9 ms |
39000 KB |
n=2000 |
73 |
Correct |
9 ms |
39000 KB |
n=2000 |
74 |
Correct |
9 ms |
39000 KB |
n=1844 |
75 |
Correct |
9 ms |
39000 KB |
n=2000 |
76 |
Correct |
9 ms |
39000 KB |
n=2000 |
77 |
Correct |
9 ms |
39004 KB |
n=2000 |
78 |
Correct |
9 ms |
39000 KB |
n=2000 |
79 |
Correct |
9 ms |
39000 KB |
n=2000 |
80 |
Correct |
9 ms |
39000 KB |
n=2000 |
81 |
Correct |
10 ms |
39000 KB |
n=2000 |
82 |
Correct |
9 ms |
39000 KB |
n=2000 |
83 |
Correct |
9 ms |
39000 KB |
n=2000 |
84 |
Correct |
9 ms |
39000 KB |
n=2000 |
85 |
Correct |
9 ms |
39000 KB |
n=2000 |
86 |
Correct |
9 ms |
39000 KB |
n=2000 |
87 |
Correct |
9 ms |
39000 KB |
n=2000 |
88 |
Correct |
9 ms |
39000 KB |
n=2000 |
89 |
Correct |
9 ms |
39000 KB |
n=2000 |
90 |
Correct |
9 ms |
39000 KB |
n=2000 |
91 |
Correct |
9 ms |
39000 KB |
n=2000 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
38744 KB |
n=5 |
2 |
Correct |
7 ms |
38828 KB |
n=100 |
3 |
Correct |
7 ms |
38744 KB |
n=100 |
4 |
Correct |
7 ms |
38744 KB |
n=100 |
5 |
Correct |
7 ms |
38744 KB |
n=100 |
6 |
Correct |
8 ms |
38744 KB |
n=100 |
7 |
Correct |
7 ms |
38744 KB |
n=100 |
8 |
Correct |
7 ms |
38744 KB |
n=100 |
9 |
Correct |
7 ms |
38812 KB |
n=100 |
10 |
Correct |
7 ms |
38744 KB |
n=100 |
11 |
Correct |
7 ms |
38744 KB |
n=100 |
12 |
Correct |
8 ms |
38744 KB |
n=100 |
13 |
Correct |
7 ms |
38748 KB |
n=100 |
14 |
Correct |
7 ms |
38744 KB |
n=100 |
15 |
Correct |
7 ms |
38784 KB |
n=100 |
16 |
Correct |
7 ms |
38808 KB |
n=100 |
17 |
Correct |
7 ms |
38744 KB |
n=100 |
18 |
Correct |
7 ms |
39000 KB |
n=100 |
19 |
Correct |
7 ms |
38744 KB |
n=100 |
20 |
Correct |
7 ms |
38744 KB |
n=100 |
21 |
Correct |
8 ms |
38748 KB |
n=100 |
22 |
Correct |
7 ms |
38744 KB |
n=100 |
23 |
Correct |
8 ms |
39000 KB |
n=100 |
24 |
Correct |
7 ms |
38744 KB |
n=100 |
25 |
Correct |
7 ms |
38744 KB |
n=100 |
26 |
Correct |
7 ms |
38744 KB |
n=12 |
27 |
Correct |
7 ms |
38748 KB |
n=100 |
28 |
Correct |
7 ms |
38744 KB |
n=500 |
29 |
Correct |
8 ms |
38744 KB |
n=500 |
30 |
Correct |
8 ms |
38748 KB |
n=500 |
31 |
Correct |
8 ms |
38744 KB |
n=500 |
32 |
Correct |
7 ms |
38744 KB |
n=500 |
33 |
Correct |
8 ms |
38744 KB |
n=500 |
34 |
Correct |
8 ms |
38744 KB |
n=500 |
35 |
Correct |
9 ms |
38820 KB |
n=500 |
36 |
Correct |
7 ms |
38744 KB |
n=500 |
37 |
Correct |
7 ms |
38744 KB |
n=500 |
38 |
Correct |
7 ms |
38744 KB |
n=500 |
39 |
Correct |
7 ms |
38748 KB |
n=500 |
40 |
Correct |
7 ms |
38744 KB |
n=500 |
41 |
Correct |
8 ms |
38744 KB |
n=500 |
42 |
Correct |
8 ms |
38744 KB |
n=500 |
43 |
Correct |
8 ms |
38744 KB |
n=500 |
44 |
Correct |
8 ms |
38744 KB |
n=500 |
45 |
Correct |
8 ms |
39004 KB |
n=500 |
46 |
Correct |
8 ms |
38744 KB |
n=500 |
47 |
Correct |
7 ms |
38744 KB |
n=500 |
48 |
Correct |
8 ms |
39000 KB |
n=500 |
49 |
Correct |
7 ms |
38748 KB |
n=500 |
50 |
Correct |
7 ms |
38744 KB |
n=500 |
51 |
Correct |
8 ms |
38748 KB |
n=500 |
52 |
Correct |
8 ms |
38744 KB |
n=500 |
53 |
Correct |
8 ms |
38744 KB |
n=500 |
54 |
Correct |
7 ms |
38744 KB |
n=500 |
55 |
Correct |
7 ms |
38744 KB |
n=278 |
56 |
Correct |
8 ms |
38744 KB |
n=500 |
57 |
Correct |
8 ms |
39000 KB |
n=500 |
58 |
Correct |
7 ms |
38748 KB |
n=500 |
59 |
Correct |
9 ms |
39000 KB |
n=2000 |
60 |
Correct |
9 ms |
39004 KB |
n=2000 |
61 |
Correct |
10 ms |
39000 KB |
n=2000 |
62 |
Correct |
9 ms |
39000 KB |
n=2000 |
63 |
Correct |
9 ms |
39000 KB |
n=2000 |
64 |
Correct |
9 ms |
39000 KB |
n=2000 |
65 |
Correct |
9 ms |
39000 KB |
n=2000 |
66 |
Correct |
9 ms |
39000 KB |
n=2000 |
67 |
Correct |
9 ms |
39000 KB |
n=2000 |
68 |
Correct |
10 ms |
39000 KB |
n=2000 |
69 |
Correct |
9 ms |
39000 KB |
n=2000 |
70 |
Correct |
9 ms |
39000 KB |
n=2000 |
71 |
Correct |
9 ms |
39000 KB |
n=2000 |
72 |
Correct |
9 ms |
39000 KB |
n=2000 |
73 |
Correct |
9 ms |
39000 KB |
n=2000 |
74 |
Correct |
9 ms |
39000 KB |
n=1844 |
75 |
Correct |
9 ms |
39000 KB |
n=2000 |
76 |
Correct |
9 ms |
39000 KB |
n=2000 |
77 |
Correct |
9 ms |
39004 KB |
n=2000 |
78 |
Correct |
9 ms |
39000 KB |
n=2000 |
79 |
Correct |
9 ms |
39000 KB |
n=2000 |
80 |
Correct |
9 ms |
39000 KB |
n=2000 |
81 |
Correct |
10 ms |
39000 KB |
n=2000 |
82 |
Correct |
9 ms |
39000 KB |
n=2000 |
83 |
Correct |
9 ms |
39000 KB |
n=2000 |
84 |
Correct |
9 ms |
39000 KB |
n=2000 |
85 |
Correct |
9 ms |
39000 KB |
n=2000 |
86 |
Correct |
9 ms |
39000 KB |
n=2000 |
87 |
Correct |
9 ms |
39000 KB |
n=2000 |
88 |
Correct |
9 ms |
39000 KB |
n=2000 |
89 |
Correct |
9 ms |
39000 KB |
n=2000 |
90 |
Correct |
9 ms |
39000 KB |
n=2000 |
91 |
Correct |
9 ms |
39000 KB |
n=2000 |
92 |
Correct |
597 ms |
72992 KB |
n=200000 |
93 |
Correct |
760 ms |
78252 KB |
n=200000 |
94 |
Correct |
602 ms |
81228 KB |
n=200000 |
95 |
Correct |
561 ms |
73080 KB |
n=200000 |
96 |
Correct |
522 ms |
72888 KB |
n=200000 |
97 |
Correct |
748 ms |
77136 KB |
n=200000 |
98 |
Correct |
524 ms |
73156 KB |
n=200000 |
99 |
Correct |
704 ms |
73036 KB |
n=200000 |
100 |
Correct |
546 ms |
73012 KB |
n=200000 |
101 |
Correct |
612 ms |
82480 KB |
n=200000 |
102 |
Correct |
253 ms |
74064 KB |
n=200000 |
103 |
Correct |
254 ms |
74092 KB |
n=200000 |
104 |
Correct |
290 ms |
73976 KB |
n=200000 |
105 |
Correct |
256 ms |
74320 KB |
n=200000 |
106 |
Correct |
286 ms |
74320 KB |
n=200000 |
107 |
Correct |
319 ms |
74320 KB |
n=200000 |
108 |
Correct |
600 ms |
73040 KB |
n=200000 |
109 |
Correct |
666 ms |
72896 KB |
n=200000 |
110 |
Correct |
593 ms |
73016 KB |
n=200000 |
111 |
Correct |
529 ms |
72512 KB |
n=200000 |
112 |
Correct |
674 ms |
81468 KB |
n=200000 |
113 |
Correct |
680 ms |
77112 KB |
n=200000 |
114 |
Correct |
483 ms |
72464 KB |
n=200000 |
115 |
Correct |
714 ms |
74956 KB |
n=200000 |
116 |
Correct |
526 ms |
73092 KB |
n=200000 |
117 |
Correct |
696 ms |
81848 KB |
n=200000 |
118 |
Correct |
688 ms |
76056 KB |
n=200000 |
119 |
Correct |
523 ms |
73012 KB |
n=200000 |
120 |
Correct |
566 ms |
81548 KB |
n=200000 |
121 |
Correct |
584 ms |
81588 KB |
n=200000 |
122 |
Correct |
572 ms |
81744 KB |
n=200000 |
123 |
Correct |
343 ms |
74568 KB |
n=200000 |
124 |
Correct |
130 ms |
51512 KB |
n=25264 |