#include <bits/stdc++.h>
// #pragma GCC optimize ("Ofast,unroll-loops")
// #pragma GCC target ("avx2")
using namespace std;
typedef long long ll;
typedef pair<int, int> pp;
#define er(args ...) cerr << __LINE__ << ": ", err(new istringstream(string(#args)), args), cerr << endl
#define per(i,r,l) for(int i = (r); i >= (l); i--)
#define rep(i,l,r) for(int i = (l); i < (r); i++)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define pb push_back
#define ss second
#define ff first
void err(istringstream *iss){}template<typename T,typename ...Args> void err(istringstream *iss,const T &_val, const Args&...args){string _name;*iss>>_name;if(_name.back()==',')_name.pop_back();cerr<<_name<<" = "<<_val<<", ",err(iss,args...);}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod = 1e9 + 7, maxn = 2e5 + 5, lg = 22, lng = 26, inf = ll(1e9) + 5;
ll pw(ll a,ll b,ll md=mod){if(!b)return 1;ll k=pw(a,b>>1ll);return k*k%md*(b&1ll?a:1)%md;}
vector<int> adj[maxn];
int par[maxn][lg], h[maxn];
void dfs(int r, int p){
par[r][0] = p;
rep(i,1,lg) par[r][i] = par[par[r][i-1]][i-1];
for(int c: adj[r]) if(c - p) h[c] = h[r]+1, dfs(c, r);
}
int lca(int u, int v){
if(h[u] > h[v]) swap(u, v);
per(i,lg-1,0) if(h[u] <= h[par[v][i]]) v = par[v][i];
if(u == v) return u;
per(i,lg-1,0) if(par[u][i] - par[v][i]) u = par[u][i], v = par[v][i];
return par[u][0];
}
set<int> pos[maxn], bt[maxn];
int main(){
cin.tie(0) -> sync_with_stdio(0);
int n, m, q; cin >> n >> m >> q;
rep(i,1,n){
int u, v; cin >> u >> v; u--, v--;
adj[u].pb(v), adj[v].pb(u);
} dfs(0, 0);
vector<int> a(m);
rep(i,0,m){
cin >> a[i]; a[i]--;
pos[a[i]].insert(i);
if(i) bt[lca(a[i-1], a[i])].insert(i-1);
}
while(q--){
int t; cin >> t;
if(t&1){
int p, v; cin >> p >> v; p--, v--;
pos[a[p]].erase(p);
if(p) bt[lca(a[p], a[p-1])].erase(p-1);
if(p < m-1) bt[lca(a[p], a[p+1])].erase(p);
a[p] = v;
pos[a[p]].insert(p);
if(p) bt[lca(a[p], a[p-1])].insert(p-1);
if(p < m-1) bt[lca(a[p], a[p+1])].insert(p);
}else{
int l, r, x; cin >> l >> r >> x; l--, r--, x--;
auto it = pos[x].lower_bound(l);
if(it != end(pos[x]) && *it <= r) cout << *it + 1 << ' ' << *it + 1 << '\n';
else{
auto it = bt[x].lower_bound(l);
if(it != end(bt[x]) && *it < r) cout << *it + 1 << ' ' << *it + 2 << '\n';
else cout << -1 << ' ' << -1 << '\n';
}
}
}
return 0;
}
/*
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
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
23764 KB |
n=5 |
2 |
Correct |
11 ms |
23820 KB |
n=100 |
3 |
Correct |
11 ms |
23788 KB |
n=100 |
4 |
Correct |
11 ms |
23764 KB |
n=100 |
5 |
Correct |
12 ms |
23780 KB |
n=100 |
6 |
Correct |
13 ms |
23840 KB |
n=100 |
7 |
Correct |
11 ms |
23852 KB |
n=100 |
8 |
Correct |
12 ms |
23820 KB |
n=100 |
9 |
Correct |
11 ms |
23816 KB |
n=100 |
10 |
Correct |
13 ms |
23820 KB |
n=100 |
11 |
Correct |
12 ms |
23824 KB |
n=100 |
12 |
Correct |
12 ms |
23848 KB |
n=100 |
13 |
Correct |
13 ms |
23764 KB |
n=100 |
14 |
Correct |
12 ms |
23764 KB |
n=100 |
15 |
Correct |
13 ms |
23820 KB |
n=100 |
16 |
Correct |
12 ms |
23764 KB |
n=100 |
17 |
Correct |
11 ms |
23820 KB |
n=100 |
18 |
Correct |
11 ms |
23820 KB |
n=100 |
19 |
Correct |
14 ms |
23764 KB |
n=100 |
20 |
Correct |
12 ms |
23764 KB |
n=100 |
21 |
Correct |
12 ms |
23892 KB |
n=100 |
22 |
Correct |
12 ms |
23764 KB |
n=100 |
23 |
Correct |
12 ms |
23816 KB |
n=100 |
24 |
Correct |
12 ms |
23764 KB |
n=100 |
25 |
Correct |
12 ms |
23764 KB |
n=100 |
26 |
Correct |
13 ms |
23824 KB |
n=12 |
27 |
Correct |
12 ms |
23844 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
23764 KB |
n=5 |
2 |
Correct |
11 ms |
23820 KB |
n=100 |
3 |
Correct |
11 ms |
23788 KB |
n=100 |
4 |
Correct |
11 ms |
23764 KB |
n=100 |
5 |
Correct |
12 ms |
23780 KB |
n=100 |
6 |
Correct |
13 ms |
23840 KB |
n=100 |
7 |
Correct |
11 ms |
23852 KB |
n=100 |
8 |
Correct |
12 ms |
23820 KB |
n=100 |
9 |
Correct |
11 ms |
23816 KB |
n=100 |
10 |
Correct |
13 ms |
23820 KB |
n=100 |
11 |
Correct |
12 ms |
23824 KB |
n=100 |
12 |
Correct |
12 ms |
23848 KB |
n=100 |
13 |
Correct |
13 ms |
23764 KB |
n=100 |
14 |
Correct |
12 ms |
23764 KB |
n=100 |
15 |
Correct |
13 ms |
23820 KB |
n=100 |
16 |
Correct |
12 ms |
23764 KB |
n=100 |
17 |
Correct |
11 ms |
23820 KB |
n=100 |
18 |
Correct |
11 ms |
23820 KB |
n=100 |
19 |
Correct |
14 ms |
23764 KB |
n=100 |
20 |
Correct |
12 ms |
23764 KB |
n=100 |
21 |
Correct |
12 ms |
23892 KB |
n=100 |
22 |
Correct |
12 ms |
23764 KB |
n=100 |
23 |
Correct |
12 ms |
23816 KB |
n=100 |
24 |
Correct |
12 ms |
23764 KB |
n=100 |
25 |
Correct |
12 ms |
23764 KB |
n=100 |
26 |
Correct |
13 ms |
23824 KB |
n=12 |
27 |
Correct |
12 ms |
23844 KB |
n=100 |
28 |
Correct |
13 ms |
23824 KB |
n=500 |
29 |
Correct |
14 ms |
23892 KB |
n=500 |
30 |
Correct |
13 ms |
23896 KB |
n=500 |
31 |
Correct |
15 ms |
23892 KB |
n=500 |
32 |
Correct |
14 ms |
23824 KB |
n=500 |
33 |
Correct |
12 ms |
23892 KB |
n=500 |
34 |
Correct |
13 ms |
23904 KB |
n=500 |
35 |
Correct |
13 ms |
23964 KB |
n=500 |
36 |
Correct |
12 ms |
23868 KB |
n=500 |
37 |
Correct |
12 ms |
23860 KB |
n=500 |
38 |
Correct |
12 ms |
23924 KB |
n=500 |
39 |
Correct |
12 ms |
23936 KB |
n=500 |
40 |
Correct |
12 ms |
23892 KB |
n=500 |
41 |
Correct |
13 ms |
23976 KB |
n=500 |
42 |
Correct |
12 ms |
23828 KB |
n=500 |
43 |
Correct |
15 ms |
23928 KB |
n=500 |
44 |
Correct |
13 ms |
23828 KB |
n=500 |
45 |
Correct |
13 ms |
23856 KB |
n=500 |
46 |
Correct |
13 ms |
23892 KB |
n=500 |
47 |
Correct |
12 ms |
23892 KB |
n=500 |
48 |
Correct |
13 ms |
23828 KB |
n=500 |
49 |
Correct |
14 ms |
23960 KB |
n=500 |
50 |
Correct |
12 ms |
23892 KB |
n=500 |
51 |
Correct |
13 ms |
23956 KB |
n=500 |
52 |
Correct |
19 ms |
23896 KB |
n=500 |
53 |
Correct |
13 ms |
23892 KB |
n=500 |
54 |
Correct |
13 ms |
23940 KB |
n=500 |
55 |
Correct |
13 ms |
23824 KB |
n=278 |
56 |
Correct |
12 ms |
23928 KB |
n=500 |
57 |
Correct |
13 ms |
23892 KB |
n=500 |
58 |
Correct |
12 ms |
23844 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
23764 KB |
n=5 |
2 |
Correct |
11 ms |
23820 KB |
n=100 |
3 |
Correct |
11 ms |
23788 KB |
n=100 |
4 |
Correct |
11 ms |
23764 KB |
n=100 |
5 |
Correct |
12 ms |
23780 KB |
n=100 |
6 |
Correct |
13 ms |
23840 KB |
n=100 |
7 |
Correct |
11 ms |
23852 KB |
n=100 |
8 |
Correct |
12 ms |
23820 KB |
n=100 |
9 |
Correct |
11 ms |
23816 KB |
n=100 |
10 |
Correct |
13 ms |
23820 KB |
n=100 |
11 |
Correct |
12 ms |
23824 KB |
n=100 |
12 |
Correct |
12 ms |
23848 KB |
n=100 |
13 |
Correct |
13 ms |
23764 KB |
n=100 |
14 |
Correct |
12 ms |
23764 KB |
n=100 |
15 |
Correct |
13 ms |
23820 KB |
n=100 |
16 |
Correct |
12 ms |
23764 KB |
n=100 |
17 |
Correct |
11 ms |
23820 KB |
n=100 |
18 |
Correct |
11 ms |
23820 KB |
n=100 |
19 |
Correct |
14 ms |
23764 KB |
n=100 |
20 |
Correct |
12 ms |
23764 KB |
n=100 |
21 |
Correct |
12 ms |
23892 KB |
n=100 |
22 |
Correct |
12 ms |
23764 KB |
n=100 |
23 |
Correct |
12 ms |
23816 KB |
n=100 |
24 |
Correct |
12 ms |
23764 KB |
n=100 |
25 |
Correct |
12 ms |
23764 KB |
n=100 |
26 |
Correct |
13 ms |
23824 KB |
n=12 |
27 |
Correct |
12 ms |
23844 KB |
n=100 |
28 |
Correct |
13 ms |
23824 KB |
n=500 |
29 |
Correct |
14 ms |
23892 KB |
n=500 |
30 |
Correct |
13 ms |
23896 KB |
n=500 |
31 |
Correct |
15 ms |
23892 KB |
n=500 |
32 |
Correct |
14 ms |
23824 KB |
n=500 |
33 |
Correct |
12 ms |
23892 KB |
n=500 |
34 |
Correct |
13 ms |
23904 KB |
n=500 |
35 |
Correct |
13 ms |
23964 KB |
n=500 |
36 |
Correct |
12 ms |
23868 KB |
n=500 |
37 |
Correct |
12 ms |
23860 KB |
n=500 |
38 |
Correct |
12 ms |
23924 KB |
n=500 |
39 |
Correct |
12 ms |
23936 KB |
n=500 |
40 |
Correct |
12 ms |
23892 KB |
n=500 |
41 |
Correct |
13 ms |
23976 KB |
n=500 |
42 |
Correct |
12 ms |
23828 KB |
n=500 |
43 |
Correct |
15 ms |
23928 KB |
n=500 |
44 |
Correct |
13 ms |
23828 KB |
n=500 |
45 |
Correct |
13 ms |
23856 KB |
n=500 |
46 |
Correct |
13 ms |
23892 KB |
n=500 |
47 |
Correct |
12 ms |
23892 KB |
n=500 |
48 |
Correct |
13 ms |
23828 KB |
n=500 |
49 |
Correct |
14 ms |
23960 KB |
n=500 |
50 |
Correct |
12 ms |
23892 KB |
n=500 |
51 |
Correct |
13 ms |
23956 KB |
n=500 |
52 |
Correct |
19 ms |
23896 KB |
n=500 |
53 |
Correct |
13 ms |
23892 KB |
n=500 |
54 |
Correct |
13 ms |
23940 KB |
n=500 |
55 |
Correct |
13 ms |
23824 KB |
n=278 |
56 |
Correct |
12 ms |
23928 KB |
n=500 |
57 |
Correct |
13 ms |
23892 KB |
n=500 |
58 |
Correct |
12 ms |
23844 KB |
n=500 |
59 |
Correct |
15 ms |
24292 KB |
n=2000 |
60 |
Correct |
15 ms |
24344 KB |
n=2000 |
61 |
Correct |
15 ms |
24276 KB |
n=2000 |
62 |
Correct |
16 ms |
24356 KB |
n=2000 |
63 |
Correct |
17 ms |
24216 KB |
n=2000 |
64 |
Correct |
17 ms |
24276 KB |
n=2000 |
65 |
Correct |
19 ms |
24296 KB |
n=2000 |
66 |
Correct |
16 ms |
24404 KB |
n=2000 |
67 |
Correct |
16 ms |
24276 KB |
n=2000 |
68 |
Correct |
16 ms |
24276 KB |
n=2000 |
69 |
Correct |
15 ms |
24216 KB |
n=2000 |
70 |
Correct |
15 ms |
24248 KB |
n=2000 |
71 |
Correct |
14 ms |
24248 KB |
n=2000 |
72 |
Correct |
16 ms |
24200 KB |
n=2000 |
73 |
Correct |
15 ms |
24212 KB |
n=2000 |
74 |
Correct |
16 ms |
24276 KB |
n=1844 |
75 |
Correct |
15 ms |
24304 KB |
n=2000 |
76 |
Correct |
16 ms |
24288 KB |
n=2000 |
77 |
Correct |
16 ms |
24316 KB |
n=2000 |
78 |
Correct |
16 ms |
24232 KB |
n=2000 |
79 |
Correct |
15 ms |
24204 KB |
n=2000 |
80 |
Correct |
15 ms |
24376 KB |
n=2000 |
81 |
Correct |
15 ms |
24340 KB |
n=2000 |
82 |
Correct |
16 ms |
24364 KB |
n=2000 |
83 |
Correct |
16 ms |
24340 KB |
n=2000 |
84 |
Correct |
16 ms |
24216 KB |
n=2000 |
85 |
Correct |
16 ms |
24276 KB |
n=2000 |
86 |
Correct |
16 ms |
24276 KB |
n=2000 |
87 |
Correct |
16 ms |
24216 KB |
n=2000 |
88 |
Correct |
15 ms |
24340 KB |
n=2000 |
89 |
Correct |
15 ms |
24360 KB |
n=2000 |
90 |
Correct |
14 ms |
24344 KB |
n=2000 |
91 |
Correct |
17 ms |
24276 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
23764 KB |
n=5 |
2 |
Correct |
11 ms |
23820 KB |
n=100 |
3 |
Correct |
11 ms |
23788 KB |
n=100 |
4 |
Correct |
11 ms |
23764 KB |
n=100 |
5 |
Correct |
12 ms |
23780 KB |
n=100 |
6 |
Correct |
13 ms |
23840 KB |
n=100 |
7 |
Correct |
11 ms |
23852 KB |
n=100 |
8 |
Correct |
12 ms |
23820 KB |
n=100 |
9 |
Correct |
11 ms |
23816 KB |
n=100 |
10 |
Correct |
13 ms |
23820 KB |
n=100 |
11 |
Correct |
12 ms |
23824 KB |
n=100 |
12 |
Correct |
12 ms |
23848 KB |
n=100 |
13 |
Correct |
13 ms |
23764 KB |
n=100 |
14 |
Correct |
12 ms |
23764 KB |
n=100 |
15 |
Correct |
13 ms |
23820 KB |
n=100 |
16 |
Correct |
12 ms |
23764 KB |
n=100 |
17 |
Correct |
11 ms |
23820 KB |
n=100 |
18 |
Correct |
11 ms |
23820 KB |
n=100 |
19 |
Correct |
14 ms |
23764 KB |
n=100 |
20 |
Correct |
12 ms |
23764 KB |
n=100 |
21 |
Correct |
12 ms |
23892 KB |
n=100 |
22 |
Correct |
12 ms |
23764 KB |
n=100 |
23 |
Correct |
12 ms |
23816 KB |
n=100 |
24 |
Correct |
12 ms |
23764 KB |
n=100 |
25 |
Correct |
12 ms |
23764 KB |
n=100 |
26 |
Correct |
13 ms |
23824 KB |
n=12 |
27 |
Correct |
12 ms |
23844 KB |
n=100 |
28 |
Correct |
13 ms |
23824 KB |
n=500 |
29 |
Correct |
14 ms |
23892 KB |
n=500 |
30 |
Correct |
13 ms |
23896 KB |
n=500 |
31 |
Correct |
15 ms |
23892 KB |
n=500 |
32 |
Correct |
14 ms |
23824 KB |
n=500 |
33 |
Correct |
12 ms |
23892 KB |
n=500 |
34 |
Correct |
13 ms |
23904 KB |
n=500 |
35 |
Correct |
13 ms |
23964 KB |
n=500 |
36 |
Correct |
12 ms |
23868 KB |
n=500 |
37 |
Correct |
12 ms |
23860 KB |
n=500 |
38 |
Correct |
12 ms |
23924 KB |
n=500 |
39 |
Correct |
12 ms |
23936 KB |
n=500 |
40 |
Correct |
12 ms |
23892 KB |
n=500 |
41 |
Correct |
13 ms |
23976 KB |
n=500 |
42 |
Correct |
12 ms |
23828 KB |
n=500 |
43 |
Correct |
15 ms |
23928 KB |
n=500 |
44 |
Correct |
13 ms |
23828 KB |
n=500 |
45 |
Correct |
13 ms |
23856 KB |
n=500 |
46 |
Correct |
13 ms |
23892 KB |
n=500 |
47 |
Correct |
12 ms |
23892 KB |
n=500 |
48 |
Correct |
13 ms |
23828 KB |
n=500 |
49 |
Correct |
14 ms |
23960 KB |
n=500 |
50 |
Correct |
12 ms |
23892 KB |
n=500 |
51 |
Correct |
13 ms |
23956 KB |
n=500 |
52 |
Correct |
19 ms |
23896 KB |
n=500 |
53 |
Correct |
13 ms |
23892 KB |
n=500 |
54 |
Correct |
13 ms |
23940 KB |
n=500 |
55 |
Correct |
13 ms |
23824 KB |
n=278 |
56 |
Correct |
12 ms |
23928 KB |
n=500 |
57 |
Correct |
13 ms |
23892 KB |
n=500 |
58 |
Correct |
12 ms |
23844 KB |
n=500 |
59 |
Correct |
15 ms |
24292 KB |
n=2000 |
60 |
Correct |
15 ms |
24344 KB |
n=2000 |
61 |
Correct |
15 ms |
24276 KB |
n=2000 |
62 |
Correct |
16 ms |
24356 KB |
n=2000 |
63 |
Correct |
17 ms |
24216 KB |
n=2000 |
64 |
Correct |
17 ms |
24276 KB |
n=2000 |
65 |
Correct |
19 ms |
24296 KB |
n=2000 |
66 |
Correct |
16 ms |
24404 KB |
n=2000 |
67 |
Correct |
16 ms |
24276 KB |
n=2000 |
68 |
Correct |
16 ms |
24276 KB |
n=2000 |
69 |
Correct |
15 ms |
24216 KB |
n=2000 |
70 |
Correct |
15 ms |
24248 KB |
n=2000 |
71 |
Correct |
14 ms |
24248 KB |
n=2000 |
72 |
Correct |
16 ms |
24200 KB |
n=2000 |
73 |
Correct |
15 ms |
24212 KB |
n=2000 |
74 |
Correct |
16 ms |
24276 KB |
n=1844 |
75 |
Correct |
15 ms |
24304 KB |
n=2000 |
76 |
Correct |
16 ms |
24288 KB |
n=2000 |
77 |
Correct |
16 ms |
24316 KB |
n=2000 |
78 |
Correct |
16 ms |
24232 KB |
n=2000 |
79 |
Correct |
15 ms |
24204 KB |
n=2000 |
80 |
Correct |
15 ms |
24376 KB |
n=2000 |
81 |
Correct |
15 ms |
24340 KB |
n=2000 |
82 |
Correct |
16 ms |
24364 KB |
n=2000 |
83 |
Correct |
16 ms |
24340 KB |
n=2000 |
84 |
Correct |
16 ms |
24216 KB |
n=2000 |
85 |
Correct |
16 ms |
24276 KB |
n=2000 |
86 |
Correct |
16 ms |
24276 KB |
n=2000 |
87 |
Correct |
16 ms |
24216 KB |
n=2000 |
88 |
Correct |
15 ms |
24340 KB |
n=2000 |
89 |
Correct |
15 ms |
24360 KB |
n=2000 |
90 |
Correct |
14 ms |
24344 KB |
n=2000 |
91 |
Correct |
17 ms |
24276 KB |
n=2000 |
92 |
Correct |
710 ms |
76164 KB |
n=200000 |
93 |
Correct |
1105 ms |
82440 KB |
n=200000 |
94 |
Correct |
1012 ms |
86924 KB |
n=200000 |
95 |
Correct |
716 ms |
75880 KB |
n=200000 |
96 |
Correct |
741 ms |
75884 KB |
n=200000 |
97 |
Correct |
1174 ms |
81284 KB |
n=200000 |
98 |
Correct |
841 ms |
75936 KB |
n=200000 |
99 |
Correct |
974 ms |
76096 KB |
n=200000 |
100 |
Correct |
714 ms |
75956 KB |
n=200000 |
101 |
Correct |
1069 ms |
88780 KB |
n=200000 |
102 |
Correct |
443 ms |
77260 KB |
n=200000 |
103 |
Correct |
456 ms |
77032 KB |
n=200000 |
104 |
Correct |
467 ms |
77148 KB |
n=200000 |
105 |
Correct |
445 ms |
77440 KB |
n=200000 |
106 |
Correct |
450 ms |
77492 KB |
n=200000 |
107 |
Correct |
472 ms |
77452 KB |
n=200000 |
108 |
Correct |
856 ms |
75988 KB |
n=200000 |
109 |
Correct |
869 ms |
76004 KB |
n=200000 |
110 |
Correct |
880 ms |
76128 KB |
n=200000 |
111 |
Correct |
708 ms |
75508 KB |
n=200000 |
112 |
Correct |
1073 ms |
87300 KB |
n=200000 |
113 |
Correct |
1140 ms |
81264 KB |
n=200000 |
114 |
Correct |
721 ms |
75584 KB |
n=200000 |
115 |
Correct |
1225 ms |
78556 KB |
n=200000 |
116 |
Correct |
714 ms |
76156 KB |
n=200000 |
117 |
Correct |
1040 ms |
88092 KB |
n=200000 |
118 |
Correct |
1214 ms |
79908 KB |
n=200000 |
119 |
Correct |
709 ms |
76028 KB |
n=200000 |
120 |
Correct |
1008 ms |
87720 KB |
n=200000 |
121 |
Correct |
986 ms |
87720 KB |
n=200000 |
122 |
Correct |
986 ms |
88012 KB |
n=200000 |
123 |
Correct |
470 ms |
77404 KB |
n=200000 |
124 |
Correct |
228 ms |
39248 KB |
n=25264 |