#include <bits/stdc++.h>
using namespace std;
vector<int> haha[200001];
int bruh[200001][18];
vector<int> dep(200001);
long long lca(long long a, long long b) {
if(dep[a] < dep[b]) {
swap(a,b);
}
long long c = dep[a]-dep[b];
for(long long i = 17; i >= 0; i--) {
if((1 << i)&c) {
a = bruh[a][i];
}
}
for(long long i = 17; i >= 0; i--) {
if(bruh[a][i] != -1 && bruh[a][i] != bruh[b][i]) {
a = bruh[a][i];
b = bruh[b][i];
}
}
if(a == b) {
return a;
}
else {
return bruh[a][0];
}
}
void dfs(long long a, long long t, long long d) {
bruh[a][0] = t;
dep[a] = d;
for(long long i = 0; i < haha[a].size(); i++) {
if(haha[a][i] != t) {
dfs(haha[a][i],a,d+1);
}
}
}
multiset<int> wow[200001];
multiset<int> yay[200001];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n,m,q,a,b,z,l,r;
cin >> n >> m >> q;
for(int i = 0; i < n-1; i++) {
cin >> a >> b;
haha[a].push_back(b);
haha[b].push_back(a);
}
dfs(1,-1,0);
for(long long i = 1; i < 18; i++) {
for(long long j = 1; j <= n; j++) {
if(bruh[j][i-1] == -1) {
bruh[j][i] = -1;
}
else {
bruh[j][i] = bruh[bruh[j][i-1]][i-1];
}
}
}
vector<int> wut(m+1);
for(int i = 1; i <= m; i++) {
cin >> wut[i];
yay[wut[i]].insert(i);
}
for(int i = 1; i < m; i++) {
wow[lca(wut[i],wut[i+1])].insert(i);
}
for(int i = 0; i < q; i++) {
cin >> z;
if(z == 1) {
cin >> a >> b;
yay[wut[a]].erase(a);
yay[b].insert(a);
if(a > 1) {
wow[lca(wut[a],wut[a-1])].erase(a-1);
wow[lca(b,wut[a-1])].insert(a-1);
}
if(a < m) {
wow[lca(wut[a],wut[a+1])].erase(a);
wow[lca(b,wut[a+1])].insert(a);
}
wut[a] = b;
}
else {
cin >> l >> r >> a;
auto d = yay[a].lower_bound(l);
if(yay[a].empty() || d == yay[a].end() || (*d) > r) {
auto e = wow[a].lower_bound(l);
if(wow[a].empty() || e == wow[a].end() || (*e) >= r) {
cout << -1 << " " << -1 << "\n";
}
else {
cout << (*e) << " " << (*e)+1 << "\n";
}
}
else {
cout << (*d) << " " << (*d) << "\n";
}
}
}
return 0;
}
Compilation message
treearray.cpp: In function 'void dfs(long long int, long long int, long long int)':
treearray.cpp:35:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | for(long long i = 0; i < haha[a].size(); i++) {
| ~~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
28508 KB |
n=5 |
2 |
Correct |
7 ms |
28508 KB |
n=100 |
3 |
Correct |
6 ms |
28528 KB |
n=100 |
4 |
Correct |
5 ms |
28508 KB |
n=100 |
5 |
Correct |
6 ms |
28508 KB |
n=100 |
6 |
Correct |
6 ms |
28504 KB |
n=100 |
7 |
Correct |
6 ms |
28508 KB |
n=100 |
8 |
Correct |
6 ms |
28504 KB |
n=100 |
9 |
Correct |
5 ms |
28504 KB |
n=100 |
10 |
Correct |
5 ms |
28508 KB |
n=100 |
11 |
Correct |
6 ms |
28508 KB |
n=100 |
12 |
Correct |
6 ms |
28504 KB |
n=100 |
13 |
Correct |
8 ms |
28508 KB |
n=100 |
14 |
Correct |
7 ms |
28764 KB |
n=100 |
15 |
Correct |
6 ms |
28508 KB |
n=100 |
16 |
Correct |
6 ms |
28508 KB |
n=100 |
17 |
Correct |
6 ms |
28504 KB |
n=100 |
18 |
Correct |
6 ms |
28508 KB |
n=100 |
19 |
Correct |
6 ms |
28508 KB |
n=100 |
20 |
Correct |
6 ms |
28508 KB |
n=100 |
21 |
Correct |
6 ms |
28504 KB |
n=100 |
22 |
Correct |
6 ms |
28508 KB |
n=100 |
23 |
Correct |
6 ms |
28508 KB |
n=100 |
24 |
Correct |
6 ms |
28504 KB |
n=100 |
25 |
Correct |
6 ms |
28508 KB |
n=100 |
26 |
Correct |
6 ms |
28568 KB |
n=12 |
27 |
Correct |
6 ms |
28508 KB |
n=100 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
28508 KB |
n=5 |
2 |
Correct |
7 ms |
28508 KB |
n=100 |
3 |
Correct |
6 ms |
28528 KB |
n=100 |
4 |
Correct |
5 ms |
28508 KB |
n=100 |
5 |
Correct |
6 ms |
28508 KB |
n=100 |
6 |
Correct |
6 ms |
28504 KB |
n=100 |
7 |
Correct |
6 ms |
28508 KB |
n=100 |
8 |
Correct |
6 ms |
28504 KB |
n=100 |
9 |
Correct |
5 ms |
28504 KB |
n=100 |
10 |
Correct |
5 ms |
28508 KB |
n=100 |
11 |
Correct |
6 ms |
28508 KB |
n=100 |
12 |
Correct |
6 ms |
28504 KB |
n=100 |
13 |
Correct |
8 ms |
28508 KB |
n=100 |
14 |
Correct |
7 ms |
28764 KB |
n=100 |
15 |
Correct |
6 ms |
28508 KB |
n=100 |
16 |
Correct |
6 ms |
28508 KB |
n=100 |
17 |
Correct |
6 ms |
28504 KB |
n=100 |
18 |
Correct |
6 ms |
28508 KB |
n=100 |
19 |
Correct |
6 ms |
28508 KB |
n=100 |
20 |
Correct |
6 ms |
28508 KB |
n=100 |
21 |
Correct |
6 ms |
28504 KB |
n=100 |
22 |
Correct |
6 ms |
28508 KB |
n=100 |
23 |
Correct |
6 ms |
28508 KB |
n=100 |
24 |
Correct |
6 ms |
28504 KB |
n=100 |
25 |
Correct |
6 ms |
28508 KB |
n=100 |
26 |
Correct |
6 ms |
28568 KB |
n=12 |
27 |
Correct |
6 ms |
28508 KB |
n=100 |
28 |
Correct |
6 ms |
28508 KB |
n=500 |
29 |
Correct |
6 ms |
28504 KB |
n=500 |
30 |
Correct |
6 ms |
28584 KB |
n=500 |
31 |
Correct |
6 ms |
28508 KB |
n=500 |
32 |
Correct |
6 ms |
28504 KB |
n=500 |
33 |
Correct |
6 ms |
28508 KB |
n=500 |
34 |
Correct |
6 ms |
28504 KB |
n=500 |
35 |
Correct |
6 ms |
28508 KB |
n=500 |
36 |
Correct |
6 ms |
28508 KB |
n=500 |
37 |
Correct |
6 ms |
28508 KB |
n=500 |
38 |
Correct |
7 ms |
28508 KB |
n=500 |
39 |
Correct |
7 ms |
28504 KB |
n=500 |
40 |
Correct |
6 ms |
28508 KB |
n=500 |
41 |
Correct |
6 ms |
28504 KB |
n=500 |
42 |
Correct |
6 ms |
28508 KB |
n=500 |
43 |
Correct |
6 ms |
28508 KB |
n=500 |
44 |
Correct |
6 ms |
28504 KB |
n=500 |
45 |
Correct |
6 ms |
28508 KB |
n=500 |
46 |
Correct |
6 ms |
28508 KB |
n=500 |
47 |
Correct |
6 ms |
28508 KB |
n=500 |
48 |
Correct |
6 ms |
28508 KB |
n=500 |
49 |
Correct |
6 ms |
28508 KB |
n=500 |
50 |
Correct |
6 ms |
28508 KB |
n=500 |
51 |
Correct |
6 ms |
28508 KB |
n=500 |
52 |
Correct |
6 ms |
28508 KB |
n=500 |
53 |
Correct |
6 ms |
28508 KB |
n=500 |
54 |
Correct |
7 ms |
28508 KB |
n=500 |
55 |
Correct |
6 ms |
28504 KB |
n=278 |
56 |
Correct |
6 ms |
28508 KB |
n=500 |
57 |
Correct |
6 ms |
28504 KB |
n=500 |
58 |
Correct |
6 ms |
28504 KB |
n=500 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
28508 KB |
n=5 |
2 |
Correct |
7 ms |
28508 KB |
n=100 |
3 |
Correct |
6 ms |
28528 KB |
n=100 |
4 |
Correct |
5 ms |
28508 KB |
n=100 |
5 |
Correct |
6 ms |
28508 KB |
n=100 |
6 |
Correct |
6 ms |
28504 KB |
n=100 |
7 |
Correct |
6 ms |
28508 KB |
n=100 |
8 |
Correct |
6 ms |
28504 KB |
n=100 |
9 |
Correct |
5 ms |
28504 KB |
n=100 |
10 |
Correct |
5 ms |
28508 KB |
n=100 |
11 |
Correct |
6 ms |
28508 KB |
n=100 |
12 |
Correct |
6 ms |
28504 KB |
n=100 |
13 |
Correct |
8 ms |
28508 KB |
n=100 |
14 |
Correct |
7 ms |
28764 KB |
n=100 |
15 |
Correct |
6 ms |
28508 KB |
n=100 |
16 |
Correct |
6 ms |
28508 KB |
n=100 |
17 |
Correct |
6 ms |
28504 KB |
n=100 |
18 |
Correct |
6 ms |
28508 KB |
n=100 |
19 |
Correct |
6 ms |
28508 KB |
n=100 |
20 |
Correct |
6 ms |
28508 KB |
n=100 |
21 |
Correct |
6 ms |
28504 KB |
n=100 |
22 |
Correct |
6 ms |
28508 KB |
n=100 |
23 |
Correct |
6 ms |
28508 KB |
n=100 |
24 |
Correct |
6 ms |
28504 KB |
n=100 |
25 |
Correct |
6 ms |
28508 KB |
n=100 |
26 |
Correct |
6 ms |
28568 KB |
n=12 |
27 |
Correct |
6 ms |
28508 KB |
n=100 |
28 |
Correct |
6 ms |
28508 KB |
n=500 |
29 |
Correct |
6 ms |
28504 KB |
n=500 |
30 |
Correct |
6 ms |
28584 KB |
n=500 |
31 |
Correct |
6 ms |
28508 KB |
n=500 |
32 |
Correct |
6 ms |
28504 KB |
n=500 |
33 |
Correct |
6 ms |
28508 KB |
n=500 |
34 |
Correct |
6 ms |
28504 KB |
n=500 |
35 |
Correct |
6 ms |
28508 KB |
n=500 |
36 |
Correct |
6 ms |
28508 KB |
n=500 |
37 |
Correct |
6 ms |
28508 KB |
n=500 |
38 |
Correct |
7 ms |
28508 KB |
n=500 |
39 |
Correct |
7 ms |
28504 KB |
n=500 |
40 |
Correct |
6 ms |
28508 KB |
n=500 |
41 |
Correct |
6 ms |
28504 KB |
n=500 |
42 |
Correct |
6 ms |
28508 KB |
n=500 |
43 |
Correct |
6 ms |
28508 KB |
n=500 |
44 |
Correct |
6 ms |
28504 KB |
n=500 |
45 |
Correct |
6 ms |
28508 KB |
n=500 |
46 |
Correct |
6 ms |
28508 KB |
n=500 |
47 |
Correct |
6 ms |
28508 KB |
n=500 |
48 |
Correct |
6 ms |
28508 KB |
n=500 |
49 |
Correct |
6 ms |
28508 KB |
n=500 |
50 |
Correct |
6 ms |
28508 KB |
n=500 |
51 |
Correct |
6 ms |
28508 KB |
n=500 |
52 |
Correct |
6 ms |
28508 KB |
n=500 |
53 |
Correct |
6 ms |
28508 KB |
n=500 |
54 |
Correct |
7 ms |
28508 KB |
n=500 |
55 |
Correct |
6 ms |
28504 KB |
n=278 |
56 |
Correct |
6 ms |
28508 KB |
n=500 |
57 |
Correct |
6 ms |
28504 KB |
n=500 |
58 |
Correct |
6 ms |
28504 KB |
n=500 |
59 |
Correct |
8 ms |
28764 KB |
n=2000 |
60 |
Correct |
8 ms |
28764 KB |
n=2000 |
61 |
Correct |
8 ms |
28764 KB |
n=2000 |
62 |
Correct |
10 ms |
28760 KB |
n=2000 |
63 |
Correct |
10 ms |
28788 KB |
n=2000 |
64 |
Correct |
10 ms |
28764 KB |
n=2000 |
65 |
Correct |
8 ms |
28760 KB |
n=2000 |
66 |
Correct |
8 ms |
28760 KB |
n=2000 |
67 |
Correct |
9 ms |
28764 KB |
n=2000 |
68 |
Correct |
8 ms |
28764 KB |
n=2000 |
69 |
Correct |
7 ms |
28676 KB |
n=2000 |
70 |
Correct |
7 ms |
28764 KB |
n=2000 |
71 |
Correct |
8 ms |
28764 KB |
n=2000 |
72 |
Correct |
7 ms |
28764 KB |
n=2000 |
73 |
Correct |
8 ms |
28764 KB |
n=2000 |
74 |
Correct |
7 ms |
28760 KB |
n=1844 |
75 |
Correct |
8 ms |
28764 KB |
n=2000 |
76 |
Correct |
8 ms |
28964 KB |
n=2000 |
77 |
Correct |
9 ms |
29016 KB |
n=2000 |
78 |
Correct |
8 ms |
28764 KB |
n=2000 |
79 |
Correct |
8 ms |
28712 KB |
n=2000 |
80 |
Correct |
8 ms |
28760 KB |
n=2000 |
81 |
Correct |
8 ms |
28764 KB |
n=2000 |
82 |
Correct |
8 ms |
28764 KB |
n=2000 |
83 |
Correct |
8 ms |
28764 KB |
n=2000 |
84 |
Correct |
7 ms |
28764 KB |
n=2000 |
85 |
Correct |
8 ms |
28764 KB |
n=2000 |
86 |
Correct |
8 ms |
28864 KB |
n=2000 |
87 |
Correct |
8 ms |
28760 KB |
n=2000 |
88 |
Correct |
8 ms |
28764 KB |
n=2000 |
89 |
Correct |
8 ms |
28760 KB |
n=2000 |
90 |
Correct |
8 ms |
28764 KB |
n=2000 |
91 |
Correct |
8 ms |
28764 KB |
n=2000 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
28508 KB |
n=5 |
2 |
Correct |
7 ms |
28508 KB |
n=100 |
3 |
Correct |
6 ms |
28528 KB |
n=100 |
4 |
Correct |
5 ms |
28508 KB |
n=100 |
5 |
Correct |
6 ms |
28508 KB |
n=100 |
6 |
Correct |
6 ms |
28504 KB |
n=100 |
7 |
Correct |
6 ms |
28508 KB |
n=100 |
8 |
Correct |
6 ms |
28504 KB |
n=100 |
9 |
Correct |
5 ms |
28504 KB |
n=100 |
10 |
Correct |
5 ms |
28508 KB |
n=100 |
11 |
Correct |
6 ms |
28508 KB |
n=100 |
12 |
Correct |
6 ms |
28504 KB |
n=100 |
13 |
Correct |
8 ms |
28508 KB |
n=100 |
14 |
Correct |
7 ms |
28764 KB |
n=100 |
15 |
Correct |
6 ms |
28508 KB |
n=100 |
16 |
Correct |
6 ms |
28508 KB |
n=100 |
17 |
Correct |
6 ms |
28504 KB |
n=100 |
18 |
Correct |
6 ms |
28508 KB |
n=100 |
19 |
Correct |
6 ms |
28508 KB |
n=100 |
20 |
Correct |
6 ms |
28508 KB |
n=100 |
21 |
Correct |
6 ms |
28504 KB |
n=100 |
22 |
Correct |
6 ms |
28508 KB |
n=100 |
23 |
Correct |
6 ms |
28508 KB |
n=100 |
24 |
Correct |
6 ms |
28504 KB |
n=100 |
25 |
Correct |
6 ms |
28508 KB |
n=100 |
26 |
Correct |
6 ms |
28568 KB |
n=12 |
27 |
Correct |
6 ms |
28508 KB |
n=100 |
28 |
Correct |
6 ms |
28508 KB |
n=500 |
29 |
Correct |
6 ms |
28504 KB |
n=500 |
30 |
Correct |
6 ms |
28584 KB |
n=500 |
31 |
Correct |
6 ms |
28508 KB |
n=500 |
32 |
Correct |
6 ms |
28504 KB |
n=500 |
33 |
Correct |
6 ms |
28508 KB |
n=500 |
34 |
Correct |
6 ms |
28504 KB |
n=500 |
35 |
Correct |
6 ms |
28508 KB |
n=500 |
36 |
Correct |
6 ms |
28508 KB |
n=500 |
37 |
Correct |
6 ms |
28508 KB |
n=500 |
38 |
Correct |
7 ms |
28508 KB |
n=500 |
39 |
Correct |
7 ms |
28504 KB |
n=500 |
40 |
Correct |
6 ms |
28508 KB |
n=500 |
41 |
Correct |
6 ms |
28504 KB |
n=500 |
42 |
Correct |
6 ms |
28508 KB |
n=500 |
43 |
Correct |
6 ms |
28508 KB |
n=500 |
44 |
Correct |
6 ms |
28504 KB |
n=500 |
45 |
Correct |
6 ms |
28508 KB |
n=500 |
46 |
Correct |
6 ms |
28508 KB |
n=500 |
47 |
Correct |
6 ms |
28508 KB |
n=500 |
48 |
Correct |
6 ms |
28508 KB |
n=500 |
49 |
Correct |
6 ms |
28508 KB |
n=500 |
50 |
Correct |
6 ms |
28508 KB |
n=500 |
51 |
Correct |
6 ms |
28508 KB |
n=500 |
52 |
Correct |
6 ms |
28508 KB |
n=500 |
53 |
Correct |
6 ms |
28508 KB |
n=500 |
54 |
Correct |
7 ms |
28508 KB |
n=500 |
55 |
Correct |
6 ms |
28504 KB |
n=278 |
56 |
Correct |
6 ms |
28508 KB |
n=500 |
57 |
Correct |
6 ms |
28504 KB |
n=500 |
58 |
Correct |
6 ms |
28504 KB |
n=500 |
59 |
Correct |
8 ms |
28764 KB |
n=2000 |
60 |
Correct |
8 ms |
28764 KB |
n=2000 |
61 |
Correct |
8 ms |
28764 KB |
n=2000 |
62 |
Correct |
10 ms |
28760 KB |
n=2000 |
63 |
Correct |
10 ms |
28788 KB |
n=2000 |
64 |
Correct |
10 ms |
28764 KB |
n=2000 |
65 |
Correct |
8 ms |
28760 KB |
n=2000 |
66 |
Correct |
8 ms |
28760 KB |
n=2000 |
67 |
Correct |
9 ms |
28764 KB |
n=2000 |
68 |
Correct |
8 ms |
28764 KB |
n=2000 |
69 |
Correct |
7 ms |
28676 KB |
n=2000 |
70 |
Correct |
7 ms |
28764 KB |
n=2000 |
71 |
Correct |
8 ms |
28764 KB |
n=2000 |
72 |
Correct |
7 ms |
28764 KB |
n=2000 |
73 |
Correct |
8 ms |
28764 KB |
n=2000 |
74 |
Correct |
7 ms |
28760 KB |
n=1844 |
75 |
Correct |
8 ms |
28764 KB |
n=2000 |
76 |
Correct |
8 ms |
28964 KB |
n=2000 |
77 |
Correct |
9 ms |
29016 KB |
n=2000 |
78 |
Correct |
8 ms |
28764 KB |
n=2000 |
79 |
Correct |
8 ms |
28712 KB |
n=2000 |
80 |
Correct |
8 ms |
28760 KB |
n=2000 |
81 |
Correct |
8 ms |
28764 KB |
n=2000 |
82 |
Correct |
8 ms |
28764 KB |
n=2000 |
83 |
Correct |
8 ms |
28764 KB |
n=2000 |
84 |
Correct |
7 ms |
28764 KB |
n=2000 |
85 |
Correct |
8 ms |
28764 KB |
n=2000 |
86 |
Correct |
8 ms |
28864 KB |
n=2000 |
87 |
Correct |
8 ms |
28760 KB |
n=2000 |
88 |
Correct |
8 ms |
28764 KB |
n=2000 |
89 |
Correct |
8 ms |
28760 KB |
n=2000 |
90 |
Correct |
8 ms |
28764 KB |
n=2000 |
91 |
Correct |
8 ms |
28764 KB |
n=2000 |
92 |
Correct |
484 ms |
72932 KB |
n=200000 |
93 |
Correct |
691 ms |
79648 KB |
n=200000 |
94 |
Correct |
659 ms |
84052 KB |
n=200000 |
95 |
Correct |
413 ms |
72900 KB |
n=200000 |
96 |
Correct |
406 ms |
73160 KB |
n=200000 |
97 |
Correct |
695 ms |
78164 KB |
n=200000 |
98 |
Correct |
427 ms |
72752 KB |
n=200000 |
99 |
Correct |
553 ms |
73044 KB |
n=200000 |
100 |
Correct |
440 ms |
72856 KB |
n=200000 |
101 |
Correct |
694 ms |
85460 KB |
n=200000 |
102 |
Correct |
267 ms |
73980 KB |
n=200000 |
103 |
Correct |
247 ms |
74064 KB |
n=200000 |
104 |
Correct |
274 ms |
74104 KB |
n=200000 |
105 |
Correct |
256 ms |
74324 KB |
n=200000 |
106 |
Correct |
311 ms |
74328 KB |
n=200000 |
107 |
Correct |
302 ms |
74332 KB |
n=200000 |
108 |
Correct |
557 ms |
72820 KB |
n=200000 |
109 |
Correct |
528 ms |
73044 KB |
n=200000 |
110 |
Correct |
580 ms |
73116 KB |
n=200000 |
111 |
Correct |
524 ms |
72372 KB |
n=200000 |
112 |
Correct |
737 ms |
84476 KB |
n=200000 |
113 |
Correct |
742 ms |
78188 KB |
n=200000 |
114 |
Correct |
503 ms |
72428 KB |
n=200000 |
115 |
Correct |
735 ms |
75784 KB |
n=200000 |
116 |
Correct |
429 ms |
73100 KB |
n=200000 |
117 |
Correct |
723 ms |
84820 KB |
n=200000 |
118 |
Correct |
710 ms |
76820 KB |
n=200000 |
119 |
Correct |
454 ms |
73056 KB |
n=200000 |
120 |
Correct |
670 ms |
84712 KB |
n=200000 |
121 |
Correct |
662 ms |
84496 KB |
n=200000 |
122 |
Correct |
612 ms |
84912 KB |
n=200000 |
123 |
Correct |
277 ms |
74496 KB |
n=200000 |
124 |
Correct |
141 ms |
41552 KB |
n=25264 |