#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 |
18 ms |
23768 KB |
n=5 |
2 |
Correct |
13 ms |
23764 KB |
n=100 |
3 |
Correct |
16 ms |
23764 KB |
n=100 |
4 |
Correct |
15 ms |
23748 KB |
n=100 |
5 |
Correct |
22 ms |
23796 KB |
n=100 |
6 |
Correct |
13 ms |
23764 KB |
n=100 |
7 |
Correct |
14 ms |
23764 KB |
n=100 |
8 |
Correct |
13 ms |
23824 KB |
n=100 |
9 |
Correct |
15 ms |
23840 KB |
n=100 |
10 |
Correct |
13 ms |
23764 KB |
n=100 |
11 |
Correct |
14 ms |
23764 KB |
n=100 |
12 |
Correct |
17 ms |
23840 KB |
n=100 |
13 |
Correct |
13 ms |
23764 KB |
n=100 |
14 |
Correct |
17 ms |
23732 KB |
n=100 |
15 |
Correct |
13 ms |
23764 KB |
n=100 |
16 |
Correct |
13 ms |
23816 KB |
n=100 |
17 |
Correct |
13 ms |
23828 KB |
n=100 |
18 |
Correct |
14 ms |
23804 KB |
n=100 |
19 |
Correct |
13 ms |
23764 KB |
n=100 |
20 |
Correct |
26 ms |
23848 KB |
n=100 |
21 |
Correct |
13 ms |
23824 KB |
n=100 |
22 |
Correct |
15 ms |
23728 KB |
n=100 |
23 |
Correct |
13 ms |
23764 KB |
n=100 |
24 |
Correct |
13 ms |
23764 KB |
n=100 |
25 |
Correct |
23 ms |
23728 KB |
n=100 |
26 |
Correct |
25 ms |
23716 KB |
n=12 |
27 |
Correct |
14 ms |
23780 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
23768 KB |
n=5 |
2 |
Correct |
13 ms |
23764 KB |
n=100 |
3 |
Correct |
16 ms |
23764 KB |
n=100 |
4 |
Correct |
15 ms |
23748 KB |
n=100 |
5 |
Correct |
22 ms |
23796 KB |
n=100 |
6 |
Correct |
13 ms |
23764 KB |
n=100 |
7 |
Correct |
14 ms |
23764 KB |
n=100 |
8 |
Correct |
13 ms |
23824 KB |
n=100 |
9 |
Correct |
15 ms |
23840 KB |
n=100 |
10 |
Correct |
13 ms |
23764 KB |
n=100 |
11 |
Correct |
14 ms |
23764 KB |
n=100 |
12 |
Correct |
17 ms |
23840 KB |
n=100 |
13 |
Correct |
13 ms |
23764 KB |
n=100 |
14 |
Correct |
17 ms |
23732 KB |
n=100 |
15 |
Correct |
13 ms |
23764 KB |
n=100 |
16 |
Correct |
13 ms |
23816 KB |
n=100 |
17 |
Correct |
13 ms |
23828 KB |
n=100 |
18 |
Correct |
14 ms |
23804 KB |
n=100 |
19 |
Correct |
13 ms |
23764 KB |
n=100 |
20 |
Correct |
26 ms |
23848 KB |
n=100 |
21 |
Correct |
13 ms |
23824 KB |
n=100 |
22 |
Correct |
15 ms |
23728 KB |
n=100 |
23 |
Correct |
13 ms |
23764 KB |
n=100 |
24 |
Correct |
13 ms |
23764 KB |
n=100 |
25 |
Correct |
23 ms |
23728 KB |
n=100 |
26 |
Correct |
25 ms |
23716 KB |
n=12 |
27 |
Correct |
14 ms |
23780 KB |
n=100 |
28 |
Correct |
17 ms |
23944 KB |
n=500 |
29 |
Correct |
17 ms |
23920 KB |
n=500 |
30 |
Correct |
14 ms |
23888 KB |
n=500 |
31 |
Correct |
14 ms |
23892 KB |
n=500 |
32 |
Correct |
15 ms |
23952 KB |
n=500 |
33 |
Correct |
14 ms |
23892 KB |
n=500 |
34 |
Correct |
14 ms |
23892 KB |
n=500 |
35 |
Correct |
14 ms |
23888 KB |
n=500 |
36 |
Correct |
14 ms |
23836 KB |
n=500 |
37 |
Correct |
15 ms |
23892 KB |
n=500 |
38 |
Correct |
15 ms |
23840 KB |
n=500 |
39 |
Correct |
14 ms |
23844 KB |
n=500 |
40 |
Correct |
14 ms |
23892 KB |
n=500 |
41 |
Correct |
14 ms |
23892 KB |
n=500 |
42 |
Correct |
16 ms |
23892 KB |
n=500 |
43 |
Correct |
20 ms |
23832 KB |
n=500 |
44 |
Correct |
14 ms |
23892 KB |
n=500 |
45 |
Correct |
15 ms |
23892 KB |
n=500 |
46 |
Correct |
14 ms |
23892 KB |
n=500 |
47 |
Correct |
14 ms |
23892 KB |
n=500 |
48 |
Correct |
15 ms |
23828 KB |
n=500 |
49 |
Correct |
14 ms |
23920 KB |
n=500 |
50 |
Correct |
14 ms |
23892 KB |
n=500 |
51 |
Correct |
16 ms |
23892 KB |
n=500 |
52 |
Correct |
14 ms |
23892 KB |
n=500 |
53 |
Correct |
15 ms |
23892 KB |
n=500 |
54 |
Correct |
22 ms |
23924 KB |
n=500 |
55 |
Correct |
24 ms |
23892 KB |
n=278 |
56 |
Correct |
14 ms |
23892 KB |
n=500 |
57 |
Correct |
14 ms |
23960 KB |
n=500 |
58 |
Correct |
14 ms |
23924 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
23768 KB |
n=5 |
2 |
Correct |
13 ms |
23764 KB |
n=100 |
3 |
Correct |
16 ms |
23764 KB |
n=100 |
4 |
Correct |
15 ms |
23748 KB |
n=100 |
5 |
Correct |
22 ms |
23796 KB |
n=100 |
6 |
Correct |
13 ms |
23764 KB |
n=100 |
7 |
Correct |
14 ms |
23764 KB |
n=100 |
8 |
Correct |
13 ms |
23824 KB |
n=100 |
9 |
Correct |
15 ms |
23840 KB |
n=100 |
10 |
Correct |
13 ms |
23764 KB |
n=100 |
11 |
Correct |
14 ms |
23764 KB |
n=100 |
12 |
Correct |
17 ms |
23840 KB |
n=100 |
13 |
Correct |
13 ms |
23764 KB |
n=100 |
14 |
Correct |
17 ms |
23732 KB |
n=100 |
15 |
Correct |
13 ms |
23764 KB |
n=100 |
16 |
Correct |
13 ms |
23816 KB |
n=100 |
17 |
Correct |
13 ms |
23828 KB |
n=100 |
18 |
Correct |
14 ms |
23804 KB |
n=100 |
19 |
Correct |
13 ms |
23764 KB |
n=100 |
20 |
Correct |
26 ms |
23848 KB |
n=100 |
21 |
Correct |
13 ms |
23824 KB |
n=100 |
22 |
Correct |
15 ms |
23728 KB |
n=100 |
23 |
Correct |
13 ms |
23764 KB |
n=100 |
24 |
Correct |
13 ms |
23764 KB |
n=100 |
25 |
Correct |
23 ms |
23728 KB |
n=100 |
26 |
Correct |
25 ms |
23716 KB |
n=12 |
27 |
Correct |
14 ms |
23780 KB |
n=100 |
28 |
Correct |
17 ms |
23944 KB |
n=500 |
29 |
Correct |
17 ms |
23920 KB |
n=500 |
30 |
Correct |
14 ms |
23888 KB |
n=500 |
31 |
Correct |
14 ms |
23892 KB |
n=500 |
32 |
Correct |
15 ms |
23952 KB |
n=500 |
33 |
Correct |
14 ms |
23892 KB |
n=500 |
34 |
Correct |
14 ms |
23892 KB |
n=500 |
35 |
Correct |
14 ms |
23888 KB |
n=500 |
36 |
Correct |
14 ms |
23836 KB |
n=500 |
37 |
Correct |
15 ms |
23892 KB |
n=500 |
38 |
Correct |
15 ms |
23840 KB |
n=500 |
39 |
Correct |
14 ms |
23844 KB |
n=500 |
40 |
Correct |
14 ms |
23892 KB |
n=500 |
41 |
Correct |
14 ms |
23892 KB |
n=500 |
42 |
Correct |
16 ms |
23892 KB |
n=500 |
43 |
Correct |
20 ms |
23832 KB |
n=500 |
44 |
Correct |
14 ms |
23892 KB |
n=500 |
45 |
Correct |
15 ms |
23892 KB |
n=500 |
46 |
Correct |
14 ms |
23892 KB |
n=500 |
47 |
Correct |
14 ms |
23892 KB |
n=500 |
48 |
Correct |
15 ms |
23828 KB |
n=500 |
49 |
Correct |
14 ms |
23920 KB |
n=500 |
50 |
Correct |
14 ms |
23892 KB |
n=500 |
51 |
Correct |
16 ms |
23892 KB |
n=500 |
52 |
Correct |
14 ms |
23892 KB |
n=500 |
53 |
Correct |
15 ms |
23892 KB |
n=500 |
54 |
Correct |
22 ms |
23924 KB |
n=500 |
55 |
Correct |
24 ms |
23892 KB |
n=278 |
56 |
Correct |
14 ms |
23892 KB |
n=500 |
57 |
Correct |
14 ms |
23960 KB |
n=500 |
58 |
Correct |
14 ms |
23924 KB |
n=500 |
59 |
Correct |
17 ms |
24276 KB |
n=2000 |
60 |
Correct |
16 ms |
24440 KB |
n=2000 |
61 |
Correct |
17 ms |
24276 KB |
n=2000 |
62 |
Correct |
17 ms |
24276 KB |
n=2000 |
63 |
Correct |
18 ms |
24204 KB |
n=2000 |
64 |
Correct |
19 ms |
24344 KB |
n=2000 |
65 |
Correct |
24 ms |
24268 KB |
n=2000 |
66 |
Correct |
25 ms |
24404 KB |
n=2000 |
67 |
Correct |
18 ms |
24220 KB |
n=2000 |
68 |
Correct |
17 ms |
24276 KB |
n=2000 |
69 |
Correct |
16 ms |
24332 KB |
n=2000 |
70 |
Correct |
19 ms |
24276 KB |
n=2000 |
71 |
Correct |
15 ms |
24336 KB |
n=2000 |
72 |
Correct |
15 ms |
24308 KB |
n=2000 |
73 |
Correct |
16 ms |
24276 KB |
n=2000 |
74 |
Correct |
16 ms |
24284 KB |
n=1844 |
75 |
Correct |
15 ms |
24276 KB |
n=2000 |
76 |
Correct |
18 ms |
24224 KB |
n=2000 |
77 |
Correct |
22 ms |
24276 KB |
n=2000 |
78 |
Correct |
18 ms |
24316 KB |
n=2000 |
79 |
Correct |
17 ms |
24276 KB |
n=2000 |
80 |
Correct |
18 ms |
24360 KB |
n=2000 |
81 |
Correct |
17 ms |
24276 KB |
n=2000 |
82 |
Correct |
17 ms |
24276 KB |
n=2000 |
83 |
Correct |
15 ms |
24404 KB |
n=2000 |
84 |
Correct |
17 ms |
24224 KB |
n=2000 |
85 |
Correct |
19 ms |
24368 KB |
n=2000 |
86 |
Correct |
18 ms |
24276 KB |
n=2000 |
87 |
Correct |
17 ms |
24236 KB |
n=2000 |
88 |
Correct |
17 ms |
24440 KB |
n=2000 |
89 |
Correct |
16 ms |
24424 KB |
n=2000 |
90 |
Correct |
31 ms |
24408 KB |
n=2000 |
91 |
Correct |
16 ms |
24276 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
23768 KB |
n=5 |
2 |
Correct |
13 ms |
23764 KB |
n=100 |
3 |
Correct |
16 ms |
23764 KB |
n=100 |
4 |
Correct |
15 ms |
23748 KB |
n=100 |
5 |
Correct |
22 ms |
23796 KB |
n=100 |
6 |
Correct |
13 ms |
23764 KB |
n=100 |
7 |
Correct |
14 ms |
23764 KB |
n=100 |
8 |
Correct |
13 ms |
23824 KB |
n=100 |
9 |
Correct |
15 ms |
23840 KB |
n=100 |
10 |
Correct |
13 ms |
23764 KB |
n=100 |
11 |
Correct |
14 ms |
23764 KB |
n=100 |
12 |
Correct |
17 ms |
23840 KB |
n=100 |
13 |
Correct |
13 ms |
23764 KB |
n=100 |
14 |
Correct |
17 ms |
23732 KB |
n=100 |
15 |
Correct |
13 ms |
23764 KB |
n=100 |
16 |
Correct |
13 ms |
23816 KB |
n=100 |
17 |
Correct |
13 ms |
23828 KB |
n=100 |
18 |
Correct |
14 ms |
23804 KB |
n=100 |
19 |
Correct |
13 ms |
23764 KB |
n=100 |
20 |
Correct |
26 ms |
23848 KB |
n=100 |
21 |
Correct |
13 ms |
23824 KB |
n=100 |
22 |
Correct |
15 ms |
23728 KB |
n=100 |
23 |
Correct |
13 ms |
23764 KB |
n=100 |
24 |
Correct |
13 ms |
23764 KB |
n=100 |
25 |
Correct |
23 ms |
23728 KB |
n=100 |
26 |
Correct |
25 ms |
23716 KB |
n=12 |
27 |
Correct |
14 ms |
23780 KB |
n=100 |
28 |
Correct |
17 ms |
23944 KB |
n=500 |
29 |
Correct |
17 ms |
23920 KB |
n=500 |
30 |
Correct |
14 ms |
23888 KB |
n=500 |
31 |
Correct |
14 ms |
23892 KB |
n=500 |
32 |
Correct |
15 ms |
23952 KB |
n=500 |
33 |
Correct |
14 ms |
23892 KB |
n=500 |
34 |
Correct |
14 ms |
23892 KB |
n=500 |
35 |
Correct |
14 ms |
23888 KB |
n=500 |
36 |
Correct |
14 ms |
23836 KB |
n=500 |
37 |
Correct |
15 ms |
23892 KB |
n=500 |
38 |
Correct |
15 ms |
23840 KB |
n=500 |
39 |
Correct |
14 ms |
23844 KB |
n=500 |
40 |
Correct |
14 ms |
23892 KB |
n=500 |
41 |
Correct |
14 ms |
23892 KB |
n=500 |
42 |
Correct |
16 ms |
23892 KB |
n=500 |
43 |
Correct |
20 ms |
23832 KB |
n=500 |
44 |
Correct |
14 ms |
23892 KB |
n=500 |
45 |
Correct |
15 ms |
23892 KB |
n=500 |
46 |
Correct |
14 ms |
23892 KB |
n=500 |
47 |
Correct |
14 ms |
23892 KB |
n=500 |
48 |
Correct |
15 ms |
23828 KB |
n=500 |
49 |
Correct |
14 ms |
23920 KB |
n=500 |
50 |
Correct |
14 ms |
23892 KB |
n=500 |
51 |
Correct |
16 ms |
23892 KB |
n=500 |
52 |
Correct |
14 ms |
23892 KB |
n=500 |
53 |
Correct |
15 ms |
23892 KB |
n=500 |
54 |
Correct |
22 ms |
23924 KB |
n=500 |
55 |
Correct |
24 ms |
23892 KB |
n=278 |
56 |
Correct |
14 ms |
23892 KB |
n=500 |
57 |
Correct |
14 ms |
23960 KB |
n=500 |
58 |
Correct |
14 ms |
23924 KB |
n=500 |
59 |
Correct |
17 ms |
24276 KB |
n=2000 |
60 |
Correct |
16 ms |
24440 KB |
n=2000 |
61 |
Correct |
17 ms |
24276 KB |
n=2000 |
62 |
Correct |
17 ms |
24276 KB |
n=2000 |
63 |
Correct |
18 ms |
24204 KB |
n=2000 |
64 |
Correct |
19 ms |
24344 KB |
n=2000 |
65 |
Correct |
24 ms |
24268 KB |
n=2000 |
66 |
Correct |
25 ms |
24404 KB |
n=2000 |
67 |
Correct |
18 ms |
24220 KB |
n=2000 |
68 |
Correct |
17 ms |
24276 KB |
n=2000 |
69 |
Correct |
16 ms |
24332 KB |
n=2000 |
70 |
Correct |
19 ms |
24276 KB |
n=2000 |
71 |
Correct |
15 ms |
24336 KB |
n=2000 |
72 |
Correct |
15 ms |
24308 KB |
n=2000 |
73 |
Correct |
16 ms |
24276 KB |
n=2000 |
74 |
Correct |
16 ms |
24284 KB |
n=1844 |
75 |
Correct |
15 ms |
24276 KB |
n=2000 |
76 |
Correct |
18 ms |
24224 KB |
n=2000 |
77 |
Correct |
22 ms |
24276 KB |
n=2000 |
78 |
Correct |
18 ms |
24316 KB |
n=2000 |
79 |
Correct |
17 ms |
24276 KB |
n=2000 |
80 |
Correct |
18 ms |
24360 KB |
n=2000 |
81 |
Correct |
17 ms |
24276 KB |
n=2000 |
82 |
Correct |
17 ms |
24276 KB |
n=2000 |
83 |
Correct |
15 ms |
24404 KB |
n=2000 |
84 |
Correct |
17 ms |
24224 KB |
n=2000 |
85 |
Correct |
19 ms |
24368 KB |
n=2000 |
86 |
Correct |
18 ms |
24276 KB |
n=2000 |
87 |
Correct |
17 ms |
24236 KB |
n=2000 |
88 |
Correct |
17 ms |
24440 KB |
n=2000 |
89 |
Correct |
16 ms |
24424 KB |
n=2000 |
90 |
Correct |
31 ms |
24408 KB |
n=2000 |
91 |
Correct |
16 ms |
24276 KB |
n=2000 |
92 |
Correct |
822 ms |
70492 KB |
n=200000 |
93 |
Correct |
1214 ms |
75812 KB |
n=200000 |
94 |
Correct |
1188 ms |
79708 KB |
n=200000 |
95 |
Correct |
748 ms |
69428 KB |
n=200000 |
96 |
Correct |
740 ms |
69468 KB |
n=200000 |
97 |
Correct |
1243 ms |
73692 KB |
n=200000 |
98 |
Correct |
787 ms |
69524 KB |
n=200000 |
99 |
Correct |
965 ms |
68928 KB |
n=200000 |
100 |
Correct |
774 ms |
69492 KB |
n=200000 |
101 |
Correct |
1064 ms |
80916 KB |
n=200000 |
102 |
Correct |
446 ms |
70476 KB |
n=200000 |
103 |
Correct |
466 ms |
70472 KB |
n=200000 |
104 |
Correct |
467 ms |
70452 KB |
n=200000 |
105 |
Correct |
533 ms |
70168 KB |
n=200000 |
106 |
Correct |
484 ms |
70160 KB |
n=200000 |
107 |
Correct |
484 ms |
70184 KB |
n=200000 |
108 |
Correct |
894 ms |
69104 KB |
n=200000 |
109 |
Correct |
914 ms |
69120 KB |
n=200000 |
110 |
Correct |
919 ms |
69088 KB |
n=200000 |
111 |
Correct |
753 ms |
69332 KB |
n=200000 |
112 |
Correct |
1086 ms |
79624 KB |
n=200000 |
113 |
Correct |
1252 ms |
73600 KB |
n=200000 |
114 |
Correct |
890 ms |
69484 KB |
n=200000 |
115 |
Correct |
1304 ms |
70808 KB |
n=200000 |
116 |
Correct |
761 ms |
69256 KB |
n=200000 |
117 |
Correct |
1107 ms |
80128 KB |
n=200000 |
118 |
Correct |
1238 ms |
72116 KB |
n=200000 |
119 |
Correct |
693 ms |
69180 KB |
n=200000 |
120 |
Correct |
999 ms |
81020 KB |
n=200000 |
121 |
Correct |
1064 ms |
80732 KB |
n=200000 |
122 |
Correct |
996 ms |
81208 KB |
n=200000 |
123 |
Correct |
477 ms |
69776 KB |
n=200000 |
124 |
Correct |
238 ms |
37416 KB |
n=25264 |