#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e5 + 7;
int a[N], l[N];
set <int> s[N], s1[N];
vector <int> g[N];
int p[N][20], d[N];
void dfs (int u, int pa = 0, int depth = 0) {
p[u][0] = pa;
for (int i = 1; i < 20; i++) {
p[u][i] = p[p[u][i - 1]][i - 1];
}
d[u] = depth;
for (int v : g[u]) {
if(v != pa) {
dfs(v, u, depth + 1);
}
}
}
int lca (int u, int v) {
if (d[u] > d[v]) {
swap(u, v);
}
for (int i = 19; i >= 0; i--) {
if ((d[v] - d[u]) >> i & 1) {
v = p[v][i];
}
}
if (u == v) {
return u;
}
for (int i = 19; i >= 0; i--) {
if (p[u][i] != p[v][i]) {
u = p[u][i];
v = p[v][i];
}
}
return p[u][0];
}
void solve() {
int n, m, q;
cin >> n >> m >> q;
for(int i = 0; i < n - 1; i++) {
int u, v;
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
dfs(1);
for(int i = 1; i <= m; i++) {
cin >> a[i];
s1[a[i]].insert(i);
}
auto del = [&] (int pos) {
s[l[pos]].erase(pos);
};
auto calc = [&] (int pos) {
l[pos] = lca(a[pos], a[pos + 1]);
s[l[pos]].insert(pos);
};
for (int i = 1; i < m; i++) {
calc(i);
}
while (q--) {
int x;
cin >> x;
if (x == 1) {
int i, v;
cin >> i >> v;
s1[a[i]].erase(i);
a[i] = v;
s1[a[i]].insert(i);
if (i - 1 >= 1) {
del(i - 1);
calc(i - 1);
}
if (i + 1 <= m) {
del(i);
calc(i);
}
}
else {
int l, r, v;
cin >> l >> r >> v;
auto it = s[v].lower_bound(l);
if (it != s[v].end() && *it < r) {
cout << *it << " " << *it + 1 << "\n";
}
else {
auto it = s1[v].lower_bound(l);
if (it != s1[v].end() && *it <= r) {
cout << *it << " " << *it << "\n";
}
else {
cout << -1 << " " << -1 << "\n";
}
}
}
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
23764 KB |
n=5 |
2 |
Correct |
12 ms |
23764 KB |
n=100 |
3 |
Correct |
11 ms |
23764 KB |
n=100 |
4 |
Correct |
12 ms |
23764 KB |
n=100 |
5 |
Correct |
12 ms |
23764 KB |
n=100 |
6 |
Correct |
11 ms |
23852 KB |
n=100 |
7 |
Correct |
11 ms |
23764 KB |
n=100 |
8 |
Correct |
11 ms |
23824 KB |
n=100 |
9 |
Correct |
11 ms |
23776 KB |
n=100 |
10 |
Correct |
12 ms |
23860 KB |
n=100 |
11 |
Correct |
12 ms |
23764 KB |
n=100 |
12 |
Correct |
12 ms |
23772 KB |
n=100 |
13 |
Correct |
12 ms |
23764 KB |
n=100 |
14 |
Correct |
12 ms |
23764 KB |
n=100 |
15 |
Correct |
12 ms |
23824 KB |
n=100 |
16 |
Correct |
12 ms |
23840 KB |
n=100 |
17 |
Correct |
11 ms |
23740 KB |
n=100 |
18 |
Correct |
12 ms |
23764 KB |
n=100 |
19 |
Correct |
12 ms |
23848 KB |
n=100 |
20 |
Correct |
12 ms |
23764 KB |
n=100 |
21 |
Correct |
12 ms |
23740 KB |
n=100 |
22 |
Correct |
12 ms |
23864 KB |
n=100 |
23 |
Correct |
12 ms |
23960 KB |
n=100 |
24 |
Correct |
12 ms |
23764 KB |
n=100 |
25 |
Correct |
12 ms |
23764 KB |
n=100 |
26 |
Correct |
12 ms |
23764 KB |
n=12 |
27 |
Correct |
14 ms |
23764 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
23764 KB |
n=5 |
2 |
Correct |
12 ms |
23764 KB |
n=100 |
3 |
Correct |
11 ms |
23764 KB |
n=100 |
4 |
Correct |
12 ms |
23764 KB |
n=100 |
5 |
Correct |
12 ms |
23764 KB |
n=100 |
6 |
Correct |
11 ms |
23852 KB |
n=100 |
7 |
Correct |
11 ms |
23764 KB |
n=100 |
8 |
Correct |
11 ms |
23824 KB |
n=100 |
9 |
Correct |
11 ms |
23776 KB |
n=100 |
10 |
Correct |
12 ms |
23860 KB |
n=100 |
11 |
Correct |
12 ms |
23764 KB |
n=100 |
12 |
Correct |
12 ms |
23772 KB |
n=100 |
13 |
Correct |
12 ms |
23764 KB |
n=100 |
14 |
Correct |
12 ms |
23764 KB |
n=100 |
15 |
Correct |
12 ms |
23824 KB |
n=100 |
16 |
Correct |
12 ms |
23840 KB |
n=100 |
17 |
Correct |
11 ms |
23740 KB |
n=100 |
18 |
Correct |
12 ms |
23764 KB |
n=100 |
19 |
Correct |
12 ms |
23848 KB |
n=100 |
20 |
Correct |
12 ms |
23764 KB |
n=100 |
21 |
Correct |
12 ms |
23740 KB |
n=100 |
22 |
Correct |
12 ms |
23864 KB |
n=100 |
23 |
Correct |
12 ms |
23960 KB |
n=100 |
24 |
Correct |
12 ms |
23764 KB |
n=100 |
25 |
Correct |
12 ms |
23764 KB |
n=100 |
26 |
Correct |
12 ms |
23764 KB |
n=12 |
27 |
Correct |
14 ms |
23764 KB |
n=100 |
28 |
Correct |
15 ms |
23892 KB |
n=500 |
29 |
Correct |
12 ms |
23892 KB |
n=500 |
30 |
Correct |
13 ms |
23892 KB |
n=500 |
31 |
Correct |
12 ms |
23892 KB |
n=500 |
32 |
Correct |
13 ms |
23892 KB |
n=500 |
33 |
Correct |
12 ms |
23992 KB |
n=500 |
34 |
Correct |
12 ms |
23892 KB |
n=500 |
35 |
Correct |
12 ms |
23892 KB |
n=500 |
36 |
Correct |
14 ms |
23868 KB |
n=500 |
37 |
Correct |
13 ms |
23984 KB |
n=500 |
38 |
Correct |
13 ms |
23892 KB |
n=500 |
39 |
Correct |
12 ms |
23892 KB |
n=500 |
40 |
Correct |
12 ms |
23988 KB |
n=500 |
41 |
Correct |
13 ms |
23892 KB |
n=500 |
42 |
Correct |
13 ms |
23892 KB |
n=500 |
43 |
Correct |
13 ms |
23964 KB |
n=500 |
44 |
Correct |
12 ms |
23892 KB |
n=500 |
45 |
Correct |
13 ms |
23988 KB |
n=500 |
46 |
Correct |
12 ms |
23892 KB |
n=500 |
47 |
Correct |
12 ms |
24004 KB |
n=500 |
48 |
Correct |
12 ms |
23984 KB |
n=500 |
49 |
Correct |
12 ms |
23892 KB |
n=500 |
50 |
Correct |
13 ms |
23888 KB |
n=500 |
51 |
Correct |
13 ms |
23892 KB |
n=500 |
52 |
Correct |
12 ms |
24004 KB |
n=500 |
53 |
Correct |
13 ms |
23992 KB |
n=500 |
54 |
Correct |
13 ms |
23912 KB |
n=500 |
55 |
Correct |
12 ms |
23892 KB |
n=278 |
56 |
Correct |
12 ms |
23892 KB |
n=500 |
57 |
Correct |
14 ms |
23892 KB |
n=500 |
58 |
Correct |
12 ms |
23868 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
23764 KB |
n=5 |
2 |
Correct |
12 ms |
23764 KB |
n=100 |
3 |
Correct |
11 ms |
23764 KB |
n=100 |
4 |
Correct |
12 ms |
23764 KB |
n=100 |
5 |
Correct |
12 ms |
23764 KB |
n=100 |
6 |
Correct |
11 ms |
23852 KB |
n=100 |
7 |
Correct |
11 ms |
23764 KB |
n=100 |
8 |
Correct |
11 ms |
23824 KB |
n=100 |
9 |
Correct |
11 ms |
23776 KB |
n=100 |
10 |
Correct |
12 ms |
23860 KB |
n=100 |
11 |
Correct |
12 ms |
23764 KB |
n=100 |
12 |
Correct |
12 ms |
23772 KB |
n=100 |
13 |
Correct |
12 ms |
23764 KB |
n=100 |
14 |
Correct |
12 ms |
23764 KB |
n=100 |
15 |
Correct |
12 ms |
23824 KB |
n=100 |
16 |
Correct |
12 ms |
23840 KB |
n=100 |
17 |
Correct |
11 ms |
23740 KB |
n=100 |
18 |
Correct |
12 ms |
23764 KB |
n=100 |
19 |
Correct |
12 ms |
23848 KB |
n=100 |
20 |
Correct |
12 ms |
23764 KB |
n=100 |
21 |
Correct |
12 ms |
23740 KB |
n=100 |
22 |
Correct |
12 ms |
23864 KB |
n=100 |
23 |
Correct |
12 ms |
23960 KB |
n=100 |
24 |
Correct |
12 ms |
23764 KB |
n=100 |
25 |
Correct |
12 ms |
23764 KB |
n=100 |
26 |
Correct |
12 ms |
23764 KB |
n=12 |
27 |
Correct |
14 ms |
23764 KB |
n=100 |
28 |
Correct |
15 ms |
23892 KB |
n=500 |
29 |
Correct |
12 ms |
23892 KB |
n=500 |
30 |
Correct |
13 ms |
23892 KB |
n=500 |
31 |
Correct |
12 ms |
23892 KB |
n=500 |
32 |
Correct |
13 ms |
23892 KB |
n=500 |
33 |
Correct |
12 ms |
23992 KB |
n=500 |
34 |
Correct |
12 ms |
23892 KB |
n=500 |
35 |
Correct |
12 ms |
23892 KB |
n=500 |
36 |
Correct |
14 ms |
23868 KB |
n=500 |
37 |
Correct |
13 ms |
23984 KB |
n=500 |
38 |
Correct |
13 ms |
23892 KB |
n=500 |
39 |
Correct |
12 ms |
23892 KB |
n=500 |
40 |
Correct |
12 ms |
23988 KB |
n=500 |
41 |
Correct |
13 ms |
23892 KB |
n=500 |
42 |
Correct |
13 ms |
23892 KB |
n=500 |
43 |
Correct |
13 ms |
23964 KB |
n=500 |
44 |
Correct |
12 ms |
23892 KB |
n=500 |
45 |
Correct |
13 ms |
23988 KB |
n=500 |
46 |
Correct |
12 ms |
23892 KB |
n=500 |
47 |
Correct |
12 ms |
24004 KB |
n=500 |
48 |
Correct |
12 ms |
23984 KB |
n=500 |
49 |
Correct |
12 ms |
23892 KB |
n=500 |
50 |
Correct |
13 ms |
23888 KB |
n=500 |
51 |
Correct |
13 ms |
23892 KB |
n=500 |
52 |
Correct |
12 ms |
24004 KB |
n=500 |
53 |
Correct |
13 ms |
23992 KB |
n=500 |
54 |
Correct |
13 ms |
23912 KB |
n=500 |
55 |
Correct |
12 ms |
23892 KB |
n=278 |
56 |
Correct |
12 ms |
23892 KB |
n=500 |
57 |
Correct |
14 ms |
23892 KB |
n=500 |
58 |
Correct |
12 ms |
23868 KB |
n=500 |
59 |
Correct |
15 ms |
24372 KB |
n=2000 |
60 |
Correct |
15 ms |
24536 KB |
n=2000 |
61 |
Correct |
15 ms |
24404 KB |
n=2000 |
62 |
Correct |
15 ms |
24388 KB |
n=2000 |
63 |
Correct |
15 ms |
24384 KB |
n=2000 |
64 |
Correct |
15 ms |
24488 KB |
n=2000 |
65 |
Correct |
18 ms |
24408 KB |
n=2000 |
66 |
Correct |
15 ms |
24416 KB |
n=2000 |
67 |
Correct |
17 ms |
24404 KB |
n=2000 |
68 |
Correct |
15 ms |
24432 KB |
n=2000 |
69 |
Correct |
15 ms |
24404 KB |
n=2000 |
70 |
Correct |
14 ms |
24476 KB |
n=2000 |
71 |
Correct |
14 ms |
24404 KB |
n=2000 |
72 |
Correct |
14 ms |
24404 KB |
n=2000 |
73 |
Correct |
14 ms |
24392 KB |
n=2000 |
74 |
Correct |
14 ms |
24352 KB |
n=1844 |
75 |
Correct |
14 ms |
24380 KB |
n=2000 |
76 |
Correct |
15 ms |
24404 KB |
n=2000 |
77 |
Correct |
15 ms |
24404 KB |
n=2000 |
78 |
Correct |
15 ms |
24404 KB |
n=2000 |
79 |
Correct |
15 ms |
24404 KB |
n=2000 |
80 |
Correct |
15 ms |
24404 KB |
n=2000 |
81 |
Correct |
15 ms |
24384 KB |
n=2000 |
82 |
Correct |
15 ms |
24348 KB |
n=2000 |
83 |
Correct |
14 ms |
24404 KB |
n=2000 |
84 |
Correct |
15 ms |
24364 KB |
n=2000 |
85 |
Correct |
15 ms |
24492 KB |
n=2000 |
86 |
Correct |
15 ms |
24404 KB |
n=2000 |
87 |
Correct |
15 ms |
24424 KB |
n=2000 |
88 |
Correct |
14 ms |
24532 KB |
n=2000 |
89 |
Correct |
14 ms |
24444 KB |
n=2000 |
90 |
Correct |
15 ms |
24540 KB |
n=2000 |
91 |
Correct |
15 ms |
24368 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
23764 KB |
n=5 |
2 |
Correct |
12 ms |
23764 KB |
n=100 |
3 |
Correct |
11 ms |
23764 KB |
n=100 |
4 |
Correct |
12 ms |
23764 KB |
n=100 |
5 |
Correct |
12 ms |
23764 KB |
n=100 |
6 |
Correct |
11 ms |
23852 KB |
n=100 |
7 |
Correct |
11 ms |
23764 KB |
n=100 |
8 |
Correct |
11 ms |
23824 KB |
n=100 |
9 |
Correct |
11 ms |
23776 KB |
n=100 |
10 |
Correct |
12 ms |
23860 KB |
n=100 |
11 |
Correct |
12 ms |
23764 KB |
n=100 |
12 |
Correct |
12 ms |
23772 KB |
n=100 |
13 |
Correct |
12 ms |
23764 KB |
n=100 |
14 |
Correct |
12 ms |
23764 KB |
n=100 |
15 |
Correct |
12 ms |
23824 KB |
n=100 |
16 |
Correct |
12 ms |
23840 KB |
n=100 |
17 |
Correct |
11 ms |
23740 KB |
n=100 |
18 |
Correct |
12 ms |
23764 KB |
n=100 |
19 |
Correct |
12 ms |
23848 KB |
n=100 |
20 |
Correct |
12 ms |
23764 KB |
n=100 |
21 |
Correct |
12 ms |
23740 KB |
n=100 |
22 |
Correct |
12 ms |
23864 KB |
n=100 |
23 |
Correct |
12 ms |
23960 KB |
n=100 |
24 |
Correct |
12 ms |
23764 KB |
n=100 |
25 |
Correct |
12 ms |
23764 KB |
n=100 |
26 |
Correct |
12 ms |
23764 KB |
n=12 |
27 |
Correct |
14 ms |
23764 KB |
n=100 |
28 |
Correct |
15 ms |
23892 KB |
n=500 |
29 |
Correct |
12 ms |
23892 KB |
n=500 |
30 |
Correct |
13 ms |
23892 KB |
n=500 |
31 |
Correct |
12 ms |
23892 KB |
n=500 |
32 |
Correct |
13 ms |
23892 KB |
n=500 |
33 |
Correct |
12 ms |
23992 KB |
n=500 |
34 |
Correct |
12 ms |
23892 KB |
n=500 |
35 |
Correct |
12 ms |
23892 KB |
n=500 |
36 |
Correct |
14 ms |
23868 KB |
n=500 |
37 |
Correct |
13 ms |
23984 KB |
n=500 |
38 |
Correct |
13 ms |
23892 KB |
n=500 |
39 |
Correct |
12 ms |
23892 KB |
n=500 |
40 |
Correct |
12 ms |
23988 KB |
n=500 |
41 |
Correct |
13 ms |
23892 KB |
n=500 |
42 |
Correct |
13 ms |
23892 KB |
n=500 |
43 |
Correct |
13 ms |
23964 KB |
n=500 |
44 |
Correct |
12 ms |
23892 KB |
n=500 |
45 |
Correct |
13 ms |
23988 KB |
n=500 |
46 |
Correct |
12 ms |
23892 KB |
n=500 |
47 |
Correct |
12 ms |
24004 KB |
n=500 |
48 |
Correct |
12 ms |
23984 KB |
n=500 |
49 |
Correct |
12 ms |
23892 KB |
n=500 |
50 |
Correct |
13 ms |
23888 KB |
n=500 |
51 |
Correct |
13 ms |
23892 KB |
n=500 |
52 |
Correct |
12 ms |
24004 KB |
n=500 |
53 |
Correct |
13 ms |
23992 KB |
n=500 |
54 |
Correct |
13 ms |
23912 KB |
n=500 |
55 |
Correct |
12 ms |
23892 KB |
n=278 |
56 |
Correct |
12 ms |
23892 KB |
n=500 |
57 |
Correct |
14 ms |
23892 KB |
n=500 |
58 |
Correct |
12 ms |
23868 KB |
n=500 |
59 |
Correct |
15 ms |
24372 KB |
n=2000 |
60 |
Correct |
15 ms |
24536 KB |
n=2000 |
61 |
Correct |
15 ms |
24404 KB |
n=2000 |
62 |
Correct |
15 ms |
24388 KB |
n=2000 |
63 |
Correct |
15 ms |
24384 KB |
n=2000 |
64 |
Correct |
15 ms |
24488 KB |
n=2000 |
65 |
Correct |
18 ms |
24408 KB |
n=2000 |
66 |
Correct |
15 ms |
24416 KB |
n=2000 |
67 |
Correct |
17 ms |
24404 KB |
n=2000 |
68 |
Correct |
15 ms |
24432 KB |
n=2000 |
69 |
Correct |
15 ms |
24404 KB |
n=2000 |
70 |
Correct |
14 ms |
24476 KB |
n=2000 |
71 |
Correct |
14 ms |
24404 KB |
n=2000 |
72 |
Correct |
14 ms |
24404 KB |
n=2000 |
73 |
Correct |
14 ms |
24392 KB |
n=2000 |
74 |
Correct |
14 ms |
24352 KB |
n=1844 |
75 |
Correct |
14 ms |
24380 KB |
n=2000 |
76 |
Correct |
15 ms |
24404 KB |
n=2000 |
77 |
Correct |
15 ms |
24404 KB |
n=2000 |
78 |
Correct |
15 ms |
24404 KB |
n=2000 |
79 |
Correct |
15 ms |
24404 KB |
n=2000 |
80 |
Correct |
15 ms |
24404 KB |
n=2000 |
81 |
Correct |
15 ms |
24384 KB |
n=2000 |
82 |
Correct |
15 ms |
24348 KB |
n=2000 |
83 |
Correct |
14 ms |
24404 KB |
n=2000 |
84 |
Correct |
15 ms |
24364 KB |
n=2000 |
85 |
Correct |
15 ms |
24492 KB |
n=2000 |
86 |
Correct |
15 ms |
24404 KB |
n=2000 |
87 |
Correct |
15 ms |
24424 KB |
n=2000 |
88 |
Correct |
14 ms |
24532 KB |
n=2000 |
89 |
Correct |
14 ms |
24444 KB |
n=2000 |
90 |
Correct |
15 ms |
24540 KB |
n=2000 |
91 |
Correct |
15 ms |
24368 KB |
n=2000 |
92 |
Correct |
631 ms |
87652 KB |
n=200000 |
93 |
Correct |
873 ms |
91308 KB |
n=200000 |
94 |
Correct |
809 ms |
94208 KB |
n=200000 |
95 |
Correct |
608 ms |
87380 KB |
n=200000 |
96 |
Correct |
629 ms |
87356 KB |
n=200000 |
97 |
Correct |
875 ms |
90536 KB |
n=200000 |
98 |
Correct |
622 ms |
87552 KB |
n=200000 |
99 |
Correct |
786 ms |
87104 KB |
n=200000 |
100 |
Correct |
664 ms |
87600 KB |
n=200000 |
101 |
Correct |
789 ms |
95124 KB |
n=200000 |
102 |
Correct |
419 ms |
88564 KB |
n=200000 |
103 |
Correct |
390 ms |
88788 KB |
n=200000 |
104 |
Correct |
402 ms |
88584 KB |
n=200000 |
105 |
Correct |
414 ms |
88456 KB |
n=200000 |
106 |
Correct |
398 ms |
88424 KB |
n=200000 |
107 |
Correct |
403 ms |
88368 KB |
n=200000 |
108 |
Correct |
697 ms |
87348 KB |
n=200000 |
109 |
Correct |
694 ms |
87260 KB |
n=200000 |
110 |
Correct |
704 ms |
87368 KB |
n=200000 |
111 |
Correct |
627 ms |
87472 KB |
n=200000 |
112 |
Correct |
788 ms |
94528 KB |
n=200000 |
113 |
Correct |
884 ms |
90588 KB |
n=200000 |
114 |
Correct |
650 ms |
87352 KB |
n=200000 |
115 |
Correct |
938 ms |
88488 KB |
n=200000 |
116 |
Correct |
602 ms |
87196 KB |
n=200000 |
117 |
Correct |
875 ms |
94520 KB |
n=200000 |
118 |
Correct |
915 ms |
89384 KB |
n=200000 |
119 |
Correct |
604 ms |
87296 KB |
n=200000 |
120 |
Correct |
750 ms |
94784 KB |
n=200000 |
121 |
Correct |
734 ms |
94928 KB |
n=200000 |
122 |
Correct |
729 ms |
95300 KB |
n=200000 |
123 |
Correct |
408 ms |
88072 KB |
n=200000 |
124 |
Correct |
185 ms |
39992 KB |
n=25264 |