#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define for1(i,j,k) for(int i=j;i<=k;i++)
#define for2(i,j,k) for(int i=j;i>=k;i--)
#define for3(i,j,k,l) for(int i=j;i<=k;i+=l)
#define bit(n,i) ((n>>i)&1)
#define all(x) x.begin(),x.end()
//#pragma GCC optimize("O2,unroll-loops")
//#pragma GCC target("avx,avx2,bmi,bmi2,sse,sse2,sse3,ssse3,sse4,popcnt")
//#define int long long
typedef long long ll;
typedef pair<int,int> pii;
typedef double ld;
typedef pair<ld,ld> pdd;
typedef pair<ll,ll> pll;
const ll maxn=2e5+5;
const ll offset=1e9;
const ll block_sz=317;
const ll inf=1e9;
const ll mod=1e9+7;
int n,m,q,up[maxn][19],in[maxn],out[maxn],a[maxn],Time;
set<pii> L[maxn];
vector<int> adj[maxn];
void dfs(int u,int pre)
{
in[u]=++Time;
up[u][0]=pre;
for1(i,1,18)
{
up[u][i]=up[up[u][i-1]][i-1];
}
for(int v: adj[u])
{
if (v==pre) continue;
dfs(v,u);
}
out[u]=Time;
}
bool chk(int u,int v)
{
return (in[u]<=in[v] && out[v]<=out[u]);
}
int lca(int u,int v)
{
if (chk(u,v)) return u;
if (chk(v,u)) return v;
for2(i,18,0)
{
if (!chk(up[u][i],v)) u=up[u][i];
}
return up[u][0];
}
void sol()
{
cin >> n>>m>>q;
for1(i,2,n)
{
int u,v; cin >> u>> v;
adj[u].pb(v);
adj[v].pb(u);
}
dfs(1,1);
//cerr<< chk(4,5)<<" wtf\n";
for1(i,1,m)
{
cin >> a[i];
L[a[i]].insert({i,i});
}
for1(i,1,m-1)
{
L[lca(a[i],a[i+1])].insert({i,i+1});
}
for1(i,1,q)
{
//cerr<< i<<'\n';
int type; cin >> type;
if (type==1)
{
int pos,u;cin >> pos>>u;
L[a[pos]].erase({pos,pos});
L[u].insert({pos,pos});
if (pos>1)
{
L[lca(a[pos],a[pos-1])].erase({pos-1,pos});
L[lca(u,a[pos-1])].insert({pos-1,pos});
}
if (pos<m)
{
L[lca(a[pos],a[pos+1])].erase({pos,pos+1});
L[lca(u,a[pos+1])].insert({pos,pos+1});
}
a[pos]=u;
}
else
{
int l,r,u;cin >> l>> r>>u;
auto it=L[u].lower_bound({l,l});
if (it!=L[u].end() && it->se <=r) cout << it->fi << ' '<<it->se<<'\n';
else cout << -1 << ' '<<-1<<'\n';
}
}
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
// freopen("GROUPDIV.inp","r",stdin);
// freopen("GROUPDIV.out","w",stdout);
int t=1;//cin >> t;
while (t--)
{
sol();
}
}
/*
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
5 4 1
1 2
3 1
3 4
5 3
4 5 2 3
2 1 3 1
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14420 KB |
n=5 |
2 |
Correct |
7 ms |
14420 KB |
n=100 |
3 |
Correct |
8 ms |
14420 KB |
n=100 |
4 |
Correct |
7 ms |
14420 KB |
n=100 |
5 |
Correct |
7 ms |
14420 KB |
n=100 |
6 |
Correct |
8 ms |
14420 KB |
n=100 |
7 |
Correct |
7 ms |
14420 KB |
n=100 |
8 |
Correct |
8 ms |
14416 KB |
n=100 |
9 |
Correct |
8 ms |
14420 KB |
n=100 |
10 |
Correct |
7 ms |
14420 KB |
n=100 |
11 |
Correct |
7 ms |
14420 KB |
n=100 |
12 |
Correct |
8 ms |
14420 KB |
n=100 |
13 |
Correct |
7 ms |
14420 KB |
n=100 |
14 |
Correct |
8 ms |
14420 KB |
n=100 |
15 |
Correct |
7 ms |
14420 KB |
n=100 |
16 |
Correct |
7 ms |
14420 KB |
n=100 |
17 |
Correct |
7 ms |
14420 KB |
n=100 |
18 |
Correct |
7 ms |
14420 KB |
n=100 |
19 |
Correct |
7 ms |
14420 KB |
n=100 |
20 |
Correct |
9 ms |
14544 KB |
n=100 |
21 |
Correct |
7 ms |
14420 KB |
n=100 |
22 |
Correct |
8 ms |
14420 KB |
n=100 |
23 |
Correct |
7 ms |
14420 KB |
n=100 |
24 |
Correct |
8 ms |
14420 KB |
n=100 |
25 |
Correct |
7 ms |
14420 KB |
n=100 |
26 |
Correct |
8 ms |
14420 KB |
n=12 |
27 |
Correct |
7 ms |
14420 KB |
n=100 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14420 KB |
n=5 |
2 |
Correct |
7 ms |
14420 KB |
n=100 |
3 |
Correct |
8 ms |
14420 KB |
n=100 |
4 |
Correct |
7 ms |
14420 KB |
n=100 |
5 |
Correct |
7 ms |
14420 KB |
n=100 |
6 |
Correct |
8 ms |
14420 KB |
n=100 |
7 |
Correct |
7 ms |
14420 KB |
n=100 |
8 |
Correct |
8 ms |
14416 KB |
n=100 |
9 |
Correct |
8 ms |
14420 KB |
n=100 |
10 |
Correct |
7 ms |
14420 KB |
n=100 |
11 |
Correct |
7 ms |
14420 KB |
n=100 |
12 |
Correct |
8 ms |
14420 KB |
n=100 |
13 |
Correct |
7 ms |
14420 KB |
n=100 |
14 |
Correct |
8 ms |
14420 KB |
n=100 |
15 |
Correct |
7 ms |
14420 KB |
n=100 |
16 |
Correct |
7 ms |
14420 KB |
n=100 |
17 |
Correct |
7 ms |
14420 KB |
n=100 |
18 |
Correct |
7 ms |
14420 KB |
n=100 |
19 |
Correct |
7 ms |
14420 KB |
n=100 |
20 |
Correct |
9 ms |
14544 KB |
n=100 |
21 |
Correct |
7 ms |
14420 KB |
n=100 |
22 |
Correct |
8 ms |
14420 KB |
n=100 |
23 |
Correct |
7 ms |
14420 KB |
n=100 |
24 |
Correct |
8 ms |
14420 KB |
n=100 |
25 |
Correct |
7 ms |
14420 KB |
n=100 |
26 |
Correct |
8 ms |
14420 KB |
n=12 |
27 |
Correct |
7 ms |
14420 KB |
n=100 |
28 |
Correct |
7 ms |
14548 KB |
n=500 |
29 |
Correct |
8 ms |
14548 KB |
n=500 |
30 |
Correct |
7 ms |
14560 KB |
n=500 |
31 |
Correct |
9 ms |
14564 KB |
n=500 |
32 |
Correct |
7 ms |
14548 KB |
n=500 |
33 |
Correct |
8 ms |
14548 KB |
n=500 |
34 |
Correct |
8 ms |
14548 KB |
n=500 |
35 |
Correct |
8 ms |
14548 KB |
n=500 |
36 |
Correct |
7 ms |
14548 KB |
n=500 |
37 |
Correct |
7 ms |
14548 KB |
n=500 |
38 |
Correct |
8 ms |
14548 KB |
n=500 |
39 |
Correct |
7 ms |
14548 KB |
n=500 |
40 |
Correct |
9 ms |
14548 KB |
n=500 |
41 |
Correct |
7 ms |
14548 KB |
n=500 |
42 |
Correct |
8 ms |
14548 KB |
n=500 |
43 |
Correct |
8 ms |
14548 KB |
n=500 |
44 |
Correct |
7 ms |
14548 KB |
n=500 |
45 |
Correct |
7 ms |
14548 KB |
n=500 |
46 |
Correct |
7 ms |
14548 KB |
n=500 |
47 |
Correct |
7 ms |
14548 KB |
n=500 |
48 |
Correct |
7 ms |
14548 KB |
n=500 |
49 |
Correct |
8 ms |
14572 KB |
n=500 |
50 |
Correct |
10 ms |
14548 KB |
n=500 |
51 |
Correct |
8 ms |
14548 KB |
n=500 |
52 |
Correct |
8 ms |
14548 KB |
n=500 |
53 |
Correct |
9 ms |
14564 KB |
n=500 |
54 |
Correct |
7 ms |
14548 KB |
n=500 |
55 |
Correct |
7 ms |
14420 KB |
n=278 |
56 |
Correct |
7 ms |
14548 KB |
n=500 |
57 |
Correct |
7 ms |
14548 KB |
n=500 |
58 |
Correct |
8 ms |
14548 KB |
n=500 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14420 KB |
n=5 |
2 |
Correct |
7 ms |
14420 KB |
n=100 |
3 |
Correct |
8 ms |
14420 KB |
n=100 |
4 |
Correct |
7 ms |
14420 KB |
n=100 |
5 |
Correct |
7 ms |
14420 KB |
n=100 |
6 |
Correct |
8 ms |
14420 KB |
n=100 |
7 |
Correct |
7 ms |
14420 KB |
n=100 |
8 |
Correct |
8 ms |
14416 KB |
n=100 |
9 |
Correct |
8 ms |
14420 KB |
n=100 |
10 |
Correct |
7 ms |
14420 KB |
n=100 |
11 |
Correct |
7 ms |
14420 KB |
n=100 |
12 |
Correct |
8 ms |
14420 KB |
n=100 |
13 |
Correct |
7 ms |
14420 KB |
n=100 |
14 |
Correct |
8 ms |
14420 KB |
n=100 |
15 |
Correct |
7 ms |
14420 KB |
n=100 |
16 |
Correct |
7 ms |
14420 KB |
n=100 |
17 |
Correct |
7 ms |
14420 KB |
n=100 |
18 |
Correct |
7 ms |
14420 KB |
n=100 |
19 |
Correct |
7 ms |
14420 KB |
n=100 |
20 |
Correct |
9 ms |
14544 KB |
n=100 |
21 |
Correct |
7 ms |
14420 KB |
n=100 |
22 |
Correct |
8 ms |
14420 KB |
n=100 |
23 |
Correct |
7 ms |
14420 KB |
n=100 |
24 |
Correct |
8 ms |
14420 KB |
n=100 |
25 |
Correct |
7 ms |
14420 KB |
n=100 |
26 |
Correct |
8 ms |
14420 KB |
n=12 |
27 |
Correct |
7 ms |
14420 KB |
n=100 |
28 |
Correct |
7 ms |
14548 KB |
n=500 |
29 |
Correct |
8 ms |
14548 KB |
n=500 |
30 |
Correct |
7 ms |
14560 KB |
n=500 |
31 |
Correct |
9 ms |
14564 KB |
n=500 |
32 |
Correct |
7 ms |
14548 KB |
n=500 |
33 |
Correct |
8 ms |
14548 KB |
n=500 |
34 |
Correct |
8 ms |
14548 KB |
n=500 |
35 |
Correct |
8 ms |
14548 KB |
n=500 |
36 |
Correct |
7 ms |
14548 KB |
n=500 |
37 |
Correct |
7 ms |
14548 KB |
n=500 |
38 |
Correct |
8 ms |
14548 KB |
n=500 |
39 |
Correct |
7 ms |
14548 KB |
n=500 |
40 |
Correct |
9 ms |
14548 KB |
n=500 |
41 |
Correct |
7 ms |
14548 KB |
n=500 |
42 |
Correct |
8 ms |
14548 KB |
n=500 |
43 |
Correct |
8 ms |
14548 KB |
n=500 |
44 |
Correct |
7 ms |
14548 KB |
n=500 |
45 |
Correct |
7 ms |
14548 KB |
n=500 |
46 |
Correct |
7 ms |
14548 KB |
n=500 |
47 |
Correct |
7 ms |
14548 KB |
n=500 |
48 |
Correct |
7 ms |
14548 KB |
n=500 |
49 |
Correct |
8 ms |
14572 KB |
n=500 |
50 |
Correct |
10 ms |
14548 KB |
n=500 |
51 |
Correct |
8 ms |
14548 KB |
n=500 |
52 |
Correct |
8 ms |
14548 KB |
n=500 |
53 |
Correct |
9 ms |
14564 KB |
n=500 |
54 |
Correct |
7 ms |
14548 KB |
n=500 |
55 |
Correct |
7 ms |
14420 KB |
n=278 |
56 |
Correct |
7 ms |
14548 KB |
n=500 |
57 |
Correct |
7 ms |
14548 KB |
n=500 |
58 |
Correct |
8 ms |
14548 KB |
n=500 |
59 |
Correct |
12 ms |
14932 KB |
n=2000 |
60 |
Correct |
9 ms |
14932 KB |
n=2000 |
61 |
Correct |
10 ms |
14932 KB |
n=2000 |
62 |
Correct |
10 ms |
14932 KB |
n=2000 |
63 |
Correct |
10 ms |
14932 KB |
n=2000 |
64 |
Correct |
10 ms |
15016 KB |
n=2000 |
65 |
Correct |
10 ms |
14932 KB |
n=2000 |
66 |
Correct |
9 ms |
15060 KB |
n=2000 |
67 |
Correct |
10 ms |
14804 KB |
n=2000 |
68 |
Correct |
9 ms |
14932 KB |
n=2000 |
69 |
Correct |
9 ms |
14932 KB |
n=2000 |
70 |
Correct |
10 ms |
14932 KB |
n=2000 |
71 |
Correct |
11 ms |
14932 KB |
n=2000 |
72 |
Correct |
9 ms |
14804 KB |
n=2000 |
73 |
Correct |
9 ms |
14932 KB |
n=2000 |
74 |
Correct |
9 ms |
14804 KB |
n=1844 |
75 |
Correct |
10 ms |
14804 KB |
n=2000 |
76 |
Correct |
10 ms |
14804 KB |
n=2000 |
77 |
Correct |
10 ms |
14804 KB |
n=2000 |
78 |
Correct |
10 ms |
14928 KB |
n=2000 |
79 |
Correct |
11 ms |
14804 KB |
n=2000 |
80 |
Correct |
9 ms |
14932 KB |
n=2000 |
81 |
Correct |
12 ms |
14932 KB |
n=2000 |
82 |
Correct |
10 ms |
14804 KB |
n=2000 |
83 |
Correct |
9 ms |
14932 KB |
n=2000 |
84 |
Correct |
10 ms |
14804 KB |
n=2000 |
85 |
Correct |
10 ms |
14932 KB |
n=2000 |
86 |
Correct |
12 ms |
14900 KB |
n=2000 |
87 |
Correct |
10 ms |
14932 KB |
n=2000 |
88 |
Correct |
9 ms |
14932 KB |
n=2000 |
89 |
Correct |
9 ms |
14940 KB |
n=2000 |
90 |
Correct |
10 ms |
15056 KB |
n=2000 |
91 |
Correct |
9 ms |
14932 KB |
n=2000 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14420 KB |
n=5 |
2 |
Correct |
7 ms |
14420 KB |
n=100 |
3 |
Correct |
8 ms |
14420 KB |
n=100 |
4 |
Correct |
7 ms |
14420 KB |
n=100 |
5 |
Correct |
7 ms |
14420 KB |
n=100 |
6 |
Correct |
8 ms |
14420 KB |
n=100 |
7 |
Correct |
7 ms |
14420 KB |
n=100 |
8 |
Correct |
8 ms |
14416 KB |
n=100 |
9 |
Correct |
8 ms |
14420 KB |
n=100 |
10 |
Correct |
7 ms |
14420 KB |
n=100 |
11 |
Correct |
7 ms |
14420 KB |
n=100 |
12 |
Correct |
8 ms |
14420 KB |
n=100 |
13 |
Correct |
7 ms |
14420 KB |
n=100 |
14 |
Correct |
8 ms |
14420 KB |
n=100 |
15 |
Correct |
7 ms |
14420 KB |
n=100 |
16 |
Correct |
7 ms |
14420 KB |
n=100 |
17 |
Correct |
7 ms |
14420 KB |
n=100 |
18 |
Correct |
7 ms |
14420 KB |
n=100 |
19 |
Correct |
7 ms |
14420 KB |
n=100 |
20 |
Correct |
9 ms |
14544 KB |
n=100 |
21 |
Correct |
7 ms |
14420 KB |
n=100 |
22 |
Correct |
8 ms |
14420 KB |
n=100 |
23 |
Correct |
7 ms |
14420 KB |
n=100 |
24 |
Correct |
8 ms |
14420 KB |
n=100 |
25 |
Correct |
7 ms |
14420 KB |
n=100 |
26 |
Correct |
8 ms |
14420 KB |
n=12 |
27 |
Correct |
7 ms |
14420 KB |
n=100 |
28 |
Correct |
7 ms |
14548 KB |
n=500 |
29 |
Correct |
8 ms |
14548 KB |
n=500 |
30 |
Correct |
7 ms |
14560 KB |
n=500 |
31 |
Correct |
9 ms |
14564 KB |
n=500 |
32 |
Correct |
7 ms |
14548 KB |
n=500 |
33 |
Correct |
8 ms |
14548 KB |
n=500 |
34 |
Correct |
8 ms |
14548 KB |
n=500 |
35 |
Correct |
8 ms |
14548 KB |
n=500 |
36 |
Correct |
7 ms |
14548 KB |
n=500 |
37 |
Correct |
7 ms |
14548 KB |
n=500 |
38 |
Correct |
8 ms |
14548 KB |
n=500 |
39 |
Correct |
7 ms |
14548 KB |
n=500 |
40 |
Correct |
9 ms |
14548 KB |
n=500 |
41 |
Correct |
7 ms |
14548 KB |
n=500 |
42 |
Correct |
8 ms |
14548 KB |
n=500 |
43 |
Correct |
8 ms |
14548 KB |
n=500 |
44 |
Correct |
7 ms |
14548 KB |
n=500 |
45 |
Correct |
7 ms |
14548 KB |
n=500 |
46 |
Correct |
7 ms |
14548 KB |
n=500 |
47 |
Correct |
7 ms |
14548 KB |
n=500 |
48 |
Correct |
7 ms |
14548 KB |
n=500 |
49 |
Correct |
8 ms |
14572 KB |
n=500 |
50 |
Correct |
10 ms |
14548 KB |
n=500 |
51 |
Correct |
8 ms |
14548 KB |
n=500 |
52 |
Correct |
8 ms |
14548 KB |
n=500 |
53 |
Correct |
9 ms |
14564 KB |
n=500 |
54 |
Correct |
7 ms |
14548 KB |
n=500 |
55 |
Correct |
7 ms |
14420 KB |
n=278 |
56 |
Correct |
7 ms |
14548 KB |
n=500 |
57 |
Correct |
7 ms |
14548 KB |
n=500 |
58 |
Correct |
8 ms |
14548 KB |
n=500 |
59 |
Correct |
12 ms |
14932 KB |
n=2000 |
60 |
Correct |
9 ms |
14932 KB |
n=2000 |
61 |
Correct |
10 ms |
14932 KB |
n=2000 |
62 |
Correct |
10 ms |
14932 KB |
n=2000 |
63 |
Correct |
10 ms |
14932 KB |
n=2000 |
64 |
Correct |
10 ms |
15016 KB |
n=2000 |
65 |
Correct |
10 ms |
14932 KB |
n=2000 |
66 |
Correct |
9 ms |
15060 KB |
n=2000 |
67 |
Correct |
10 ms |
14804 KB |
n=2000 |
68 |
Correct |
9 ms |
14932 KB |
n=2000 |
69 |
Correct |
9 ms |
14932 KB |
n=2000 |
70 |
Correct |
10 ms |
14932 KB |
n=2000 |
71 |
Correct |
11 ms |
14932 KB |
n=2000 |
72 |
Correct |
9 ms |
14804 KB |
n=2000 |
73 |
Correct |
9 ms |
14932 KB |
n=2000 |
74 |
Correct |
9 ms |
14804 KB |
n=1844 |
75 |
Correct |
10 ms |
14804 KB |
n=2000 |
76 |
Correct |
10 ms |
14804 KB |
n=2000 |
77 |
Correct |
10 ms |
14804 KB |
n=2000 |
78 |
Correct |
10 ms |
14928 KB |
n=2000 |
79 |
Correct |
11 ms |
14804 KB |
n=2000 |
80 |
Correct |
9 ms |
14932 KB |
n=2000 |
81 |
Correct |
12 ms |
14932 KB |
n=2000 |
82 |
Correct |
10 ms |
14804 KB |
n=2000 |
83 |
Correct |
9 ms |
14932 KB |
n=2000 |
84 |
Correct |
10 ms |
14804 KB |
n=2000 |
85 |
Correct |
10 ms |
14932 KB |
n=2000 |
86 |
Correct |
12 ms |
14900 KB |
n=2000 |
87 |
Correct |
10 ms |
14932 KB |
n=2000 |
88 |
Correct |
9 ms |
14932 KB |
n=2000 |
89 |
Correct |
9 ms |
14940 KB |
n=2000 |
90 |
Correct |
10 ms |
15056 KB |
n=2000 |
91 |
Correct |
9 ms |
14932 KB |
n=2000 |
92 |
Correct |
552 ms |
65184 KB |
n=200000 |
93 |
Correct |
681 ms |
70056 KB |
n=200000 |
94 |
Correct |
480 ms |
73376 KB |
n=200000 |
95 |
Correct |
555 ms |
64868 KB |
n=200000 |
96 |
Correct |
545 ms |
64976 KB |
n=200000 |
97 |
Correct |
722 ms |
69068 KB |
n=200000 |
98 |
Correct |
540 ms |
64944 KB |
n=200000 |
99 |
Correct |
629 ms |
65244 KB |
n=200000 |
100 |
Correct |
528 ms |
64964 KB |
n=200000 |
101 |
Correct |
394 ms |
74572 KB |
n=200000 |
102 |
Correct |
317 ms |
66168 KB |
n=200000 |
103 |
Correct |
315 ms |
66160 KB |
n=200000 |
104 |
Correct |
319 ms |
66164 KB |
n=200000 |
105 |
Correct |
322 ms |
66508 KB |
n=200000 |
106 |
Correct |
306 ms |
66604 KB |
n=200000 |
107 |
Correct |
316 ms |
66572 KB |
n=200000 |
108 |
Correct |
605 ms |
65044 KB |
n=200000 |
109 |
Correct |
556 ms |
65076 KB |
n=200000 |
110 |
Correct |
549 ms |
64952 KB |
n=200000 |
111 |
Correct |
556 ms |
64400 KB |
n=200000 |
112 |
Correct |
448 ms |
73552 KB |
n=200000 |
113 |
Correct |
715 ms |
69076 KB |
n=200000 |
114 |
Correct |
570 ms |
64412 KB |
n=200000 |
115 |
Correct |
811 ms |
67000 KB |
n=200000 |
116 |
Correct |
517 ms |
65036 KB |
n=200000 |
117 |
Correct |
422 ms |
73944 KB |
n=200000 |
118 |
Correct |
684 ms |
67888 KB |
n=200000 |
119 |
Correct |
532 ms |
65224 KB |
n=200000 |
120 |
Correct |
380 ms |
73700 KB |
n=200000 |
121 |
Correct |
395 ms |
73640 KB |
n=200000 |
122 |
Correct |
368 ms |
73980 KB |
n=200000 |
123 |
Correct |
333 ms |
66316 KB |
n=200000 |
124 |
Correct |
121 ms |
29244 KB |
n=25264 |