#include <bits/stdc++.h>
using namespace std;
#define file ""
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define getbit(x, i) (((x) >> (i)) & 1)
#define bit(x) (1LL << (x))
#define popcount __builtin_popcountll
mt19937_64 rd(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l, int r) {
return l + rd() % (r - l + 1);
}
const int N = 1e6 + 5;
const int mod = (int)1e9 + 7; // 998244353;
const int lg = 25; // lg + 1
const int oo = 1e9;
const long long ooo = 1e18;
template<class X, class Y> bool mini(X &a, Y b) {
return a > b ? (a = b, true) : false;
}
template<class X, class Y> bool maxi(X &a, Y b) {
return a < b ? (a = b, true) : false;
}
void add(int &a, int b) {
a += b;
if (a >= mod) a -= mod;
if (a < 0) a += mod;
}
int n, m, q;
vector<int> adj[N];
int h[N], par[N][lg + 1];
int a[N];
set<int> pos[N], f[N];
void dfs(int u, int p) {
par[u][0] = p;
for (int i = 1; i <= lg; ++i) par[u][i] = par[par[u][i - 1]][i - 1];
for (int v : adj[u]) if (v != p) {
h[v] = h[u] + 1;
dfs(v, u);
}
}
int lca(int u, int v) {
if (h[u] < h[v]) swap(u, v);
for (int i = lg; i >= 0; --i) if (h[par[u][i]] >= h[v]) u = par[u][i];
if (u == v) return u;
for (int i = lg; i >= 0; --i) if (par[u][i] != par[v][i]) {
u = par[u][i];
v = par[v][i];
}
return par[u][0];
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
// freopen(file".inp", "r", stdin);
// freopen(file".out", "w", stdout);
cin >> n >> m >> q;
for (int i = 1; i < n; ++i) {
int u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
h[0] = -1;
dfs(1, 0);
for (int i = 1; i <= m; ++i) {
cin >> a[i];
pos[a[i]].insert(i);
}
for (int i = 2; i <= m; ++i) {
f[lca(a[i - 1], a[i])].insert(i - 1);
}
while (q--) {
int op;
cin >> op;
if (op == 1) {
int id, v;
cin >> id >> v;
if (id > 1) f[lca(a[id - 1], a[id])].erase(id - 1);
if (id < m) f[lca(a[id], a[id + 1])].erase(id);
pos[a[id]].erase(id);
a[id] = v;
if (id > 1) f[lca(a[id - 1], a[id])].insert(id - 1);
if (id < m) f[lca(a[id], a[id + 1])].insert(id);
pos[a[id]].insert(id);
}
else {
int l, r, v;
cin >> l >> r >> v;
auto it = pos[v].lower_bound(l);
if (it != pos[v].end() && *it <= r) {
cout << *it << ' ' << *it << '\n';
}
else {
it = f[v].lower_bound(l);
if (it != f[v].end() && *it + 1 <= r) {
cout << *it << ' ' << *it + 1 << '\n';
}
else {
cout << -1 << ' ' << -1 << '\n';
}
}
}
}
return 0;
}
/*
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
118604 KB |
n=5 |
2 |
Correct |
40 ms |
118508 KB |
n=100 |
3 |
Correct |
34 ms |
118616 KB |
n=100 |
4 |
Correct |
40 ms |
118756 KB |
n=100 |
5 |
Correct |
33 ms |
118608 KB |
n=100 |
6 |
Correct |
41 ms |
118612 KB |
n=100 |
7 |
Correct |
43 ms |
118732 KB |
n=100 |
8 |
Correct |
39 ms |
118608 KB |
n=100 |
9 |
Correct |
35 ms |
118616 KB |
n=100 |
10 |
Correct |
36 ms |
118728 KB |
n=100 |
11 |
Correct |
33 ms |
118620 KB |
n=100 |
12 |
Correct |
40 ms |
118608 KB |
n=100 |
13 |
Correct |
42 ms |
118620 KB |
n=100 |
14 |
Correct |
36 ms |
118620 KB |
n=100 |
15 |
Correct |
35 ms |
118616 KB |
n=100 |
16 |
Correct |
36 ms |
118564 KB |
n=100 |
17 |
Correct |
36 ms |
118560 KB |
n=100 |
18 |
Correct |
34 ms |
118612 KB |
n=100 |
19 |
Correct |
34 ms |
118620 KB |
n=100 |
20 |
Correct |
35 ms |
118576 KB |
n=100 |
21 |
Correct |
39 ms |
118608 KB |
n=100 |
22 |
Correct |
35 ms |
118728 KB |
n=100 |
23 |
Correct |
34 ms |
118660 KB |
n=100 |
24 |
Correct |
41 ms |
118612 KB |
n=100 |
25 |
Correct |
33 ms |
118612 KB |
n=100 |
26 |
Correct |
35 ms |
118620 KB |
n=12 |
27 |
Correct |
34 ms |
118612 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
118604 KB |
n=5 |
2 |
Correct |
40 ms |
118508 KB |
n=100 |
3 |
Correct |
34 ms |
118616 KB |
n=100 |
4 |
Correct |
40 ms |
118756 KB |
n=100 |
5 |
Correct |
33 ms |
118608 KB |
n=100 |
6 |
Correct |
41 ms |
118612 KB |
n=100 |
7 |
Correct |
43 ms |
118732 KB |
n=100 |
8 |
Correct |
39 ms |
118608 KB |
n=100 |
9 |
Correct |
35 ms |
118616 KB |
n=100 |
10 |
Correct |
36 ms |
118728 KB |
n=100 |
11 |
Correct |
33 ms |
118620 KB |
n=100 |
12 |
Correct |
40 ms |
118608 KB |
n=100 |
13 |
Correct |
42 ms |
118620 KB |
n=100 |
14 |
Correct |
36 ms |
118620 KB |
n=100 |
15 |
Correct |
35 ms |
118616 KB |
n=100 |
16 |
Correct |
36 ms |
118564 KB |
n=100 |
17 |
Correct |
36 ms |
118560 KB |
n=100 |
18 |
Correct |
34 ms |
118612 KB |
n=100 |
19 |
Correct |
34 ms |
118620 KB |
n=100 |
20 |
Correct |
35 ms |
118576 KB |
n=100 |
21 |
Correct |
39 ms |
118608 KB |
n=100 |
22 |
Correct |
35 ms |
118728 KB |
n=100 |
23 |
Correct |
34 ms |
118660 KB |
n=100 |
24 |
Correct |
41 ms |
118612 KB |
n=100 |
25 |
Correct |
33 ms |
118612 KB |
n=100 |
26 |
Correct |
35 ms |
118620 KB |
n=12 |
27 |
Correct |
34 ms |
118612 KB |
n=100 |
28 |
Correct |
35 ms |
118616 KB |
n=500 |
29 |
Correct |
40 ms |
118608 KB |
n=500 |
30 |
Correct |
35 ms |
118664 KB |
n=500 |
31 |
Correct |
42 ms |
118712 KB |
n=500 |
32 |
Correct |
34 ms |
118752 KB |
n=500 |
33 |
Correct |
32 ms |
118844 KB |
n=500 |
34 |
Correct |
33 ms |
118832 KB |
n=500 |
35 |
Correct |
42 ms |
118612 KB |
n=500 |
36 |
Correct |
42 ms |
118608 KB |
n=500 |
37 |
Correct |
39 ms |
118616 KB |
n=500 |
38 |
Correct |
34 ms |
118616 KB |
n=500 |
39 |
Correct |
32 ms |
118620 KB |
n=500 |
40 |
Correct |
40 ms |
118616 KB |
n=500 |
41 |
Correct |
40 ms |
118616 KB |
n=500 |
42 |
Correct |
40 ms |
118620 KB |
n=500 |
43 |
Correct |
38 ms |
118620 KB |
n=500 |
44 |
Correct |
33 ms |
118704 KB |
n=500 |
45 |
Correct |
33 ms |
118680 KB |
n=500 |
46 |
Correct |
33 ms |
118884 KB |
n=500 |
47 |
Correct |
40 ms |
118876 KB |
n=500 |
48 |
Correct |
32 ms |
118620 KB |
n=500 |
49 |
Correct |
39 ms |
118876 KB |
n=500 |
50 |
Correct |
32 ms |
118612 KB |
n=500 |
51 |
Correct |
45 ms |
118832 KB |
n=500 |
52 |
Correct |
33 ms |
118872 KB |
n=500 |
53 |
Correct |
37 ms |
118712 KB |
n=500 |
54 |
Correct |
32 ms |
118872 KB |
n=500 |
55 |
Correct |
32 ms |
118892 KB |
n=278 |
56 |
Correct |
33 ms |
118608 KB |
n=500 |
57 |
Correct |
32 ms |
118660 KB |
n=500 |
58 |
Correct |
33 ms |
118612 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
118604 KB |
n=5 |
2 |
Correct |
40 ms |
118508 KB |
n=100 |
3 |
Correct |
34 ms |
118616 KB |
n=100 |
4 |
Correct |
40 ms |
118756 KB |
n=100 |
5 |
Correct |
33 ms |
118608 KB |
n=100 |
6 |
Correct |
41 ms |
118612 KB |
n=100 |
7 |
Correct |
43 ms |
118732 KB |
n=100 |
8 |
Correct |
39 ms |
118608 KB |
n=100 |
9 |
Correct |
35 ms |
118616 KB |
n=100 |
10 |
Correct |
36 ms |
118728 KB |
n=100 |
11 |
Correct |
33 ms |
118620 KB |
n=100 |
12 |
Correct |
40 ms |
118608 KB |
n=100 |
13 |
Correct |
42 ms |
118620 KB |
n=100 |
14 |
Correct |
36 ms |
118620 KB |
n=100 |
15 |
Correct |
35 ms |
118616 KB |
n=100 |
16 |
Correct |
36 ms |
118564 KB |
n=100 |
17 |
Correct |
36 ms |
118560 KB |
n=100 |
18 |
Correct |
34 ms |
118612 KB |
n=100 |
19 |
Correct |
34 ms |
118620 KB |
n=100 |
20 |
Correct |
35 ms |
118576 KB |
n=100 |
21 |
Correct |
39 ms |
118608 KB |
n=100 |
22 |
Correct |
35 ms |
118728 KB |
n=100 |
23 |
Correct |
34 ms |
118660 KB |
n=100 |
24 |
Correct |
41 ms |
118612 KB |
n=100 |
25 |
Correct |
33 ms |
118612 KB |
n=100 |
26 |
Correct |
35 ms |
118620 KB |
n=12 |
27 |
Correct |
34 ms |
118612 KB |
n=100 |
28 |
Correct |
35 ms |
118616 KB |
n=500 |
29 |
Correct |
40 ms |
118608 KB |
n=500 |
30 |
Correct |
35 ms |
118664 KB |
n=500 |
31 |
Correct |
42 ms |
118712 KB |
n=500 |
32 |
Correct |
34 ms |
118752 KB |
n=500 |
33 |
Correct |
32 ms |
118844 KB |
n=500 |
34 |
Correct |
33 ms |
118832 KB |
n=500 |
35 |
Correct |
42 ms |
118612 KB |
n=500 |
36 |
Correct |
42 ms |
118608 KB |
n=500 |
37 |
Correct |
39 ms |
118616 KB |
n=500 |
38 |
Correct |
34 ms |
118616 KB |
n=500 |
39 |
Correct |
32 ms |
118620 KB |
n=500 |
40 |
Correct |
40 ms |
118616 KB |
n=500 |
41 |
Correct |
40 ms |
118616 KB |
n=500 |
42 |
Correct |
40 ms |
118620 KB |
n=500 |
43 |
Correct |
38 ms |
118620 KB |
n=500 |
44 |
Correct |
33 ms |
118704 KB |
n=500 |
45 |
Correct |
33 ms |
118680 KB |
n=500 |
46 |
Correct |
33 ms |
118884 KB |
n=500 |
47 |
Correct |
40 ms |
118876 KB |
n=500 |
48 |
Correct |
32 ms |
118620 KB |
n=500 |
49 |
Correct |
39 ms |
118876 KB |
n=500 |
50 |
Correct |
32 ms |
118612 KB |
n=500 |
51 |
Correct |
45 ms |
118832 KB |
n=500 |
52 |
Correct |
33 ms |
118872 KB |
n=500 |
53 |
Correct |
37 ms |
118712 KB |
n=500 |
54 |
Correct |
32 ms |
118872 KB |
n=500 |
55 |
Correct |
32 ms |
118892 KB |
n=278 |
56 |
Correct |
33 ms |
118608 KB |
n=500 |
57 |
Correct |
32 ms |
118660 KB |
n=500 |
58 |
Correct |
33 ms |
118612 KB |
n=500 |
59 |
Correct |
42 ms |
119120 KB |
n=2000 |
60 |
Correct |
42 ms |
119120 KB |
n=2000 |
61 |
Correct |
35 ms |
119160 KB |
n=2000 |
62 |
Correct |
40 ms |
119180 KB |
n=2000 |
63 |
Correct |
46 ms |
119228 KB |
n=2000 |
64 |
Correct |
36 ms |
119132 KB |
n=2000 |
65 |
Correct |
34 ms |
119132 KB |
n=2000 |
66 |
Correct |
41 ms |
119120 KB |
n=2000 |
67 |
Correct |
35 ms |
119224 KB |
n=2000 |
68 |
Correct |
36 ms |
119124 KB |
n=2000 |
69 |
Correct |
39 ms |
119124 KB |
n=2000 |
70 |
Correct |
40 ms |
119120 KB |
n=2000 |
71 |
Correct |
36 ms |
119124 KB |
n=2000 |
72 |
Correct |
38 ms |
119120 KB |
n=2000 |
73 |
Correct |
37 ms |
119132 KB |
n=2000 |
74 |
Correct |
36 ms |
118976 KB |
n=1844 |
75 |
Correct |
43 ms |
119080 KB |
n=2000 |
76 |
Correct |
40 ms |
119124 KB |
n=2000 |
77 |
Correct |
46 ms |
119120 KB |
n=2000 |
78 |
Correct |
36 ms |
119120 KB |
n=2000 |
79 |
Correct |
37 ms |
119256 KB |
n=2000 |
80 |
Correct |
45 ms |
119328 KB |
n=2000 |
81 |
Correct |
35 ms |
119132 KB |
n=2000 |
82 |
Correct |
35 ms |
119120 KB |
n=2000 |
83 |
Correct |
35 ms |
119124 KB |
n=2000 |
84 |
Correct |
41 ms |
119120 KB |
n=2000 |
85 |
Correct |
38 ms |
119216 KB |
n=2000 |
86 |
Correct |
36 ms |
119244 KB |
n=2000 |
87 |
Correct |
36 ms |
119152 KB |
n=2000 |
88 |
Correct |
47 ms |
119312 KB |
n=2000 |
89 |
Correct |
42 ms |
119120 KB |
n=2000 |
90 |
Correct |
38 ms |
119132 KB |
n=2000 |
91 |
Correct |
38 ms |
119164 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
118604 KB |
n=5 |
2 |
Correct |
40 ms |
118508 KB |
n=100 |
3 |
Correct |
34 ms |
118616 KB |
n=100 |
4 |
Correct |
40 ms |
118756 KB |
n=100 |
5 |
Correct |
33 ms |
118608 KB |
n=100 |
6 |
Correct |
41 ms |
118612 KB |
n=100 |
7 |
Correct |
43 ms |
118732 KB |
n=100 |
8 |
Correct |
39 ms |
118608 KB |
n=100 |
9 |
Correct |
35 ms |
118616 KB |
n=100 |
10 |
Correct |
36 ms |
118728 KB |
n=100 |
11 |
Correct |
33 ms |
118620 KB |
n=100 |
12 |
Correct |
40 ms |
118608 KB |
n=100 |
13 |
Correct |
42 ms |
118620 KB |
n=100 |
14 |
Correct |
36 ms |
118620 KB |
n=100 |
15 |
Correct |
35 ms |
118616 KB |
n=100 |
16 |
Correct |
36 ms |
118564 KB |
n=100 |
17 |
Correct |
36 ms |
118560 KB |
n=100 |
18 |
Correct |
34 ms |
118612 KB |
n=100 |
19 |
Correct |
34 ms |
118620 KB |
n=100 |
20 |
Correct |
35 ms |
118576 KB |
n=100 |
21 |
Correct |
39 ms |
118608 KB |
n=100 |
22 |
Correct |
35 ms |
118728 KB |
n=100 |
23 |
Correct |
34 ms |
118660 KB |
n=100 |
24 |
Correct |
41 ms |
118612 KB |
n=100 |
25 |
Correct |
33 ms |
118612 KB |
n=100 |
26 |
Correct |
35 ms |
118620 KB |
n=12 |
27 |
Correct |
34 ms |
118612 KB |
n=100 |
28 |
Correct |
35 ms |
118616 KB |
n=500 |
29 |
Correct |
40 ms |
118608 KB |
n=500 |
30 |
Correct |
35 ms |
118664 KB |
n=500 |
31 |
Correct |
42 ms |
118712 KB |
n=500 |
32 |
Correct |
34 ms |
118752 KB |
n=500 |
33 |
Correct |
32 ms |
118844 KB |
n=500 |
34 |
Correct |
33 ms |
118832 KB |
n=500 |
35 |
Correct |
42 ms |
118612 KB |
n=500 |
36 |
Correct |
42 ms |
118608 KB |
n=500 |
37 |
Correct |
39 ms |
118616 KB |
n=500 |
38 |
Correct |
34 ms |
118616 KB |
n=500 |
39 |
Correct |
32 ms |
118620 KB |
n=500 |
40 |
Correct |
40 ms |
118616 KB |
n=500 |
41 |
Correct |
40 ms |
118616 KB |
n=500 |
42 |
Correct |
40 ms |
118620 KB |
n=500 |
43 |
Correct |
38 ms |
118620 KB |
n=500 |
44 |
Correct |
33 ms |
118704 KB |
n=500 |
45 |
Correct |
33 ms |
118680 KB |
n=500 |
46 |
Correct |
33 ms |
118884 KB |
n=500 |
47 |
Correct |
40 ms |
118876 KB |
n=500 |
48 |
Correct |
32 ms |
118620 KB |
n=500 |
49 |
Correct |
39 ms |
118876 KB |
n=500 |
50 |
Correct |
32 ms |
118612 KB |
n=500 |
51 |
Correct |
45 ms |
118832 KB |
n=500 |
52 |
Correct |
33 ms |
118872 KB |
n=500 |
53 |
Correct |
37 ms |
118712 KB |
n=500 |
54 |
Correct |
32 ms |
118872 KB |
n=500 |
55 |
Correct |
32 ms |
118892 KB |
n=278 |
56 |
Correct |
33 ms |
118608 KB |
n=500 |
57 |
Correct |
32 ms |
118660 KB |
n=500 |
58 |
Correct |
33 ms |
118612 KB |
n=500 |
59 |
Correct |
42 ms |
119120 KB |
n=2000 |
60 |
Correct |
42 ms |
119120 KB |
n=2000 |
61 |
Correct |
35 ms |
119160 KB |
n=2000 |
62 |
Correct |
40 ms |
119180 KB |
n=2000 |
63 |
Correct |
46 ms |
119228 KB |
n=2000 |
64 |
Correct |
36 ms |
119132 KB |
n=2000 |
65 |
Correct |
34 ms |
119132 KB |
n=2000 |
66 |
Correct |
41 ms |
119120 KB |
n=2000 |
67 |
Correct |
35 ms |
119224 KB |
n=2000 |
68 |
Correct |
36 ms |
119124 KB |
n=2000 |
69 |
Correct |
39 ms |
119124 KB |
n=2000 |
70 |
Correct |
40 ms |
119120 KB |
n=2000 |
71 |
Correct |
36 ms |
119124 KB |
n=2000 |
72 |
Correct |
38 ms |
119120 KB |
n=2000 |
73 |
Correct |
37 ms |
119132 KB |
n=2000 |
74 |
Correct |
36 ms |
118976 KB |
n=1844 |
75 |
Correct |
43 ms |
119080 KB |
n=2000 |
76 |
Correct |
40 ms |
119124 KB |
n=2000 |
77 |
Correct |
46 ms |
119120 KB |
n=2000 |
78 |
Correct |
36 ms |
119120 KB |
n=2000 |
79 |
Correct |
37 ms |
119256 KB |
n=2000 |
80 |
Correct |
45 ms |
119328 KB |
n=2000 |
81 |
Correct |
35 ms |
119132 KB |
n=2000 |
82 |
Correct |
35 ms |
119120 KB |
n=2000 |
83 |
Correct |
35 ms |
119124 KB |
n=2000 |
84 |
Correct |
41 ms |
119120 KB |
n=2000 |
85 |
Correct |
38 ms |
119216 KB |
n=2000 |
86 |
Correct |
36 ms |
119244 KB |
n=2000 |
87 |
Correct |
36 ms |
119152 KB |
n=2000 |
88 |
Correct |
47 ms |
119312 KB |
n=2000 |
89 |
Correct |
42 ms |
119120 KB |
n=2000 |
90 |
Correct |
38 ms |
119132 KB |
n=2000 |
91 |
Correct |
38 ms |
119164 KB |
n=2000 |
92 |
Correct |
828 ms |
175440 KB |
n=200000 |
93 |
Correct |
1399 ms |
179792 KB |
n=200000 |
94 |
Correct |
1221 ms |
184432 KB |
n=200000 |
95 |
Correct |
765 ms |
175684 KB |
n=200000 |
96 |
Correct |
780 ms |
175792 KB |
n=200000 |
97 |
Correct |
1343 ms |
184128 KB |
n=200000 |
98 |
Correct |
799 ms |
178672 KB |
n=200000 |
99 |
Correct |
861 ms |
178940 KB |
n=200000 |
100 |
Correct |
756 ms |
179012 KB |
n=200000 |
101 |
Correct |
1269 ms |
191312 KB |
n=200000 |
102 |
Correct |
372 ms |
179888 KB |
n=200000 |
103 |
Correct |
440 ms |
179688 KB |
n=200000 |
104 |
Correct |
451 ms |
179716 KB |
n=200000 |
105 |
Correct |
428 ms |
180236 KB |
n=200000 |
106 |
Correct |
464 ms |
180332 KB |
n=200000 |
107 |
Correct |
476 ms |
180364 KB |
n=200000 |
108 |
Correct |
870 ms |
178784 KB |
n=200000 |
109 |
Correct |
899 ms |
178808 KB |
n=200000 |
110 |
Correct |
918 ms |
178616 KB |
n=200000 |
111 |
Correct |
741 ms |
178184 KB |
n=200000 |
112 |
Correct |
1225 ms |
189944 KB |
n=200000 |
113 |
Correct |
1201 ms |
184008 KB |
n=200000 |
114 |
Correct |
765 ms |
177948 KB |
n=200000 |
115 |
Correct |
1309 ms |
181260 KB |
n=200000 |
116 |
Correct |
743 ms |
179136 KB |
n=200000 |
117 |
Correct |
1256 ms |
190596 KB |
n=200000 |
118 |
Correct |
1290 ms |
182756 KB |
n=200000 |
119 |
Correct |
748 ms |
179140 KB |
n=200000 |
120 |
Correct |
1163 ms |
190504 KB |
n=200000 |
121 |
Correct |
1209 ms |
190356 KB |
n=200000 |
122 |
Correct |
1258 ms |
190812 KB |
n=200000 |
123 |
Correct |
481 ms |
180196 KB |
n=200000 |
124 |
Correct |
279 ms |
137452 KB |
n=25264 |