//#pragma GCC optomize ("Ofast")
//#pragma GCC optomize ("unroll-loops")
//#pragma GCC target ("avx,avx2,fma")
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define sz size
#define cl clear
#define ins insert
#define ers erase
#define pii pair < int , int >
#define pll pair< long long , long long >
#define all(x) x.begin() , x.end()
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define tostr(x) to_string(x)
#define tonum(s) atoi(s.c_str())
#define seon(x) setprecision(x)
#define bpop(x) __builtin_popcount(x)
#define deb(x) cerr << #x << " = " << x << endl;
#define int ll
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
const double PI = 3.14159265;
const ll N = 2e5+5;
const ll mod = 1e9+7;
const ll inf = 1e9;
const ll INF = 1e18;
using namespace std;
int n , m , q , a[N];
int dep[N] , up[N][20] ;
vector<int> g[N];
set<int> st1[N];
set<pii> st;
void dfs(int v, int p){
dep[v] = dep[p]+1;
up[v][0] = p;
for(int i = 1; i < 20; i++){
up[v][i] = up[up[v][i-1]][i-1];
}
for(int to : g[v]){
if(to == p) continue;
dfs(to , v);
}
}
int lca(int a , int b){
if(dep[a] > dep[b]) swap(a , b);
for(int i = 19; i >= 0; i--){
if(dep[up[b][i]] >= dep[a]){
b = up[b][i];
}
}
if(b == a) return a;
for(int i = 19; i >= 0; i--){
if(up[b][i] != up[a][i]){
b = up[b][i];
a = up[a][i];
}
}
return up[b][0];
}
void solve(){
cin >> n >> m >> q;
for(int i = 1; i < n; i++){
int a, b;
cin >> a >> b;
g[a].pb(b);
g[b].pb(a);
}
dfs(1 , 0);
for(int i = 1; i <= m; i++) {
cin >> a[i];
if(i) st.ins({lca(a[i] , a[i-1]) , i-1});
st1[a[i]].ins(i);
}
while(q--){
int tp;
cin >> tp;
if(tp == 1){
int pos , v;
cin >> pos >> v;
st1[a[pos]].ers(pos);
if(pos-1 >= 1) st.ers({lca(a[pos] , a[pos-1]) , pos-1});
if(pos+1 <= m) st.ers({lca(a[pos] , a[pos+1]) , pos});
a[pos] = v;
st1[a[pos]].ins(pos);
if(pos-1 >= 1) st.ins({lca(a[pos] , a[pos-1]) , pos-1});
if(pos+1 <= m) st.ins({lca(a[pos] , a[pos+1]) , pos});
} else {
int l , r , v;
cin >> l >> r >> v;
auto it = st1[v].lower_bound(l);
if(it != st1[v].end()){
if(*it <= r){
cout << *it <<" " << *it << "\n";
continue;
}
}
auto it1 = st.lower_bound({v , l});
if(it1 != st.end()){
pii a = *it1;
if(a.F == v && a.S <= r-1){
cout << a.S <<" " << a.S+1 << "\n";
continue;
}
}
cout << -1 << " " << -1 <<"\n";
}
}
}
signed main(){
ios;
solve();
return 0;
}
/*
11
1 2
2 3
2 4
1 5
5 6
6 7
6 8
5 9
9 10
9 11
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
14464 KB |
n=5 |
2 |
Correct |
7 ms |
14420 KB |
n=100 |
3 |
Correct |
8 ms |
14420 KB |
n=100 |
4 |
Correct |
8 ms |
14420 KB |
n=100 |
5 |
Correct |
8 ms |
14420 KB |
n=100 |
6 |
Correct |
7 ms |
14420 KB |
n=100 |
7 |
Correct |
7 ms |
14420 KB |
n=100 |
8 |
Correct |
7 ms |
14420 KB |
n=100 |
9 |
Correct |
8 ms |
14420 KB |
n=100 |
10 |
Correct |
8 ms |
14416 KB |
n=100 |
11 |
Correct |
8 ms |
14420 KB |
n=100 |
12 |
Correct |
8 ms |
14420 KB |
n=100 |
13 |
Correct |
8 ms |
14388 KB |
n=100 |
14 |
Correct |
8 ms |
14420 KB |
n=100 |
15 |
Correct |
8 ms |
14416 KB |
n=100 |
16 |
Correct |
9 ms |
14420 KB |
n=100 |
17 |
Correct |
8 ms |
14420 KB |
n=100 |
18 |
Correct |
9 ms |
14420 KB |
n=100 |
19 |
Correct |
9 ms |
14420 KB |
n=100 |
20 |
Correct |
8 ms |
14416 KB |
n=100 |
21 |
Correct |
8 ms |
14420 KB |
n=100 |
22 |
Correct |
9 ms |
14420 KB |
n=100 |
23 |
Correct |
7 ms |
14420 KB |
n=100 |
24 |
Correct |
9 ms |
14432 KB |
n=100 |
25 |
Correct |
8 ms |
14420 KB |
n=100 |
26 |
Correct |
8 ms |
14420 KB |
n=12 |
27 |
Correct |
8 ms |
14420 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
14464 KB |
n=5 |
2 |
Correct |
7 ms |
14420 KB |
n=100 |
3 |
Correct |
8 ms |
14420 KB |
n=100 |
4 |
Correct |
8 ms |
14420 KB |
n=100 |
5 |
Correct |
8 ms |
14420 KB |
n=100 |
6 |
Correct |
7 ms |
14420 KB |
n=100 |
7 |
Correct |
7 ms |
14420 KB |
n=100 |
8 |
Correct |
7 ms |
14420 KB |
n=100 |
9 |
Correct |
8 ms |
14420 KB |
n=100 |
10 |
Correct |
8 ms |
14416 KB |
n=100 |
11 |
Correct |
8 ms |
14420 KB |
n=100 |
12 |
Correct |
8 ms |
14420 KB |
n=100 |
13 |
Correct |
8 ms |
14388 KB |
n=100 |
14 |
Correct |
8 ms |
14420 KB |
n=100 |
15 |
Correct |
8 ms |
14416 KB |
n=100 |
16 |
Correct |
9 ms |
14420 KB |
n=100 |
17 |
Correct |
8 ms |
14420 KB |
n=100 |
18 |
Correct |
9 ms |
14420 KB |
n=100 |
19 |
Correct |
9 ms |
14420 KB |
n=100 |
20 |
Correct |
8 ms |
14416 KB |
n=100 |
21 |
Correct |
8 ms |
14420 KB |
n=100 |
22 |
Correct |
9 ms |
14420 KB |
n=100 |
23 |
Correct |
7 ms |
14420 KB |
n=100 |
24 |
Correct |
9 ms |
14432 KB |
n=100 |
25 |
Correct |
8 ms |
14420 KB |
n=100 |
26 |
Correct |
8 ms |
14420 KB |
n=12 |
27 |
Correct |
8 ms |
14420 KB |
n=100 |
28 |
Correct |
10 ms |
14596 KB |
n=500 |
29 |
Correct |
8 ms |
14556 KB |
n=500 |
30 |
Correct |
9 ms |
14548 KB |
n=500 |
31 |
Correct |
9 ms |
14548 KB |
n=500 |
32 |
Correct |
9 ms |
14548 KB |
n=500 |
33 |
Correct |
10 ms |
14548 KB |
n=500 |
34 |
Correct |
9 ms |
14548 KB |
n=500 |
35 |
Correct |
9 ms |
14548 KB |
n=500 |
36 |
Correct |
10 ms |
14552 KB |
n=500 |
37 |
Correct |
8 ms |
14536 KB |
n=500 |
38 |
Correct |
10 ms |
14548 KB |
n=500 |
39 |
Correct |
10 ms |
14508 KB |
n=500 |
40 |
Correct |
8 ms |
14548 KB |
n=500 |
41 |
Correct |
8 ms |
14564 KB |
n=500 |
42 |
Correct |
9 ms |
14556 KB |
n=500 |
43 |
Correct |
10 ms |
14548 KB |
n=500 |
44 |
Correct |
9 ms |
14548 KB |
n=500 |
45 |
Correct |
8 ms |
14548 KB |
n=500 |
46 |
Correct |
9 ms |
14544 KB |
n=500 |
47 |
Correct |
9 ms |
14608 KB |
n=500 |
48 |
Correct |
8 ms |
14548 KB |
n=500 |
49 |
Correct |
9 ms |
14564 KB |
n=500 |
50 |
Correct |
8 ms |
14548 KB |
n=500 |
51 |
Correct |
8 ms |
14548 KB |
n=500 |
52 |
Correct |
10 ms |
14556 KB |
n=500 |
53 |
Correct |
9 ms |
14548 KB |
n=500 |
54 |
Correct |
8 ms |
14548 KB |
n=500 |
55 |
Correct |
8 ms |
14436 KB |
n=278 |
56 |
Correct |
8 ms |
14568 KB |
n=500 |
57 |
Correct |
8 ms |
14548 KB |
n=500 |
58 |
Correct |
8 ms |
14548 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
14464 KB |
n=5 |
2 |
Correct |
7 ms |
14420 KB |
n=100 |
3 |
Correct |
8 ms |
14420 KB |
n=100 |
4 |
Correct |
8 ms |
14420 KB |
n=100 |
5 |
Correct |
8 ms |
14420 KB |
n=100 |
6 |
Correct |
7 ms |
14420 KB |
n=100 |
7 |
Correct |
7 ms |
14420 KB |
n=100 |
8 |
Correct |
7 ms |
14420 KB |
n=100 |
9 |
Correct |
8 ms |
14420 KB |
n=100 |
10 |
Correct |
8 ms |
14416 KB |
n=100 |
11 |
Correct |
8 ms |
14420 KB |
n=100 |
12 |
Correct |
8 ms |
14420 KB |
n=100 |
13 |
Correct |
8 ms |
14388 KB |
n=100 |
14 |
Correct |
8 ms |
14420 KB |
n=100 |
15 |
Correct |
8 ms |
14416 KB |
n=100 |
16 |
Correct |
9 ms |
14420 KB |
n=100 |
17 |
Correct |
8 ms |
14420 KB |
n=100 |
18 |
Correct |
9 ms |
14420 KB |
n=100 |
19 |
Correct |
9 ms |
14420 KB |
n=100 |
20 |
Correct |
8 ms |
14416 KB |
n=100 |
21 |
Correct |
8 ms |
14420 KB |
n=100 |
22 |
Correct |
9 ms |
14420 KB |
n=100 |
23 |
Correct |
7 ms |
14420 KB |
n=100 |
24 |
Correct |
9 ms |
14432 KB |
n=100 |
25 |
Correct |
8 ms |
14420 KB |
n=100 |
26 |
Correct |
8 ms |
14420 KB |
n=12 |
27 |
Correct |
8 ms |
14420 KB |
n=100 |
28 |
Correct |
10 ms |
14596 KB |
n=500 |
29 |
Correct |
8 ms |
14556 KB |
n=500 |
30 |
Correct |
9 ms |
14548 KB |
n=500 |
31 |
Correct |
9 ms |
14548 KB |
n=500 |
32 |
Correct |
9 ms |
14548 KB |
n=500 |
33 |
Correct |
10 ms |
14548 KB |
n=500 |
34 |
Correct |
9 ms |
14548 KB |
n=500 |
35 |
Correct |
9 ms |
14548 KB |
n=500 |
36 |
Correct |
10 ms |
14552 KB |
n=500 |
37 |
Correct |
8 ms |
14536 KB |
n=500 |
38 |
Correct |
10 ms |
14548 KB |
n=500 |
39 |
Correct |
10 ms |
14508 KB |
n=500 |
40 |
Correct |
8 ms |
14548 KB |
n=500 |
41 |
Correct |
8 ms |
14564 KB |
n=500 |
42 |
Correct |
9 ms |
14556 KB |
n=500 |
43 |
Correct |
10 ms |
14548 KB |
n=500 |
44 |
Correct |
9 ms |
14548 KB |
n=500 |
45 |
Correct |
8 ms |
14548 KB |
n=500 |
46 |
Correct |
9 ms |
14544 KB |
n=500 |
47 |
Correct |
9 ms |
14608 KB |
n=500 |
48 |
Correct |
8 ms |
14548 KB |
n=500 |
49 |
Correct |
9 ms |
14564 KB |
n=500 |
50 |
Correct |
8 ms |
14548 KB |
n=500 |
51 |
Correct |
8 ms |
14548 KB |
n=500 |
52 |
Correct |
10 ms |
14556 KB |
n=500 |
53 |
Correct |
9 ms |
14548 KB |
n=500 |
54 |
Correct |
8 ms |
14548 KB |
n=500 |
55 |
Correct |
8 ms |
14436 KB |
n=278 |
56 |
Correct |
8 ms |
14568 KB |
n=500 |
57 |
Correct |
8 ms |
14548 KB |
n=500 |
58 |
Correct |
8 ms |
14548 KB |
n=500 |
59 |
Correct |
12 ms |
15104 KB |
n=2000 |
60 |
Correct |
11 ms |
15188 KB |
n=2000 |
61 |
Correct |
11 ms |
15068 KB |
n=2000 |
62 |
Correct |
12 ms |
15060 KB |
n=2000 |
63 |
Correct |
11 ms |
15068 KB |
n=2000 |
64 |
Correct |
11 ms |
15072 KB |
n=2000 |
65 |
Correct |
14 ms |
15060 KB |
n=2000 |
66 |
Correct |
11 ms |
15076 KB |
n=2000 |
67 |
Correct |
12 ms |
15028 KB |
n=2000 |
68 |
Correct |
12 ms |
15076 KB |
n=2000 |
69 |
Correct |
10 ms |
15060 KB |
n=2000 |
70 |
Correct |
10 ms |
15068 KB |
n=2000 |
71 |
Correct |
10 ms |
15060 KB |
n=2000 |
72 |
Correct |
13 ms |
15036 KB |
n=2000 |
73 |
Correct |
10 ms |
15060 KB |
n=2000 |
74 |
Correct |
11 ms |
15024 KB |
n=1844 |
75 |
Correct |
10 ms |
15140 KB |
n=2000 |
76 |
Correct |
13 ms |
15052 KB |
n=2000 |
77 |
Correct |
11 ms |
15060 KB |
n=2000 |
78 |
Correct |
12 ms |
15060 KB |
n=2000 |
79 |
Correct |
12 ms |
15188 KB |
n=2000 |
80 |
Correct |
11 ms |
15204 KB |
n=2000 |
81 |
Correct |
12 ms |
15060 KB |
n=2000 |
82 |
Correct |
11 ms |
15060 KB |
n=2000 |
83 |
Correct |
12 ms |
15068 KB |
n=2000 |
84 |
Correct |
12 ms |
15060 KB |
n=2000 |
85 |
Correct |
12 ms |
15152 KB |
n=2000 |
86 |
Correct |
11 ms |
15060 KB |
n=2000 |
87 |
Correct |
11 ms |
15072 KB |
n=2000 |
88 |
Correct |
11 ms |
15152 KB |
n=2000 |
89 |
Correct |
11 ms |
15164 KB |
n=2000 |
90 |
Correct |
11 ms |
15188 KB |
n=2000 |
91 |
Correct |
10 ms |
15060 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
14464 KB |
n=5 |
2 |
Correct |
7 ms |
14420 KB |
n=100 |
3 |
Correct |
8 ms |
14420 KB |
n=100 |
4 |
Correct |
8 ms |
14420 KB |
n=100 |
5 |
Correct |
8 ms |
14420 KB |
n=100 |
6 |
Correct |
7 ms |
14420 KB |
n=100 |
7 |
Correct |
7 ms |
14420 KB |
n=100 |
8 |
Correct |
7 ms |
14420 KB |
n=100 |
9 |
Correct |
8 ms |
14420 KB |
n=100 |
10 |
Correct |
8 ms |
14416 KB |
n=100 |
11 |
Correct |
8 ms |
14420 KB |
n=100 |
12 |
Correct |
8 ms |
14420 KB |
n=100 |
13 |
Correct |
8 ms |
14388 KB |
n=100 |
14 |
Correct |
8 ms |
14420 KB |
n=100 |
15 |
Correct |
8 ms |
14416 KB |
n=100 |
16 |
Correct |
9 ms |
14420 KB |
n=100 |
17 |
Correct |
8 ms |
14420 KB |
n=100 |
18 |
Correct |
9 ms |
14420 KB |
n=100 |
19 |
Correct |
9 ms |
14420 KB |
n=100 |
20 |
Correct |
8 ms |
14416 KB |
n=100 |
21 |
Correct |
8 ms |
14420 KB |
n=100 |
22 |
Correct |
9 ms |
14420 KB |
n=100 |
23 |
Correct |
7 ms |
14420 KB |
n=100 |
24 |
Correct |
9 ms |
14432 KB |
n=100 |
25 |
Correct |
8 ms |
14420 KB |
n=100 |
26 |
Correct |
8 ms |
14420 KB |
n=12 |
27 |
Correct |
8 ms |
14420 KB |
n=100 |
28 |
Correct |
10 ms |
14596 KB |
n=500 |
29 |
Correct |
8 ms |
14556 KB |
n=500 |
30 |
Correct |
9 ms |
14548 KB |
n=500 |
31 |
Correct |
9 ms |
14548 KB |
n=500 |
32 |
Correct |
9 ms |
14548 KB |
n=500 |
33 |
Correct |
10 ms |
14548 KB |
n=500 |
34 |
Correct |
9 ms |
14548 KB |
n=500 |
35 |
Correct |
9 ms |
14548 KB |
n=500 |
36 |
Correct |
10 ms |
14552 KB |
n=500 |
37 |
Correct |
8 ms |
14536 KB |
n=500 |
38 |
Correct |
10 ms |
14548 KB |
n=500 |
39 |
Correct |
10 ms |
14508 KB |
n=500 |
40 |
Correct |
8 ms |
14548 KB |
n=500 |
41 |
Correct |
8 ms |
14564 KB |
n=500 |
42 |
Correct |
9 ms |
14556 KB |
n=500 |
43 |
Correct |
10 ms |
14548 KB |
n=500 |
44 |
Correct |
9 ms |
14548 KB |
n=500 |
45 |
Correct |
8 ms |
14548 KB |
n=500 |
46 |
Correct |
9 ms |
14544 KB |
n=500 |
47 |
Correct |
9 ms |
14608 KB |
n=500 |
48 |
Correct |
8 ms |
14548 KB |
n=500 |
49 |
Correct |
9 ms |
14564 KB |
n=500 |
50 |
Correct |
8 ms |
14548 KB |
n=500 |
51 |
Correct |
8 ms |
14548 KB |
n=500 |
52 |
Correct |
10 ms |
14556 KB |
n=500 |
53 |
Correct |
9 ms |
14548 KB |
n=500 |
54 |
Correct |
8 ms |
14548 KB |
n=500 |
55 |
Correct |
8 ms |
14436 KB |
n=278 |
56 |
Correct |
8 ms |
14568 KB |
n=500 |
57 |
Correct |
8 ms |
14548 KB |
n=500 |
58 |
Correct |
8 ms |
14548 KB |
n=500 |
59 |
Correct |
12 ms |
15104 KB |
n=2000 |
60 |
Correct |
11 ms |
15188 KB |
n=2000 |
61 |
Correct |
11 ms |
15068 KB |
n=2000 |
62 |
Correct |
12 ms |
15060 KB |
n=2000 |
63 |
Correct |
11 ms |
15068 KB |
n=2000 |
64 |
Correct |
11 ms |
15072 KB |
n=2000 |
65 |
Correct |
14 ms |
15060 KB |
n=2000 |
66 |
Correct |
11 ms |
15076 KB |
n=2000 |
67 |
Correct |
12 ms |
15028 KB |
n=2000 |
68 |
Correct |
12 ms |
15076 KB |
n=2000 |
69 |
Correct |
10 ms |
15060 KB |
n=2000 |
70 |
Correct |
10 ms |
15068 KB |
n=2000 |
71 |
Correct |
10 ms |
15060 KB |
n=2000 |
72 |
Correct |
13 ms |
15036 KB |
n=2000 |
73 |
Correct |
10 ms |
15060 KB |
n=2000 |
74 |
Correct |
11 ms |
15024 KB |
n=1844 |
75 |
Correct |
10 ms |
15140 KB |
n=2000 |
76 |
Correct |
13 ms |
15052 KB |
n=2000 |
77 |
Correct |
11 ms |
15060 KB |
n=2000 |
78 |
Correct |
12 ms |
15060 KB |
n=2000 |
79 |
Correct |
12 ms |
15188 KB |
n=2000 |
80 |
Correct |
11 ms |
15204 KB |
n=2000 |
81 |
Correct |
12 ms |
15060 KB |
n=2000 |
82 |
Correct |
11 ms |
15060 KB |
n=2000 |
83 |
Correct |
12 ms |
15068 KB |
n=2000 |
84 |
Correct |
12 ms |
15060 KB |
n=2000 |
85 |
Correct |
12 ms |
15152 KB |
n=2000 |
86 |
Correct |
11 ms |
15060 KB |
n=2000 |
87 |
Correct |
11 ms |
15072 KB |
n=2000 |
88 |
Correct |
11 ms |
15152 KB |
n=2000 |
89 |
Correct |
11 ms |
15164 KB |
n=2000 |
90 |
Correct |
11 ms |
15188 KB |
n=2000 |
91 |
Correct |
10 ms |
15060 KB |
n=2000 |
92 |
Correct |
763 ms |
86352 KB |
n=200000 |
93 |
Correct |
1582 ms |
91260 KB |
n=200000 |
94 |
Correct |
1455 ms |
94140 KB |
n=200000 |
95 |
Correct |
788 ms |
86052 KB |
n=200000 |
96 |
Correct |
709 ms |
86268 KB |
n=200000 |
97 |
Correct |
1570 ms |
90380 KB |
n=200000 |
98 |
Correct |
752 ms |
86096 KB |
n=200000 |
99 |
Correct |
1006 ms |
86516 KB |
n=200000 |
100 |
Correct |
737 ms |
86100 KB |
n=200000 |
101 |
Correct |
1456 ms |
95056 KB |
n=200000 |
102 |
Correct |
468 ms |
87452 KB |
n=200000 |
103 |
Correct |
485 ms |
87620 KB |
n=200000 |
104 |
Correct |
487 ms |
87504 KB |
n=200000 |
105 |
Correct |
489 ms |
87856 KB |
n=200000 |
106 |
Correct |
478 ms |
87896 KB |
n=200000 |
107 |
Correct |
482 ms |
87928 KB |
n=200000 |
108 |
Correct |
1028 ms |
86408 KB |
n=200000 |
109 |
Correct |
929 ms |
86316 KB |
n=200000 |
110 |
Correct |
905 ms |
86380 KB |
n=200000 |
111 |
Correct |
746 ms |
85696 KB |
n=200000 |
112 |
Correct |
1535 ms |
94216 KB |
n=200000 |
113 |
Correct |
1619 ms |
90380 KB |
n=200000 |
114 |
Correct |
765 ms |
85632 KB |
n=200000 |
115 |
Correct |
1646 ms |
88356 KB |
n=200000 |
116 |
Correct |
726 ms |
86284 KB |
n=200000 |
117 |
Correct |
1490 ms |
94472 KB |
n=200000 |
118 |
Correct |
1629 ms |
89176 KB |
n=200000 |
119 |
Correct |
695 ms |
86196 KB |
n=200000 |
120 |
Correct |
1398 ms |
93996 KB |
n=200000 |
121 |
Correct |
1391 ms |
94048 KB |
n=200000 |
122 |
Correct |
1596 ms |
94256 KB |
n=200000 |
123 |
Correct |
548 ms |
87660 KB |
n=200000 |
124 |
Correct |
306 ms |
33124 KB |
n=25264 |