/*#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")*/
#include <bits/stdc++.h>
#define for1(i,a,b) for (int i = a; i <= b; i++)
#define for2(i,a,b) for (int i = a; i >= b; i--)
#define int long long
#define sz(a) (int)a.size()
#define pii pair<int,int>
#define pb push_back
/*
__builtin_popcountll(x) : Number of 1-bit
__builtin_ctzll(x) : Number of trailing 0
*/
const long double PI = 3.1415926535897932384626433832795;
const int INF = 1000000000000000000;
const int MOD = 1000000007;
const int MOD2 = 1000000009;
const long double EPS = 1e-6;
using namespace std;
int n, m, q;
int a[200005], d[200005], up[200005][18];
pii res;
set<int> id[200005], se[200005];
vector<int> g[200005];
void dfs(int u, int p) {
for1(i,1,17) up[u][i] = up[up[u][i - 1]][i - 1];
for (auto v : g[u]) if (v != p) {
d[v] = d[u] + 1;
up[v][0] = u;
dfs(v, u);
}
}
int lca(int u, int v) {
if (d[u] < d[v]) swap(u, v);
for1(i,0,17) if ((d[u] - d[v]) & (1 << i)) u = up[u][i];
if (u == v) return u;
for2(i,17,0) if (up[u][i] != up[v][i]) {
u = up[u][i];
v = up[v][i];
}
return up[u][0];
}
signed main() {
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
// freopen("cf.inp", "r", stdin);
// freopen("cf.out", "w", stdout);
cin >> n >> m >> q;
for1(i,1,n - 1) {
int a, b;
cin >> a >> b;
g[a].push_back(b);
g[b].push_back(a);
}
dfs(1, 0);
for1(i,1,m) {
cin >> a[i];
id[a[i]].insert(i);
}
for1(i,1,m - 1) se[lca(a[i], a[i + 1])].insert(i);
while (q--) {
int op;
cin >> op;
if (op == 1) {
int i, u;
cin >> i >> u;
id[a[i]].erase(i);
if (i > 1) se[lca(a[i - 1], a[i])].erase(i - 1);
if (i < m) se[lca(a[i], a[i + 1])].erase(i);
a[i] = u;
id[a[i]].insert(i);
if (i > 1) se[lca(a[i - 1], a[i])].insert(i - 1);
if (i < m) se[lca(a[i], a[i + 1])].insert(i);
}
else {
int l, r, u;
cin >> l >> r >> u;
auto it = id[u].lower_bound(l);
if (it != id[u].end() && *it <= r) {
cout << *it << " " << *it << "\n";
continue;
}
auto it2 = se[u].lower_bound(l);
if (it2 != se[u].end() && *it2 < r) {
cout << *it2 << " " << *it2 + 1 << "\n";
continue;
}
cout << "-1 -1\n";
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23816 KB |
n=5 |
2 |
Correct |
13 ms |
23772 KB |
n=100 |
3 |
Correct |
12 ms |
23736 KB |
n=100 |
4 |
Correct |
14 ms |
23844 KB |
n=100 |
5 |
Correct |
11 ms |
23724 KB |
n=100 |
6 |
Correct |
11 ms |
23756 KB |
n=100 |
7 |
Correct |
12 ms |
23756 KB |
n=100 |
8 |
Correct |
11 ms |
23740 KB |
n=100 |
9 |
Correct |
11 ms |
23804 KB |
n=100 |
10 |
Correct |
11 ms |
23772 KB |
n=100 |
11 |
Correct |
11 ms |
23756 KB |
n=100 |
12 |
Correct |
12 ms |
23844 KB |
n=100 |
13 |
Correct |
11 ms |
23784 KB |
n=100 |
14 |
Correct |
12 ms |
23756 KB |
n=100 |
15 |
Correct |
13 ms |
23840 KB |
n=100 |
16 |
Correct |
13 ms |
23820 KB |
n=100 |
17 |
Correct |
12 ms |
23784 KB |
n=100 |
18 |
Correct |
11 ms |
23884 KB |
n=100 |
19 |
Correct |
12 ms |
23768 KB |
n=100 |
20 |
Correct |
11 ms |
23756 KB |
n=100 |
21 |
Correct |
12 ms |
23788 KB |
n=100 |
22 |
Correct |
14 ms |
23840 KB |
n=100 |
23 |
Correct |
11 ms |
23756 KB |
n=100 |
24 |
Correct |
12 ms |
23756 KB |
n=100 |
25 |
Correct |
12 ms |
23756 KB |
n=100 |
26 |
Correct |
11 ms |
23756 KB |
n=12 |
27 |
Correct |
11 ms |
23756 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23816 KB |
n=5 |
2 |
Correct |
13 ms |
23772 KB |
n=100 |
3 |
Correct |
12 ms |
23736 KB |
n=100 |
4 |
Correct |
14 ms |
23844 KB |
n=100 |
5 |
Correct |
11 ms |
23724 KB |
n=100 |
6 |
Correct |
11 ms |
23756 KB |
n=100 |
7 |
Correct |
12 ms |
23756 KB |
n=100 |
8 |
Correct |
11 ms |
23740 KB |
n=100 |
9 |
Correct |
11 ms |
23804 KB |
n=100 |
10 |
Correct |
11 ms |
23772 KB |
n=100 |
11 |
Correct |
11 ms |
23756 KB |
n=100 |
12 |
Correct |
12 ms |
23844 KB |
n=100 |
13 |
Correct |
11 ms |
23784 KB |
n=100 |
14 |
Correct |
12 ms |
23756 KB |
n=100 |
15 |
Correct |
13 ms |
23840 KB |
n=100 |
16 |
Correct |
13 ms |
23820 KB |
n=100 |
17 |
Correct |
12 ms |
23784 KB |
n=100 |
18 |
Correct |
11 ms |
23884 KB |
n=100 |
19 |
Correct |
12 ms |
23768 KB |
n=100 |
20 |
Correct |
11 ms |
23756 KB |
n=100 |
21 |
Correct |
12 ms |
23788 KB |
n=100 |
22 |
Correct |
14 ms |
23840 KB |
n=100 |
23 |
Correct |
11 ms |
23756 KB |
n=100 |
24 |
Correct |
12 ms |
23756 KB |
n=100 |
25 |
Correct |
12 ms |
23756 KB |
n=100 |
26 |
Correct |
11 ms |
23756 KB |
n=12 |
27 |
Correct |
11 ms |
23756 KB |
n=100 |
28 |
Correct |
16 ms |
23972 KB |
n=500 |
29 |
Correct |
13 ms |
23984 KB |
n=500 |
30 |
Correct |
15 ms |
23884 KB |
n=500 |
31 |
Correct |
16 ms |
23956 KB |
n=500 |
32 |
Correct |
13 ms |
23924 KB |
n=500 |
33 |
Correct |
14 ms |
23884 KB |
n=500 |
34 |
Correct |
12 ms |
23884 KB |
n=500 |
35 |
Correct |
13 ms |
23904 KB |
n=500 |
36 |
Correct |
11 ms |
23884 KB |
n=500 |
37 |
Correct |
12 ms |
23908 KB |
n=500 |
38 |
Correct |
14 ms |
23904 KB |
n=500 |
39 |
Correct |
13 ms |
23884 KB |
n=500 |
40 |
Correct |
12 ms |
23872 KB |
n=500 |
41 |
Correct |
12 ms |
23896 KB |
n=500 |
42 |
Correct |
13 ms |
23888 KB |
n=500 |
43 |
Correct |
15 ms |
23884 KB |
n=500 |
44 |
Correct |
13 ms |
23884 KB |
n=500 |
45 |
Correct |
13 ms |
23884 KB |
n=500 |
46 |
Correct |
14 ms |
23956 KB |
n=500 |
47 |
Correct |
17 ms |
23884 KB |
n=500 |
48 |
Correct |
12 ms |
23884 KB |
n=500 |
49 |
Correct |
13 ms |
23972 KB |
n=500 |
50 |
Correct |
14 ms |
23884 KB |
n=500 |
51 |
Correct |
14 ms |
23868 KB |
n=500 |
52 |
Correct |
14 ms |
23884 KB |
n=500 |
53 |
Correct |
15 ms |
23928 KB |
n=500 |
54 |
Correct |
15 ms |
23884 KB |
n=500 |
55 |
Correct |
12 ms |
23884 KB |
n=278 |
56 |
Correct |
12 ms |
23884 KB |
n=500 |
57 |
Correct |
12 ms |
23884 KB |
n=500 |
58 |
Correct |
11 ms |
23884 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23816 KB |
n=5 |
2 |
Correct |
13 ms |
23772 KB |
n=100 |
3 |
Correct |
12 ms |
23736 KB |
n=100 |
4 |
Correct |
14 ms |
23844 KB |
n=100 |
5 |
Correct |
11 ms |
23724 KB |
n=100 |
6 |
Correct |
11 ms |
23756 KB |
n=100 |
7 |
Correct |
12 ms |
23756 KB |
n=100 |
8 |
Correct |
11 ms |
23740 KB |
n=100 |
9 |
Correct |
11 ms |
23804 KB |
n=100 |
10 |
Correct |
11 ms |
23772 KB |
n=100 |
11 |
Correct |
11 ms |
23756 KB |
n=100 |
12 |
Correct |
12 ms |
23844 KB |
n=100 |
13 |
Correct |
11 ms |
23784 KB |
n=100 |
14 |
Correct |
12 ms |
23756 KB |
n=100 |
15 |
Correct |
13 ms |
23840 KB |
n=100 |
16 |
Correct |
13 ms |
23820 KB |
n=100 |
17 |
Correct |
12 ms |
23784 KB |
n=100 |
18 |
Correct |
11 ms |
23884 KB |
n=100 |
19 |
Correct |
12 ms |
23768 KB |
n=100 |
20 |
Correct |
11 ms |
23756 KB |
n=100 |
21 |
Correct |
12 ms |
23788 KB |
n=100 |
22 |
Correct |
14 ms |
23840 KB |
n=100 |
23 |
Correct |
11 ms |
23756 KB |
n=100 |
24 |
Correct |
12 ms |
23756 KB |
n=100 |
25 |
Correct |
12 ms |
23756 KB |
n=100 |
26 |
Correct |
11 ms |
23756 KB |
n=12 |
27 |
Correct |
11 ms |
23756 KB |
n=100 |
28 |
Correct |
16 ms |
23972 KB |
n=500 |
29 |
Correct |
13 ms |
23984 KB |
n=500 |
30 |
Correct |
15 ms |
23884 KB |
n=500 |
31 |
Correct |
16 ms |
23956 KB |
n=500 |
32 |
Correct |
13 ms |
23924 KB |
n=500 |
33 |
Correct |
14 ms |
23884 KB |
n=500 |
34 |
Correct |
12 ms |
23884 KB |
n=500 |
35 |
Correct |
13 ms |
23904 KB |
n=500 |
36 |
Correct |
11 ms |
23884 KB |
n=500 |
37 |
Correct |
12 ms |
23908 KB |
n=500 |
38 |
Correct |
14 ms |
23904 KB |
n=500 |
39 |
Correct |
13 ms |
23884 KB |
n=500 |
40 |
Correct |
12 ms |
23872 KB |
n=500 |
41 |
Correct |
12 ms |
23896 KB |
n=500 |
42 |
Correct |
13 ms |
23888 KB |
n=500 |
43 |
Correct |
15 ms |
23884 KB |
n=500 |
44 |
Correct |
13 ms |
23884 KB |
n=500 |
45 |
Correct |
13 ms |
23884 KB |
n=500 |
46 |
Correct |
14 ms |
23956 KB |
n=500 |
47 |
Correct |
17 ms |
23884 KB |
n=500 |
48 |
Correct |
12 ms |
23884 KB |
n=500 |
49 |
Correct |
13 ms |
23972 KB |
n=500 |
50 |
Correct |
14 ms |
23884 KB |
n=500 |
51 |
Correct |
14 ms |
23868 KB |
n=500 |
52 |
Correct |
14 ms |
23884 KB |
n=500 |
53 |
Correct |
15 ms |
23928 KB |
n=500 |
54 |
Correct |
15 ms |
23884 KB |
n=500 |
55 |
Correct |
12 ms |
23884 KB |
n=278 |
56 |
Correct |
12 ms |
23884 KB |
n=500 |
57 |
Correct |
12 ms |
23884 KB |
n=500 |
58 |
Correct |
11 ms |
23884 KB |
n=500 |
59 |
Correct |
16 ms |
24384 KB |
n=2000 |
60 |
Correct |
14 ms |
24452 KB |
n=2000 |
61 |
Correct |
17 ms |
24384 KB |
n=2000 |
62 |
Correct |
16 ms |
24432 KB |
n=2000 |
63 |
Correct |
15 ms |
24408 KB |
n=2000 |
64 |
Correct |
15 ms |
24396 KB |
n=2000 |
65 |
Correct |
15 ms |
24388 KB |
n=2000 |
66 |
Correct |
16 ms |
24476 KB |
n=2000 |
67 |
Correct |
17 ms |
24372 KB |
n=2000 |
68 |
Correct |
16 ms |
24512 KB |
n=2000 |
69 |
Correct |
14 ms |
24344 KB |
n=2000 |
70 |
Correct |
14 ms |
24332 KB |
n=2000 |
71 |
Correct |
14 ms |
24300 KB |
n=2000 |
72 |
Correct |
13 ms |
24360 KB |
n=2000 |
73 |
Correct |
15 ms |
24396 KB |
n=2000 |
74 |
Correct |
15 ms |
24368 KB |
n=1844 |
75 |
Correct |
14 ms |
24396 KB |
n=2000 |
76 |
Correct |
15 ms |
24344 KB |
n=2000 |
77 |
Correct |
19 ms |
24364 KB |
n=2000 |
78 |
Correct |
16 ms |
24396 KB |
n=2000 |
79 |
Correct |
15 ms |
24324 KB |
n=2000 |
80 |
Correct |
16 ms |
24468 KB |
n=2000 |
81 |
Correct |
15 ms |
24392 KB |
n=2000 |
82 |
Correct |
15 ms |
24396 KB |
n=2000 |
83 |
Correct |
15 ms |
24428 KB |
n=2000 |
84 |
Correct |
16 ms |
24400 KB |
n=2000 |
85 |
Correct |
15 ms |
24376 KB |
n=2000 |
86 |
Correct |
17 ms |
24396 KB |
n=2000 |
87 |
Correct |
15 ms |
24412 KB |
n=2000 |
88 |
Correct |
14 ms |
24396 KB |
n=2000 |
89 |
Correct |
14 ms |
24396 KB |
n=2000 |
90 |
Correct |
15 ms |
24504 KB |
n=2000 |
91 |
Correct |
14 ms |
24396 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23816 KB |
n=5 |
2 |
Correct |
13 ms |
23772 KB |
n=100 |
3 |
Correct |
12 ms |
23736 KB |
n=100 |
4 |
Correct |
14 ms |
23844 KB |
n=100 |
5 |
Correct |
11 ms |
23724 KB |
n=100 |
6 |
Correct |
11 ms |
23756 KB |
n=100 |
7 |
Correct |
12 ms |
23756 KB |
n=100 |
8 |
Correct |
11 ms |
23740 KB |
n=100 |
9 |
Correct |
11 ms |
23804 KB |
n=100 |
10 |
Correct |
11 ms |
23772 KB |
n=100 |
11 |
Correct |
11 ms |
23756 KB |
n=100 |
12 |
Correct |
12 ms |
23844 KB |
n=100 |
13 |
Correct |
11 ms |
23784 KB |
n=100 |
14 |
Correct |
12 ms |
23756 KB |
n=100 |
15 |
Correct |
13 ms |
23840 KB |
n=100 |
16 |
Correct |
13 ms |
23820 KB |
n=100 |
17 |
Correct |
12 ms |
23784 KB |
n=100 |
18 |
Correct |
11 ms |
23884 KB |
n=100 |
19 |
Correct |
12 ms |
23768 KB |
n=100 |
20 |
Correct |
11 ms |
23756 KB |
n=100 |
21 |
Correct |
12 ms |
23788 KB |
n=100 |
22 |
Correct |
14 ms |
23840 KB |
n=100 |
23 |
Correct |
11 ms |
23756 KB |
n=100 |
24 |
Correct |
12 ms |
23756 KB |
n=100 |
25 |
Correct |
12 ms |
23756 KB |
n=100 |
26 |
Correct |
11 ms |
23756 KB |
n=12 |
27 |
Correct |
11 ms |
23756 KB |
n=100 |
28 |
Correct |
16 ms |
23972 KB |
n=500 |
29 |
Correct |
13 ms |
23984 KB |
n=500 |
30 |
Correct |
15 ms |
23884 KB |
n=500 |
31 |
Correct |
16 ms |
23956 KB |
n=500 |
32 |
Correct |
13 ms |
23924 KB |
n=500 |
33 |
Correct |
14 ms |
23884 KB |
n=500 |
34 |
Correct |
12 ms |
23884 KB |
n=500 |
35 |
Correct |
13 ms |
23904 KB |
n=500 |
36 |
Correct |
11 ms |
23884 KB |
n=500 |
37 |
Correct |
12 ms |
23908 KB |
n=500 |
38 |
Correct |
14 ms |
23904 KB |
n=500 |
39 |
Correct |
13 ms |
23884 KB |
n=500 |
40 |
Correct |
12 ms |
23872 KB |
n=500 |
41 |
Correct |
12 ms |
23896 KB |
n=500 |
42 |
Correct |
13 ms |
23888 KB |
n=500 |
43 |
Correct |
15 ms |
23884 KB |
n=500 |
44 |
Correct |
13 ms |
23884 KB |
n=500 |
45 |
Correct |
13 ms |
23884 KB |
n=500 |
46 |
Correct |
14 ms |
23956 KB |
n=500 |
47 |
Correct |
17 ms |
23884 KB |
n=500 |
48 |
Correct |
12 ms |
23884 KB |
n=500 |
49 |
Correct |
13 ms |
23972 KB |
n=500 |
50 |
Correct |
14 ms |
23884 KB |
n=500 |
51 |
Correct |
14 ms |
23868 KB |
n=500 |
52 |
Correct |
14 ms |
23884 KB |
n=500 |
53 |
Correct |
15 ms |
23928 KB |
n=500 |
54 |
Correct |
15 ms |
23884 KB |
n=500 |
55 |
Correct |
12 ms |
23884 KB |
n=278 |
56 |
Correct |
12 ms |
23884 KB |
n=500 |
57 |
Correct |
12 ms |
23884 KB |
n=500 |
58 |
Correct |
11 ms |
23884 KB |
n=500 |
59 |
Correct |
16 ms |
24384 KB |
n=2000 |
60 |
Correct |
14 ms |
24452 KB |
n=2000 |
61 |
Correct |
17 ms |
24384 KB |
n=2000 |
62 |
Correct |
16 ms |
24432 KB |
n=2000 |
63 |
Correct |
15 ms |
24408 KB |
n=2000 |
64 |
Correct |
15 ms |
24396 KB |
n=2000 |
65 |
Correct |
15 ms |
24388 KB |
n=2000 |
66 |
Correct |
16 ms |
24476 KB |
n=2000 |
67 |
Correct |
17 ms |
24372 KB |
n=2000 |
68 |
Correct |
16 ms |
24512 KB |
n=2000 |
69 |
Correct |
14 ms |
24344 KB |
n=2000 |
70 |
Correct |
14 ms |
24332 KB |
n=2000 |
71 |
Correct |
14 ms |
24300 KB |
n=2000 |
72 |
Correct |
13 ms |
24360 KB |
n=2000 |
73 |
Correct |
15 ms |
24396 KB |
n=2000 |
74 |
Correct |
15 ms |
24368 KB |
n=1844 |
75 |
Correct |
14 ms |
24396 KB |
n=2000 |
76 |
Correct |
15 ms |
24344 KB |
n=2000 |
77 |
Correct |
19 ms |
24364 KB |
n=2000 |
78 |
Correct |
16 ms |
24396 KB |
n=2000 |
79 |
Correct |
15 ms |
24324 KB |
n=2000 |
80 |
Correct |
16 ms |
24468 KB |
n=2000 |
81 |
Correct |
15 ms |
24392 KB |
n=2000 |
82 |
Correct |
15 ms |
24396 KB |
n=2000 |
83 |
Correct |
15 ms |
24428 KB |
n=2000 |
84 |
Correct |
16 ms |
24400 KB |
n=2000 |
85 |
Correct |
15 ms |
24376 KB |
n=2000 |
86 |
Correct |
17 ms |
24396 KB |
n=2000 |
87 |
Correct |
15 ms |
24412 KB |
n=2000 |
88 |
Correct |
14 ms |
24396 KB |
n=2000 |
89 |
Correct |
14 ms |
24396 KB |
n=2000 |
90 |
Correct |
15 ms |
24504 KB |
n=2000 |
91 |
Correct |
14 ms |
24396 KB |
n=2000 |
92 |
Correct |
693 ms |
82924 KB |
n=200000 |
93 |
Correct |
1119 ms |
88256 KB |
n=200000 |
94 |
Correct |
1074 ms |
92212 KB |
n=200000 |
95 |
Correct |
684 ms |
82788 KB |
n=200000 |
96 |
Correct |
673 ms |
82920 KB |
n=200000 |
97 |
Correct |
1094 ms |
87220 KB |
n=200000 |
98 |
Correct |
663 ms |
82904 KB |
n=200000 |
99 |
Correct |
927 ms |
82484 KB |
n=200000 |
100 |
Correct |
644 ms |
82984 KB |
n=200000 |
101 |
Correct |
979 ms |
93588 KB |
n=200000 |
102 |
Correct |
440 ms |
83908 KB |
n=200000 |
103 |
Correct |
417 ms |
83992 KB |
n=200000 |
104 |
Correct |
476 ms |
84052 KB |
n=200000 |
105 |
Correct |
437 ms |
83592 KB |
n=200000 |
106 |
Correct |
411 ms |
83672 KB |
n=200000 |
107 |
Correct |
428 ms |
83696 KB |
n=200000 |
108 |
Correct |
788 ms |
82692 KB |
n=200000 |
109 |
Correct |
798 ms |
82904 KB |
n=200000 |
110 |
Correct |
790 ms |
82772 KB |
n=200000 |
111 |
Correct |
646 ms |
82712 KB |
n=200000 |
112 |
Correct |
964 ms |
92872 KB |
n=200000 |
113 |
Correct |
1004 ms |
87100 KB |
n=200000 |
114 |
Correct |
609 ms |
82692 KB |
n=200000 |
115 |
Correct |
1100 ms |
84360 KB |
n=200000 |
116 |
Correct |
636 ms |
82576 KB |
n=200000 |
117 |
Correct |
980 ms |
92908 KB |
n=200000 |
118 |
Correct |
1056 ms |
85544 KB |
n=200000 |
119 |
Correct |
606 ms |
82468 KB |
n=200000 |
120 |
Correct |
948 ms |
93144 KB |
n=200000 |
121 |
Correct |
909 ms |
93324 KB |
n=200000 |
122 |
Correct |
917 ms |
93636 KB |
n=200000 |
123 |
Correct |
414 ms |
83324 KB |
n=200000 |
124 |
Correct |
243 ms |
39156 KB |
n=25264 |