#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define int long long
template <class F, class _S>
bool chmin(F &u, const _S &v){
bool flag = false;
if ( u > v ){
u = v; flag |= true;
}
return flag;
}
template <class F, class _S>
bool chmax(F &u, const _S &v){
bool flag = false;
if ( u < v ){
u = v; flag |= true;
}
return flag;
}
const int N = (1<<18) +1, inf = 1e18+200;
//int mod = 998244353;
//int mod = 1000000007;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//#define rnd(l, r) uniform_int_distribution <int> (l, r)(rng)
void solve(){
int n, m, q;
cin >> n >> m >> q;
vector<vector<int>> g(n+1);
for(int i = 1; i < n; i++){
int u, v;
cin >> u >> v;
g[u].pb(v);
g[v].pb(u);
}
vector<int> tin(n+1), tout(n+1);
vector<vector<int>> ln(22, vector<int> (n+1, 1));
int timer = 0;
auto dfs = [&](auto dfs, int ps, int pr) -> void{
ln[0][ps] = pr;
tin[ps] = timer++;
for(int i = 1; i < 20; i++)
ln[i][ps] = ln[i-1][ln[i-1][ps]];
for(int to:g[ps]){
if(to == pr)continue;
dfs(dfs, to, ps);
}
tout[ps] = timer++;
};
dfs(dfs, 1, 1);
auto lca = [&](int a, int b) -> int {
if(tin[b] <= tin[a] && tout[a] <= tout[b])return b;
if(tin[a] <= tin[b] && tout[b] <= tout[a])return a;
for(int i = 19; i >= 0; i--){
int na = ln[i][a];
if(tin[na] <= tin[b] && tout[b] <= tout[na])continue;
a = na;
}
return ln[0][a];
};
vector<multiset<int>> st(n+1);
vector<multiset<int>> sv(n+1);
vector<int> a(m+1);
for(int i = 1; i <= m; i++){
cin >> a[i];
st[a[i]].insert(i);
if(i > 1)sv[lca(a[i], a[i-1])].insert(i);
}
while(q--){
int ty;
cin >> ty;
if(ty == 1){
int ps, va;
cin >> ps >> va;
st[a[ps]].erase(st[a[ps]].find(ps));
if(ps > 1){
int x = lca(a[ps], a[ps-1]);
sv[x].erase(sv[x].find(ps));
}
if(ps < m){
int x = lca(a[ps] , a[ps+1]);
sv[x].erase(sv[x].find(ps+1));
}
a[ps] = va;
st[va].insert(ps);
if(ps > 1){
int x = lca(a[ps], a[ps-1]);
sv[x].insert(ps);
}
if(ps < m){
int x = lca(a[ps] , a[ps+1]);
sv[x].insert(ps+1);
}
}else{
int l, r, v;
cin >> l >> r >> v;
if(!st[v].empty()){
//cout << *(--st[v].end()) << '\n';
auto x = st[v].lower_bound(l);
if(l <= *x && *x <= r){
cout << *x << ' ' << *x << '\n';
continue;
}
if(*x != *(--st[v].end())){
x++;
if(l <= *x && *x <= r){
cout << *x << ' ' << *x << '\n';
continue;
}
}
}
if(!sv[v].empty()){
//cout << *(--sv[v].end()) << '\n';
auto y = sv[v].lower_bound(l);
if(l < *y && *y <= r){
cout << *y-1 << ' ' << *y << '\n';
continue;
}
if(*y != *(--sv[v].end())){
y++;
if(l < *y && *y <= r){
cout << *y-1 << ' ' << *y << '\n';
continue;
}
}
}
cout << -1 << ' ' << -1 << '\n';
}
}
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int tt = 1;
//cin >> tt;
while(tt--){
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
n=5 |
2 |
Correct |
0 ms |
348 KB |
n=100 |
3 |
Correct |
1 ms |
348 KB |
n=100 |
4 |
Correct |
0 ms |
348 KB |
n=100 |
5 |
Correct |
0 ms |
348 KB |
n=100 |
6 |
Correct |
1 ms |
344 KB |
n=100 |
7 |
Correct |
0 ms |
348 KB |
n=100 |
8 |
Correct |
0 ms |
344 KB |
n=100 |
9 |
Correct |
0 ms |
348 KB |
n=100 |
10 |
Correct |
0 ms |
348 KB |
n=100 |
11 |
Correct |
0 ms |
360 KB |
n=100 |
12 |
Correct |
0 ms |
348 KB |
n=100 |
13 |
Correct |
0 ms |
348 KB |
n=100 |
14 |
Correct |
0 ms |
348 KB |
n=100 |
15 |
Correct |
1 ms |
348 KB |
n=100 |
16 |
Correct |
1 ms |
344 KB |
n=100 |
17 |
Correct |
0 ms |
348 KB |
n=100 |
18 |
Correct |
0 ms |
348 KB |
n=100 |
19 |
Correct |
0 ms |
348 KB |
n=100 |
20 |
Correct |
0 ms |
348 KB |
n=100 |
21 |
Correct |
0 ms |
348 KB |
n=100 |
22 |
Correct |
0 ms |
348 KB |
n=100 |
23 |
Correct |
0 ms |
348 KB |
n=100 |
24 |
Correct |
0 ms |
348 KB |
n=100 |
25 |
Correct |
1 ms |
348 KB |
n=100 |
26 |
Correct |
0 ms |
348 KB |
n=12 |
27 |
Correct |
0 ms |
348 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
n=5 |
2 |
Correct |
0 ms |
348 KB |
n=100 |
3 |
Correct |
1 ms |
348 KB |
n=100 |
4 |
Correct |
0 ms |
348 KB |
n=100 |
5 |
Correct |
0 ms |
348 KB |
n=100 |
6 |
Correct |
1 ms |
344 KB |
n=100 |
7 |
Correct |
0 ms |
348 KB |
n=100 |
8 |
Correct |
0 ms |
344 KB |
n=100 |
9 |
Correct |
0 ms |
348 KB |
n=100 |
10 |
Correct |
0 ms |
348 KB |
n=100 |
11 |
Correct |
0 ms |
360 KB |
n=100 |
12 |
Correct |
0 ms |
348 KB |
n=100 |
13 |
Correct |
0 ms |
348 KB |
n=100 |
14 |
Correct |
0 ms |
348 KB |
n=100 |
15 |
Correct |
1 ms |
348 KB |
n=100 |
16 |
Correct |
1 ms |
344 KB |
n=100 |
17 |
Correct |
0 ms |
348 KB |
n=100 |
18 |
Correct |
0 ms |
348 KB |
n=100 |
19 |
Correct |
0 ms |
348 KB |
n=100 |
20 |
Correct |
0 ms |
348 KB |
n=100 |
21 |
Correct |
0 ms |
348 KB |
n=100 |
22 |
Correct |
0 ms |
348 KB |
n=100 |
23 |
Correct |
0 ms |
348 KB |
n=100 |
24 |
Correct |
0 ms |
348 KB |
n=100 |
25 |
Correct |
1 ms |
348 KB |
n=100 |
26 |
Correct |
0 ms |
348 KB |
n=12 |
27 |
Correct |
0 ms |
348 KB |
n=100 |
28 |
Correct |
1 ms |
604 KB |
n=500 |
29 |
Correct |
1 ms |
604 KB |
n=500 |
30 |
Correct |
1 ms |
604 KB |
n=500 |
31 |
Correct |
1 ms |
604 KB |
n=500 |
32 |
Correct |
1 ms |
604 KB |
n=500 |
33 |
Correct |
1 ms |
604 KB |
n=500 |
34 |
Correct |
1 ms |
600 KB |
n=500 |
35 |
Correct |
1 ms |
604 KB |
n=500 |
36 |
Correct |
1 ms |
604 KB |
n=500 |
37 |
Correct |
1 ms |
464 KB |
n=500 |
38 |
Correct |
1 ms |
604 KB |
n=500 |
39 |
Correct |
1 ms |
604 KB |
n=500 |
40 |
Correct |
1 ms |
604 KB |
n=500 |
41 |
Correct |
1 ms |
604 KB |
n=500 |
42 |
Correct |
1 ms |
600 KB |
n=500 |
43 |
Correct |
1 ms |
856 KB |
n=500 |
44 |
Correct |
1 ms |
604 KB |
n=500 |
45 |
Correct |
1 ms |
604 KB |
n=500 |
46 |
Correct |
1 ms |
604 KB |
n=500 |
47 |
Correct |
1 ms |
604 KB |
n=500 |
48 |
Correct |
1 ms |
604 KB |
n=500 |
49 |
Correct |
1 ms |
604 KB |
n=500 |
50 |
Correct |
1 ms |
604 KB |
n=500 |
51 |
Correct |
1 ms |
600 KB |
n=500 |
52 |
Correct |
1 ms |
604 KB |
n=500 |
53 |
Correct |
1 ms |
600 KB |
n=500 |
54 |
Correct |
1 ms |
600 KB |
n=500 |
55 |
Correct |
1 ms |
600 KB |
n=278 |
56 |
Correct |
1 ms |
604 KB |
n=500 |
57 |
Correct |
1 ms |
600 KB |
n=500 |
58 |
Correct |
1 ms |
464 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
n=5 |
2 |
Correct |
0 ms |
348 KB |
n=100 |
3 |
Correct |
1 ms |
348 KB |
n=100 |
4 |
Correct |
0 ms |
348 KB |
n=100 |
5 |
Correct |
0 ms |
348 KB |
n=100 |
6 |
Correct |
1 ms |
344 KB |
n=100 |
7 |
Correct |
0 ms |
348 KB |
n=100 |
8 |
Correct |
0 ms |
344 KB |
n=100 |
9 |
Correct |
0 ms |
348 KB |
n=100 |
10 |
Correct |
0 ms |
348 KB |
n=100 |
11 |
Correct |
0 ms |
360 KB |
n=100 |
12 |
Correct |
0 ms |
348 KB |
n=100 |
13 |
Correct |
0 ms |
348 KB |
n=100 |
14 |
Correct |
0 ms |
348 KB |
n=100 |
15 |
Correct |
1 ms |
348 KB |
n=100 |
16 |
Correct |
1 ms |
344 KB |
n=100 |
17 |
Correct |
0 ms |
348 KB |
n=100 |
18 |
Correct |
0 ms |
348 KB |
n=100 |
19 |
Correct |
0 ms |
348 KB |
n=100 |
20 |
Correct |
0 ms |
348 KB |
n=100 |
21 |
Correct |
0 ms |
348 KB |
n=100 |
22 |
Correct |
0 ms |
348 KB |
n=100 |
23 |
Correct |
0 ms |
348 KB |
n=100 |
24 |
Correct |
0 ms |
348 KB |
n=100 |
25 |
Correct |
1 ms |
348 KB |
n=100 |
26 |
Correct |
0 ms |
348 KB |
n=12 |
27 |
Correct |
0 ms |
348 KB |
n=100 |
28 |
Correct |
1 ms |
604 KB |
n=500 |
29 |
Correct |
1 ms |
604 KB |
n=500 |
30 |
Correct |
1 ms |
604 KB |
n=500 |
31 |
Correct |
1 ms |
604 KB |
n=500 |
32 |
Correct |
1 ms |
604 KB |
n=500 |
33 |
Correct |
1 ms |
604 KB |
n=500 |
34 |
Correct |
1 ms |
600 KB |
n=500 |
35 |
Correct |
1 ms |
604 KB |
n=500 |
36 |
Correct |
1 ms |
604 KB |
n=500 |
37 |
Correct |
1 ms |
464 KB |
n=500 |
38 |
Correct |
1 ms |
604 KB |
n=500 |
39 |
Correct |
1 ms |
604 KB |
n=500 |
40 |
Correct |
1 ms |
604 KB |
n=500 |
41 |
Correct |
1 ms |
604 KB |
n=500 |
42 |
Correct |
1 ms |
600 KB |
n=500 |
43 |
Correct |
1 ms |
856 KB |
n=500 |
44 |
Correct |
1 ms |
604 KB |
n=500 |
45 |
Correct |
1 ms |
604 KB |
n=500 |
46 |
Correct |
1 ms |
604 KB |
n=500 |
47 |
Correct |
1 ms |
604 KB |
n=500 |
48 |
Correct |
1 ms |
604 KB |
n=500 |
49 |
Correct |
1 ms |
604 KB |
n=500 |
50 |
Correct |
1 ms |
604 KB |
n=500 |
51 |
Correct |
1 ms |
600 KB |
n=500 |
52 |
Correct |
1 ms |
604 KB |
n=500 |
53 |
Correct |
1 ms |
600 KB |
n=500 |
54 |
Correct |
1 ms |
600 KB |
n=500 |
55 |
Correct |
1 ms |
600 KB |
n=278 |
56 |
Correct |
1 ms |
604 KB |
n=500 |
57 |
Correct |
1 ms |
600 KB |
n=500 |
58 |
Correct |
1 ms |
464 KB |
n=500 |
59 |
Correct |
3 ms |
1368 KB |
n=2000 |
60 |
Correct |
2 ms |
1372 KB |
n=2000 |
61 |
Correct |
3 ms |
1372 KB |
n=2000 |
62 |
Correct |
3 ms |
1372 KB |
n=2000 |
63 |
Correct |
4 ms |
1372 KB |
n=2000 |
64 |
Correct |
4 ms |
1372 KB |
n=2000 |
65 |
Correct |
3 ms |
1372 KB |
n=2000 |
66 |
Correct |
2 ms |
1368 KB |
n=2000 |
67 |
Correct |
3 ms |
1372 KB |
n=2000 |
68 |
Correct |
3 ms |
1372 KB |
n=2000 |
69 |
Correct |
2 ms |
1372 KB |
n=2000 |
70 |
Correct |
2 ms |
1372 KB |
n=2000 |
71 |
Correct |
2 ms |
1372 KB |
n=2000 |
72 |
Correct |
2 ms |
1372 KB |
n=2000 |
73 |
Correct |
3 ms |
1376 KB |
n=2000 |
74 |
Correct |
3 ms |
1120 KB |
n=1844 |
75 |
Correct |
2 ms |
1396 KB |
n=2000 |
76 |
Correct |
3 ms |
1384 KB |
n=2000 |
77 |
Correct |
3 ms |
1376 KB |
n=2000 |
78 |
Correct |
3 ms |
1372 KB |
n=2000 |
79 |
Correct |
3 ms |
1368 KB |
n=2000 |
80 |
Correct |
2 ms |
1372 KB |
n=2000 |
81 |
Correct |
3 ms |
1372 KB |
n=2000 |
82 |
Correct |
5 ms |
1372 KB |
n=2000 |
83 |
Correct |
2 ms |
1372 KB |
n=2000 |
84 |
Correct |
3 ms |
1372 KB |
n=2000 |
85 |
Correct |
3 ms |
1372 KB |
n=2000 |
86 |
Correct |
3 ms |
1372 KB |
n=2000 |
87 |
Correct |
3 ms |
1372 KB |
n=2000 |
88 |
Correct |
2 ms |
1372 KB |
n=2000 |
89 |
Correct |
2 ms |
1372 KB |
n=2000 |
90 |
Correct |
2 ms |
1372 KB |
n=2000 |
91 |
Correct |
2 ms |
1372 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
n=5 |
2 |
Correct |
0 ms |
348 KB |
n=100 |
3 |
Correct |
1 ms |
348 KB |
n=100 |
4 |
Correct |
0 ms |
348 KB |
n=100 |
5 |
Correct |
0 ms |
348 KB |
n=100 |
6 |
Correct |
1 ms |
344 KB |
n=100 |
7 |
Correct |
0 ms |
348 KB |
n=100 |
8 |
Correct |
0 ms |
344 KB |
n=100 |
9 |
Correct |
0 ms |
348 KB |
n=100 |
10 |
Correct |
0 ms |
348 KB |
n=100 |
11 |
Correct |
0 ms |
360 KB |
n=100 |
12 |
Correct |
0 ms |
348 KB |
n=100 |
13 |
Correct |
0 ms |
348 KB |
n=100 |
14 |
Correct |
0 ms |
348 KB |
n=100 |
15 |
Correct |
1 ms |
348 KB |
n=100 |
16 |
Correct |
1 ms |
344 KB |
n=100 |
17 |
Correct |
0 ms |
348 KB |
n=100 |
18 |
Correct |
0 ms |
348 KB |
n=100 |
19 |
Correct |
0 ms |
348 KB |
n=100 |
20 |
Correct |
0 ms |
348 KB |
n=100 |
21 |
Correct |
0 ms |
348 KB |
n=100 |
22 |
Correct |
0 ms |
348 KB |
n=100 |
23 |
Correct |
0 ms |
348 KB |
n=100 |
24 |
Correct |
0 ms |
348 KB |
n=100 |
25 |
Correct |
1 ms |
348 KB |
n=100 |
26 |
Correct |
0 ms |
348 KB |
n=12 |
27 |
Correct |
0 ms |
348 KB |
n=100 |
28 |
Correct |
1 ms |
604 KB |
n=500 |
29 |
Correct |
1 ms |
604 KB |
n=500 |
30 |
Correct |
1 ms |
604 KB |
n=500 |
31 |
Correct |
1 ms |
604 KB |
n=500 |
32 |
Correct |
1 ms |
604 KB |
n=500 |
33 |
Correct |
1 ms |
604 KB |
n=500 |
34 |
Correct |
1 ms |
600 KB |
n=500 |
35 |
Correct |
1 ms |
604 KB |
n=500 |
36 |
Correct |
1 ms |
604 KB |
n=500 |
37 |
Correct |
1 ms |
464 KB |
n=500 |
38 |
Correct |
1 ms |
604 KB |
n=500 |
39 |
Correct |
1 ms |
604 KB |
n=500 |
40 |
Correct |
1 ms |
604 KB |
n=500 |
41 |
Correct |
1 ms |
604 KB |
n=500 |
42 |
Correct |
1 ms |
600 KB |
n=500 |
43 |
Correct |
1 ms |
856 KB |
n=500 |
44 |
Correct |
1 ms |
604 KB |
n=500 |
45 |
Correct |
1 ms |
604 KB |
n=500 |
46 |
Correct |
1 ms |
604 KB |
n=500 |
47 |
Correct |
1 ms |
604 KB |
n=500 |
48 |
Correct |
1 ms |
604 KB |
n=500 |
49 |
Correct |
1 ms |
604 KB |
n=500 |
50 |
Correct |
1 ms |
604 KB |
n=500 |
51 |
Correct |
1 ms |
600 KB |
n=500 |
52 |
Correct |
1 ms |
604 KB |
n=500 |
53 |
Correct |
1 ms |
600 KB |
n=500 |
54 |
Correct |
1 ms |
600 KB |
n=500 |
55 |
Correct |
1 ms |
600 KB |
n=278 |
56 |
Correct |
1 ms |
604 KB |
n=500 |
57 |
Correct |
1 ms |
600 KB |
n=500 |
58 |
Correct |
1 ms |
464 KB |
n=500 |
59 |
Correct |
3 ms |
1368 KB |
n=2000 |
60 |
Correct |
2 ms |
1372 KB |
n=2000 |
61 |
Correct |
3 ms |
1372 KB |
n=2000 |
62 |
Correct |
3 ms |
1372 KB |
n=2000 |
63 |
Correct |
4 ms |
1372 KB |
n=2000 |
64 |
Correct |
4 ms |
1372 KB |
n=2000 |
65 |
Correct |
3 ms |
1372 KB |
n=2000 |
66 |
Correct |
2 ms |
1368 KB |
n=2000 |
67 |
Correct |
3 ms |
1372 KB |
n=2000 |
68 |
Correct |
3 ms |
1372 KB |
n=2000 |
69 |
Correct |
2 ms |
1372 KB |
n=2000 |
70 |
Correct |
2 ms |
1372 KB |
n=2000 |
71 |
Correct |
2 ms |
1372 KB |
n=2000 |
72 |
Correct |
2 ms |
1372 KB |
n=2000 |
73 |
Correct |
3 ms |
1376 KB |
n=2000 |
74 |
Correct |
3 ms |
1120 KB |
n=1844 |
75 |
Correct |
2 ms |
1396 KB |
n=2000 |
76 |
Correct |
3 ms |
1384 KB |
n=2000 |
77 |
Correct |
3 ms |
1376 KB |
n=2000 |
78 |
Correct |
3 ms |
1372 KB |
n=2000 |
79 |
Correct |
3 ms |
1368 KB |
n=2000 |
80 |
Correct |
2 ms |
1372 KB |
n=2000 |
81 |
Correct |
3 ms |
1372 KB |
n=2000 |
82 |
Correct |
5 ms |
1372 KB |
n=2000 |
83 |
Correct |
2 ms |
1372 KB |
n=2000 |
84 |
Correct |
3 ms |
1372 KB |
n=2000 |
85 |
Correct |
3 ms |
1372 KB |
n=2000 |
86 |
Correct |
3 ms |
1372 KB |
n=2000 |
87 |
Correct |
3 ms |
1372 KB |
n=2000 |
88 |
Correct |
2 ms |
1372 KB |
n=2000 |
89 |
Correct |
2 ms |
1372 KB |
n=2000 |
90 |
Correct |
2 ms |
1372 KB |
n=2000 |
91 |
Correct |
2 ms |
1372 KB |
n=2000 |
92 |
Correct |
658 ms |
97228 KB |
n=200000 |
93 |
Correct |
706 ms |
101944 KB |
n=200000 |
94 |
Correct |
441 ms |
104452 KB |
n=200000 |
95 |
Correct |
648 ms |
97188 KB |
n=200000 |
96 |
Correct |
611 ms |
97188 KB |
n=200000 |
97 |
Correct |
792 ms |
101176 KB |
n=200000 |
98 |
Correct |
657 ms |
97192 KB |
n=200000 |
99 |
Correct |
729 ms |
97592 KB |
n=200000 |
100 |
Correct |
620 ms |
97208 KB |
n=200000 |
101 |
Correct |
361 ms |
105272 KB |
n=200000 |
102 |
Correct |
385 ms |
98608 KB |
n=200000 |
103 |
Correct |
378 ms |
98616 KB |
n=200000 |
104 |
Correct |
373 ms |
98616 KB |
n=200000 |
105 |
Correct |
367 ms |
99124 KB |
n=200000 |
106 |
Correct |
374 ms |
99124 KB |
n=200000 |
107 |
Correct |
372 ms |
98868 KB |
n=200000 |
108 |
Correct |
661 ms |
97420 KB |
n=200000 |
109 |
Correct |
647 ms |
97348 KB |
n=200000 |
110 |
Correct |
682 ms |
97548 KB |
n=200000 |
111 |
Correct |
632 ms |
96500 KB |
n=200000 |
112 |
Correct |
416 ms |
104816 KB |
n=200000 |
113 |
Correct |
805 ms |
101172 KB |
n=200000 |
114 |
Correct |
606 ms |
96676 KB |
n=200000 |
115 |
Correct |
943 ms |
99284 KB |
n=200000 |
116 |
Correct |
642 ms |
97304 KB |
n=200000 |
117 |
Correct |
395 ms |
105012 KB |
n=200000 |
118 |
Correct |
853 ms |
100148 KB |
n=200000 |
119 |
Correct |
611 ms |
97196 KB |
n=200000 |
120 |
Correct |
306 ms |
104244 KB |
n=200000 |
121 |
Correct |
331 ms |
104188 KB |
n=200000 |
122 |
Correct |
317 ms |
104504 KB |
n=200000 |
123 |
Correct |
409 ms |
98868 KB |
n=200000 |
124 |
Correct |
84 ms |
21384 KB |
n=25264 |