#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define endl '\n'
#define fi first
#define se second
#define For(i, l, r) for (int i = l; i < r; i++)
#define ForE(i, l, r) for (int i = l; i <= r; i++)
#define FordE(i, l, r) for (int i = l; i >= r; i--)
#define Fora(v, a) for (auto v: a)
#define bend(a) a.begin(), a.end()
#define isz(a) ((signed)a.size())
using ll = long long;
using ld = long double;
using pii = pair <int, int>;
using vi = vector <int>;
using vpii = vector <pii>;
using vvi = vector <vi>;
const int N = 2e5 + 5, M = __lg(N) + 2;
int n, m, q;
vi adj[N];
int a[N];
int h[N];
int ctrtime, tin[N], tout[N]; pii sptable[M][2 * N];
void dfs_tour(int u, int p){
tin[u] = tout[u] = ++ctrtime; sptable[0][ctrtime] = {h[u], u};
Fora(&v, adj[u]){
if (v == p){
continue;
}
h[v] = h[u] + 1;
dfs_tour(v, u);
tout[u] = ++ctrtime; sptable[0][ctrtime] = {h[u], u};
}
}
int lca(int u, int v){
int l = min(tin[u], tin[v]), r = max(tout[u], tout[v]), z = __lg(r - l + 1);
return min(sptable[z][l], sptable[z][r - (1 << z) + 1]).se;
}
set <int> stt1[N], stt2[N];
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
// freopen(".inp", "r", stdin);
// freopen(".out", "w", stdout);
cin >> n >> m >> q;
For(i, 1, n){
int u, v; cin >> u >> v;
adj[u].emplace_back(v);
adj[v].emplace_back(u);
}
ForE(i, 1, m){
cin >> a[i];
}
dfs_tour(1, 1);
For(j, 1, M){
ForE(i, 1, ctrtime - (1 << j) + 1){
sptable[j][i] = min(sptable[j - 1][i], sptable[j - 1][i + (1 << (j - 1))]);
}
}
ForE(i, 1, m){
stt1[a[i]].insert(i);
}
ForE(i, 2, m){
stt2[lca(a[i - 1], a[i])].insert(i);
}
while (q--){
int que; cin >> que;
if (que == 1){
int pos, u; cin >> pos >> u;
stt1[a[pos]].erase(pos);
if (pos > 1){
stt2[lca(a[pos - 1], a[pos])].erase(pos);
}
if (pos < m){
stt2[lca(a[pos], a[pos + 1])].erase(pos + 1);
}
a[pos] = u;
stt1[a[pos]].insert(pos);
if (pos > 1){
stt2[lca(a[pos - 1], a[pos])].insert(pos);
}
if (pos < m){
stt2[lca(a[pos], a[pos + 1])].insert(pos + 1);
}
}
else{
int l, r, u; cin >> l >> r >> u;
set <int>::iterator itr;
itr = stt1[u].lower_bound(l);
if (itr != stt1[u].end() and (*itr) <= r){
cout << (*itr) << ' ' << (*itr) << endl;
continue;
}
itr = stt2[u].lower_bound(l + 1);
if (itr != stt2[u].end() and (*itr) <= r){
cout << (*itr) - 1 << ' ' << (*itr) << endl;
continue;
}
cout << -1 << ' ' << -1 << endl;
}
}
}
/*
==================================================+
INPUT: |
--------------------------------------------------|
5 4 4
1 2
3 1
3 4
5 3
4 5 2 3
2 1 3 1
1 3 5
2 3 4 5
2 1 3 1
--------------------------------------------------|
==================================================+
OUTPUT: |
--------------------------------------------------|
1 3
3 3
-1 -1
--------------------------------------------------|
==================================================+
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23756 KB |
n=5 |
2 |
Correct |
13 ms |
23884 KB |
n=100 |
3 |
Correct |
13 ms |
23884 KB |
n=100 |
4 |
Correct |
13 ms |
23856 KB |
n=100 |
5 |
Correct |
13 ms |
23884 KB |
n=100 |
6 |
Correct |
13 ms |
23868 KB |
n=100 |
7 |
Correct |
13 ms |
23824 KB |
n=100 |
8 |
Correct |
14 ms |
23884 KB |
n=100 |
9 |
Correct |
15 ms |
23832 KB |
n=100 |
10 |
Correct |
13 ms |
23884 KB |
n=100 |
11 |
Correct |
14 ms |
23896 KB |
n=100 |
12 |
Correct |
13 ms |
23900 KB |
n=100 |
13 |
Correct |
14 ms |
23872 KB |
n=100 |
14 |
Correct |
13 ms |
23884 KB |
n=100 |
15 |
Correct |
13 ms |
23884 KB |
n=100 |
16 |
Correct |
13 ms |
23884 KB |
n=100 |
17 |
Correct |
13 ms |
23876 KB |
n=100 |
18 |
Correct |
13 ms |
23884 KB |
n=100 |
19 |
Correct |
13 ms |
23812 KB |
n=100 |
20 |
Correct |
13 ms |
23884 KB |
n=100 |
21 |
Correct |
13 ms |
23884 KB |
n=100 |
22 |
Correct |
13 ms |
23884 KB |
n=100 |
23 |
Correct |
14 ms |
23884 KB |
n=100 |
24 |
Correct |
13 ms |
23884 KB |
n=100 |
25 |
Correct |
13 ms |
23896 KB |
n=100 |
26 |
Correct |
13 ms |
23756 KB |
n=12 |
27 |
Correct |
15 ms |
23904 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23756 KB |
n=5 |
2 |
Correct |
13 ms |
23884 KB |
n=100 |
3 |
Correct |
13 ms |
23884 KB |
n=100 |
4 |
Correct |
13 ms |
23856 KB |
n=100 |
5 |
Correct |
13 ms |
23884 KB |
n=100 |
6 |
Correct |
13 ms |
23868 KB |
n=100 |
7 |
Correct |
13 ms |
23824 KB |
n=100 |
8 |
Correct |
14 ms |
23884 KB |
n=100 |
9 |
Correct |
15 ms |
23832 KB |
n=100 |
10 |
Correct |
13 ms |
23884 KB |
n=100 |
11 |
Correct |
14 ms |
23896 KB |
n=100 |
12 |
Correct |
13 ms |
23900 KB |
n=100 |
13 |
Correct |
14 ms |
23872 KB |
n=100 |
14 |
Correct |
13 ms |
23884 KB |
n=100 |
15 |
Correct |
13 ms |
23884 KB |
n=100 |
16 |
Correct |
13 ms |
23884 KB |
n=100 |
17 |
Correct |
13 ms |
23876 KB |
n=100 |
18 |
Correct |
13 ms |
23884 KB |
n=100 |
19 |
Correct |
13 ms |
23812 KB |
n=100 |
20 |
Correct |
13 ms |
23884 KB |
n=100 |
21 |
Correct |
13 ms |
23884 KB |
n=100 |
22 |
Correct |
13 ms |
23884 KB |
n=100 |
23 |
Correct |
14 ms |
23884 KB |
n=100 |
24 |
Correct |
13 ms |
23884 KB |
n=100 |
25 |
Correct |
13 ms |
23896 KB |
n=100 |
26 |
Correct |
13 ms |
23756 KB |
n=12 |
27 |
Correct |
15 ms |
23904 KB |
n=100 |
28 |
Correct |
14 ms |
24012 KB |
n=500 |
29 |
Correct |
14 ms |
24012 KB |
n=500 |
30 |
Correct |
16 ms |
24012 KB |
n=500 |
31 |
Correct |
14 ms |
24012 KB |
n=500 |
32 |
Correct |
14 ms |
24024 KB |
n=500 |
33 |
Correct |
14 ms |
24012 KB |
n=500 |
34 |
Correct |
14 ms |
24012 KB |
n=500 |
35 |
Correct |
14 ms |
24004 KB |
n=500 |
36 |
Correct |
14 ms |
23992 KB |
n=500 |
37 |
Correct |
14 ms |
24012 KB |
n=500 |
38 |
Correct |
14 ms |
23980 KB |
n=500 |
39 |
Correct |
15 ms |
24032 KB |
n=500 |
40 |
Correct |
14 ms |
23972 KB |
n=500 |
41 |
Correct |
14 ms |
23952 KB |
n=500 |
42 |
Correct |
15 ms |
23952 KB |
n=500 |
43 |
Correct |
14 ms |
24012 KB |
n=500 |
44 |
Correct |
14 ms |
24036 KB |
n=500 |
45 |
Correct |
14 ms |
24012 KB |
n=500 |
46 |
Correct |
14 ms |
24052 KB |
n=500 |
47 |
Correct |
15 ms |
24016 KB |
n=500 |
48 |
Correct |
14 ms |
23988 KB |
n=500 |
49 |
Correct |
15 ms |
24012 KB |
n=500 |
50 |
Correct |
14 ms |
24036 KB |
n=500 |
51 |
Correct |
14 ms |
24004 KB |
n=500 |
52 |
Correct |
14 ms |
24012 KB |
n=500 |
53 |
Correct |
14 ms |
24012 KB |
n=500 |
54 |
Correct |
14 ms |
24048 KB |
n=500 |
55 |
Correct |
13 ms |
23884 KB |
n=278 |
56 |
Correct |
14 ms |
23964 KB |
n=500 |
57 |
Correct |
14 ms |
24012 KB |
n=500 |
58 |
Correct |
15 ms |
24012 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23756 KB |
n=5 |
2 |
Correct |
13 ms |
23884 KB |
n=100 |
3 |
Correct |
13 ms |
23884 KB |
n=100 |
4 |
Correct |
13 ms |
23856 KB |
n=100 |
5 |
Correct |
13 ms |
23884 KB |
n=100 |
6 |
Correct |
13 ms |
23868 KB |
n=100 |
7 |
Correct |
13 ms |
23824 KB |
n=100 |
8 |
Correct |
14 ms |
23884 KB |
n=100 |
9 |
Correct |
15 ms |
23832 KB |
n=100 |
10 |
Correct |
13 ms |
23884 KB |
n=100 |
11 |
Correct |
14 ms |
23896 KB |
n=100 |
12 |
Correct |
13 ms |
23900 KB |
n=100 |
13 |
Correct |
14 ms |
23872 KB |
n=100 |
14 |
Correct |
13 ms |
23884 KB |
n=100 |
15 |
Correct |
13 ms |
23884 KB |
n=100 |
16 |
Correct |
13 ms |
23884 KB |
n=100 |
17 |
Correct |
13 ms |
23876 KB |
n=100 |
18 |
Correct |
13 ms |
23884 KB |
n=100 |
19 |
Correct |
13 ms |
23812 KB |
n=100 |
20 |
Correct |
13 ms |
23884 KB |
n=100 |
21 |
Correct |
13 ms |
23884 KB |
n=100 |
22 |
Correct |
13 ms |
23884 KB |
n=100 |
23 |
Correct |
14 ms |
23884 KB |
n=100 |
24 |
Correct |
13 ms |
23884 KB |
n=100 |
25 |
Correct |
13 ms |
23896 KB |
n=100 |
26 |
Correct |
13 ms |
23756 KB |
n=12 |
27 |
Correct |
15 ms |
23904 KB |
n=100 |
28 |
Correct |
14 ms |
24012 KB |
n=500 |
29 |
Correct |
14 ms |
24012 KB |
n=500 |
30 |
Correct |
16 ms |
24012 KB |
n=500 |
31 |
Correct |
14 ms |
24012 KB |
n=500 |
32 |
Correct |
14 ms |
24024 KB |
n=500 |
33 |
Correct |
14 ms |
24012 KB |
n=500 |
34 |
Correct |
14 ms |
24012 KB |
n=500 |
35 |
Correct |
14 ms |
24004 KB |
n=500 |
36 |
Correct |
14 ms |
23992 KB |
n=500 |
37 |
Correct |
14 ms |
24012 KB |
n=500 |
38 |
Correct |
14 ms |
23980 KB |
n=500 |
39 |
Correct |
15 ms |
24032 KB |
n=500 |
40 |
Correct |
14 ms |
23972 KB |
n=500 |
41 |
Correct |
14 ms |
23952 KB |
n=500 |
42 |
Correct |
15 ms |
23952 KB |
n=500 |
43 |
Correct |
14 ms |
24012 KB |
n=500 |
44 |
Correct |
14 ms |
24036 KB |
n=500 |
45 |
Correct |
14 ms |
24012 KB |
n=500 |
46 |
Correct |
14 ms |
24052 KB |
n=500 |
47 |
Correct |
15 ms |
24016 KB |
n=500 |
48 |
Correct |
14 ms |
23988 KB |
n=500 |
49 |
Correct |
15 ms |
24012 KB |
n=500 |
50 |
Correct |
14 ms |
24036 KB |
n=500 |
51 |
Correct |
14 ms |
24004 KB |
n=500 |
52 |
Correct |
14 ms |
24012 KB |
n=500 |
53 |
Correct |
14 ms |
24012 KB |
n=500 |
54 |
Correct |
14 ms |
24048 KB |
n=500 |
55 |
Correct |
13 ms |
23884 KB |
n=278 |
56 |
Correct |
14 ms |
23964 KB |
n=500 |
57 |
Correct |
14 ms |
24012 KB |
n=500 |
58 |
Correct |
15 ms |
24012 KB |
n=500 |
59 |
Correct |
17 ms |
24556 KB |
n=2000 |
60 |
Correct |
16 ms |
24652 KB |
n=2000 |
61 |
Correct |
17 ms |
24564 KB |
n=2000 |
62 |
Correct |
17 ms |
24568 KB |
n=2000 |
63 |
Correct |
17 ms |
24436 KB |
n=2000 |
64 |
Correct |
17 ms |
24524 KB |
n=2000 |
65 |
Correct |
17 ms |
24524 KB |
n=2000 |
66 |
Correct |
16 ms |
24620 KB |
n=2000 |
67 |
Correct |
17 ms |
24444 KB |
n=2000 |
68 |
Correct |
16 ms |
24524 KB |
n=2000 |
69 |
Correct |
17 ms |
24540 KB |
n=2000 |
70 |
Correct |
17 ms |
24568 KB |
n=2000 |
71 |
Correct |
16 ms |
24484 KB |
n=2000 |
72 |
Correct |
16 ms |
24524 KB |
n=2000 |
73 |
Correct |
16 ms |
24484 KB |
n=2000 |
74 |
Correct |
16 ms |
24408 KB |
n=1844 |
75 |
Correct |
16 ms |
24468 KB |
n=2000 |
76 |
Correct |
17 ms |
24524 KB |
n=2000 |
77 |
Correct |
17 ms |
24544 KB |
n=2000 |
78 |
Correct |
17 ms |
24524 KB |
n=2000 |
79 |
Correct |
17 ms |
24480 KB |
n=2000 |
80 |
Correct |
16 ms |
24652 KB |
n=2000 |
81 |
Correct |
17 ms |
24492 KB |
n=2000 |
82 |
Correct |
17 ms |
24524 KB |
n=2000 |
83 |
Correct |
16 ms |
24572 KB |
n=2000 |
84 |
Correct |
17 ms |
24560 KB |
n=2000 |
85 |
Correct |
17 ms |
24504 KB |
n=2000 |
86 |
Correct |
16 ms |
24524 KB |
n=2000 |
87 |
Correct |
18 ms |
24524 KB |
n=2000 |
88 |
Correct |
16 ms |
24780 KB |
n=2000 |
89 |
Correct |
17 ms |
24704 KB |
n=2000 |
90 |
Correct |
16 ms |
24652 KB |
n=2000 |
91 |
Correct |
16 ms |
24524 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23756 KB |
n=5 |
2 |
Correct |
13 ms |
23884 KB |
n=100 |
3 |
Correct |
13 ms |
23884 KB |
n=100 |
4 |
Correct |
13 ms |
23856 KB |
n=100 |
5 |
Correct |
13 ms |
23884 KB |
n=100 |
6 |
Correct |
13 ms |
23868 KB |
n=100 |
7 |
Correct |
13 ms |
23824 KB |
n=100 |
8 |
Correct |
14 ms |
23884 KB |
n=100 |
9 |
Correct |
15 ms |
23832 KB |
n=100 |
10 |
Correct |
13 ms |
23884 KB |
n=100 |
11 |
Correct |
14 ms |
23896 KB |
n=100 |
12 |
Correct |
13 ms |
23900 KB |
n=100 |
13 |
Correct |
14 ms |
23872 KB |
n=100 |
14 |
Correct |
13 ms |
23884 KB |
n=100 |
15 |
Correct |
13 ms |
23884 KB |
n=100 |
16 |
Correct |
13 ms |
23884 KB |
n=100 |
17 |
Correct |
13 ms |
23876 KB |
n=100 |
18 |
Correct |
13 ms |
23884 KB |
n=100 |
19 |
Correct |
13 ms |
23812 KB |
n=100 |
20 |
Correct |
13 ms |
23884 KB |
n=100 |
21 |
Correct |
13 ms |
23884 KB |
n=100 |
22 |
Correct |
13 ms |
23884 KB |
n=100 |
23 |
Correct |
14 ms |
23884 KB |
n=100 |
24 |
Correct |
13 ms |
23884 KB |
n=100 |
25 |
Correct |
13 ms |
23896 KB |
n=100 |
26 |
Correct |
13 ms |
23756 KB |
n=12 |
27 |
Correct |
15 ms |
23904 KB |
n=100 |
28 |
Correct |
14 ms |
24012 KB |
n=500 |
29 |
Correct |
14 ms |
24012 KB |
n=500 |
30 |
Correct |
16 ms |
24012 KB |
n=500 |
31 |
Correct |
14 ms |
24012 KB |
n=500 |
32 |
Correct |
14 ms |
24024 KB |
n=500 |
33 |
Correct |
14 ms |
24012 KB |
n=500 |
34 |
Correct |
14 ms |
24012 KB |
n=500 |
35 |
Correct |
14 ms |
24004 KB |
n=500 |
36 |
Correct |
14 ms |
23992 KB |
n=500 |
37 |
Correct |
14 ms |
24012 KB |
n=500 |
38 |
Correct |
14 ms |
23980 KB |
n=500 |
39 |
Correct |
15 ms |
24032 KB |
n=500 |
40 |
Correct |
14 ms |
23972 KB |
n=500 |
41 |
Correct |
14 ms |
23952 KB |
n=500 |
42 |
Correct |
15 ms |
23952 KB |
n=500 |
43 |
Correct |
14 ms |
24012 KB |
n=500 |
44 |
Correct |
14 ms |
24036 KB |
n=500 |
45 |
Correct |
14 ms |
24012 KB |
n=500 |
46 |
Correct |
14 ms |
24052 KB |
n=500 |
47 |
Correct |
15 ms |
24016 KB |
n=500 |
48 |
Correct |
14 ms |
23988 KB |
n=500 |
49 |
Correct |
15 ms |
24012 KB |
n=500 |
50 |
Correct |
14 ms |
24036 KB |
n=500 |
51 |
Correct |
14 ms |
24004 KB |
n=500 |
52 |
Correct |
14 ms |
24012 KB |
n=500 |
53 |
Correct |
14 ms |
24012 KB |
n=500 |
54 |
Correct |
14 ms |
24048 KB |
n=500 |
55 |
Correct |
13 ms |
23884 KB |
n=278 |
56 |
Correct |
14 ms |
23964 KB |
n=500 |
57 |
Correct |
14 ms |
24012 KB |
n=500 |
58 |
Correct |
15 ms |
24012 KB |
n=500 |
59 |
Correct |
17 ms |
24556 KB |
n=2000 |
60 |
Correct |
16 ms |
24652 KB |
n=2000 |
61 |
Correct |
17 ms |
24564 KB |
n=2000 |
62 |
Correct |
17 ms |
24568 KB |
n=2000 |
63 |
Correct |
17 ms |
24436 KB |
n=2000 |
64 |
Correct |
17 ms |
24524 KB |
n=2000 |
65 |
Correct |
17 ms |
24524 KB |
n=2000 |
66 |
Correct |
16 ms |
24620 KB |
n=2000 |
67 |
Correct |
17 ms |
24444 KB |
n=2000 |
68 |
Correct |
16 ms |
24524 KB |
n=2000 |
69 |
Correct |
17 ms |
24540 KB |
n=2000 |
70 |
Correct |
17 ms |
24568 KB |
n=2000 |
71 |
Correct |
16 ms |
24484 KB |
n=2000 |
72 |
Correct |
16 ms |
24524 KB |
n=2000 |
73 |
Correct |
16 ms |
24484 KB |
n=2000 |
74 |
Correct |
16 ms |
24408 KB |
n=1844 |
75 |
Correct |
16 ms |
24468 KB |
n=2000 |
76 |
Correct |
17 ms |
24524 KB |
n=2000 |
77 |
Correct |
17 ms |
24544 KB |
n=2000 |
78 |
Correct |
17 ms |
24524 KB |
n=2000 |
79 |
Correct |
17 ms |
24480 KB |
n=2000 |
80 |
Correct |
16 ms |
24652 KB |
n=2000 |
81 |
Correct |
17 ms |
24492 KB |
n=2000 |
82 |
Correct |
17 ms |
24524 KB |
n=2000 |
83 |
Correct |
16 ms |
24572 KB |
n=2000 |
84 |
Correct |
17 ms |
24560 KB |
n=2000 |
85 |
Correct |
17 ms |
24504 KB |
n=2000 |
86 |
Correct |
16 ms |
24524 KB |
n=2000 |
87 |
Correct |
18 ms |
24524 KB |
n=2000 |
88 |
Correct |
16 ms |
24780 KB |
n=2000 |
89 |
Correct |
17 ms |
24704 KB |
n=2000 |
90 |
Correct |
16 ms |
24652 KB |
n=2000 |
91 |
Correct |
16 ms |
24524 KB |
n=2000 |
92 |
Correct |
784 ms |
109416 KB |
n=200000 |
93 |
Correct |
716 ms |
119408 KB |
n=200000 |
94 |
Correct |
647 ms |
129408 KB |
n=200000 |
95 |
Correct |
730 ms |
115708 KB |
n=200000 |
96 |
Correct |
696 ms |
115692 KB |
n=200000 |
97 |
Correct |
707 ms |
122372 KB |
n=200000 |
98 |
Correct |
722 ms |
115636 KB |
n=200000 |
99 |
Correct |
801 ms |
115844 KB |
n=200000 |
100 |
Correct |
719 ms |
115764 KB |
n=200000 |
101 |
Correct |
676 ms |
131512 KB |
n=200000 |
102 |
Correct |
451 ms |
116932 KB |
n=200000 |
103 |
Correct |
460 ms |
116852 KB |
n=200000 |
104 |
Correct |
443 ms |
116908 KB |
n=200000 |
105 |
Correct |
440 ms |
117244 KB |
n=200000 |
106 |
Correct |
485 ms |
117192 KB |
n=200000 |
107 |
Correct |
446 ms |
117184 KB |
n=200000 |
108 |
Correct |
791 ms |
115712 KB |
n=200000 |
109 |
Correct |
796 ms |
115688 KB |
n=200000 |
110 |
Correct |
753 ms |
115780 KB |
n=200000 |
111 |
Correct |
693 ms |
115160 KB |
n=200000 |
112 |
Correct |
678 ms |
129896 KB |
n=200000 |
113 |
Correct |
758 ms |
122364 KB |
n=200000 |
114 |
Correct |
753 ms |
115160 KB |
n=200000 |
115 |
Correct |
854 ms |
118756 KB |
n=200000 |
116 |
Correct |
712 ms |
115760 KB |
n=200000 |
117 |
Correct |
675 ms |
130680 KB |
n=200000 |
118 |
Correct |
766 ms |
120512 KB |
n=200000 |
119 |
Correct |
719 ms |
115896 KB |
n=200000 |
120 |
Correct |
635 ms |
130536 KB |
n=200000 |
121 |
Correct |
630 ms |
130500 KB |
n=200000 |
122 |
Correct |
620 ms |
130892 KB |
n=200000 |
123 |
Correct |
482 ms |
117048 KB |
n=200000 |
124 |
Correct |
190 ms |
43460 KB |
n=25264 |