#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pi pair<int, int>
#define pii pair<int, pi>
#define fi first
#define se second
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
int n, m, q;
vector <int> adj[300005];
multiset <int> ms[300005];
int S[300005], E[300005], cnt = 1, par[20][200005], dep[200005];
void dfs(int x, int p, int d){
S[x] = cnt++;
par[0][x] = p;
dep[x] = d;
for(auto i : adj[x])if(i != p)dfs(i, x, d + 1);
E[x] = cnt - 1;
}
int lca(int u, int v){
if(dep[u] > dep[v])swap(u, v);
int df = dep[v] - dep[u];
for(int i=0;i<19;i++)if(df >> i & 1)v = par[i][v];
if(u == v)return u;
for(int i=19;i>=0;i--){
if(par[i][u] != par[i][v])u = par[i][u], v = par[i][v];
}
return par[0][u];
}
int back[300005];
struct node{
int s, e, m, mn, mx;
node *l, *r;
node(int _s, int _e){
s = _s, e = _e, m = (s + e) >> 1;
if(s != e)l = new node(s, m), r = new node(m+1, e);
mn = 1e9, mx = 0;
}
void upd(int p, int v, int v2){
if(s == e)mn = v, mx = v2;
else{
if(p <= m)l->upd(p, v, v2);
else r->upd(p, v, v2);
mn = min(l->mn, r->mn);
mx = max(l->mx, r->mx);
}
}
pi qry(int a, int b){
if(s == a && e == b)return {mn, mx};
else if(b <= m)return l->qry(a, b);
else if(a > m)return r->qry(a ,b);
else {
pi lft = l->qry(a, m), rgt = r->qry(m+1, b);
lft.fi = min(lft.fi, rgt.fi);
lft.se = max(lft.se, rgt.se);
return lft;
}
}
}*root;
int A[300005];
void solve(){
cin >> n >> m >> q;
for(int i=1;i<n;i++){
int a, b; cin >> a >> b;
adj[a].push_back(b);
adj[b].push_back(a);
}
dfs(1, -1, 1);
for(int i=1;i<=m;i++)cin >> A[i], ms[A[i]].insert(i);
/*
root = new node(1, n);
for(int i=1;i<=n;i++){
if(!ms[i].empty()){
auto it = ms[i].begin(), it2 = --ms[i].end();
root->upd(S[i], *it, *it2);
}
}
*/
for(int i=1;i<=n;i++)back[S[i]] = i;
for(int i=1;i<=19;i++)for(int j=1;j<=n;j++)par[i][j] = par[i-1][par[i-1][j]];
while(q--){
int t; cin >> t;
if(t == 1){
int x, y; cin >> x >> y;
/*
ms[A[x]].erase(ms[A[x]].find(i));
if(!ms[A[x]].empty()){
auto it = ms[A[x]].begin(), it2 = --ms[A[x]].end();
root->upd(S[i], *it, *it2);
}
else root->upd(S[i], 1e9, 0);
A[x] = y;
ms[y].insert(i);
if(!ms[y].empty()){
auto it = ms[y].begin(), it2 = --ms[y].end();
root->upd(S[y], *it, *it2);
}
*/
A[x] = y;
}
else{
int l, r, v; cin >> l >> r >> v;
int mn = 1e9, mx = 0, f = 0, st = l;
for(int i = l; i <= r; i++){
if(S[A[i]] < S[v] || S[A[i]] > E[v]){
mn = 1e9; mx = 0;
st = i + 1;
continue;
}
mn = min(mn, S[A[i]]);
mx = max(mx, S[A[i]]);
if(lca(back[mn], back[mx]) == v){
f = 1;
cout << st << ' ' << i << '\n';
break;
}
}
if(!f)cout << -1 << ' ' << -1 << '\n';
}
}
}
main(){
ios::sync_with_stdio(0);cin.tie(0);
int tc = 1;
//cin >> tc;
for(int tc1=1;tc1<=tc;tc1++){
// cout << "Case #" << tc1 << ": ";
solve();
}
}
Compilation message
treearray.cpp:134:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
134 | main(){
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
61528 KB |
n=5 |
2 |
Correct |
13 ms |
61528 KB |
n=100 |
3 |
Correct |
14 ms |
61528 KB |
n=100 |
4 |
Correct |
13 ms |
61532 KB |
n=100 |
5 |
Correct |
13 ms |
61532 KB |
n=100 |
6 |
Correct |
13 ms |
61564 KB |
n=100 |
7 |
Correct |
13 ms |
61532 KB |
n=100 |
8 |
Correct |
13 ms |
61544 KB |
n=100 |
9 |
Correct |
13 ms |
61528 KB |
n=100 |
10 |
Correct |
15 ms |
61516 KB |
n=100 |
11 |
Correct |
14 ms |
61528 KB |
n=100 |
12 |
Correct |
13 ms |
61528 KB |
n=100 |
13 |
Correct |
14 ms |
61528 KB |
n=100 |
14 |
Correct |
13 ms |
61644 KB |
n=100 |
15 |
Correct |
13 ms |
61532 KB |
n=100 |
16 |
Correct |
13 ms |
61528 KB |
n=100 |
17 |
Correct |
13 ms |
61528 KB |
n=100 |
18 |
Correct |
13 ms |
61532 KB |
n=100 |
19 |
Correct |
13 ms |
61532 KB |
n=100 |
20 |
Correct |
13 ms |
61528 KB |
n=100 |
21 |
Correct |
13 ms |
61532 KB |
n=100 |
22 |
Correct |
14 ms |
61532 KB |
n=100 |
23 |
Correct |
13 ms |
61616 KB |
n=100 |
24 |
Correct |
14 ms |
61532 KB |
n=100 |
25 |
Correct |
13 ms |
61532 KB |
n=100 |
26 |
Correct |
14 ms |
61528 KB |
n=12 |
27 |
Correct |
13 ms |
61532 KB |
n=100 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
61528 KB |
n=5 |
2 |
Correct |
13 ms |
61528 KB |
n=100 |
3 |
Correct |
14 ms |
61528 KB |
n=100 |
4 |
Correct |
13 ms |
61532 KB |
n=100 |
5 |
Correct |
13 ms |
61532 KB |
n=100 |
6 |
Correct |
13 ms |
61564 KB |
n=100 |
7 |
Correct |
13 ms |
61532 KB |
n=100 |
8 |
Correct |
13 ms |
61544 KB |
n=100 |
9 |
Correct |
13 ms |
61528 KB |
n=100 |
10 |
Correct |
15 ms |
61516 KB |
n=100 |
11 |
Correct |
14 ms |
61528 KB |
n=100 |
12 |
Correct |
13 ms |
61528 KB |
n=100 |
13 |
Correct |
14 ms |
61528 KB |
n=100 |
14 |
Correct |
13 ms |
61644 KB |
n=100 |
15 |
Correct |
13 ms |
61532 KB |
n=100 |
16 |
Correct |
13 ms |
61528 KB |
n=100 |
17 |
Correct |
13 ms |
61528 KB |
n=100 |
18 |
Correct |
13 ms |
61532 KB |
n=100 |
19 |
Correct |
13 ms |
61532 KB |
n=100 |
20 |
Correct |
13 ms |
61528 KB |
n=100 |
21 |
Correct |
13 ms |
61532 KB |
n=100 |
22 |
Correct |
14 ms |
61532 KB |
n=100 |
23 |
Correct |
13 ms |
61616 KB |
n=100 |
24 |
Correct |
14 ms |
61532 KB |
n=100 |
25 |
Correct |
13 ms |
61532 KB |
n=100 |
26 |
Correct |
14 ms |
61528 KB |
n=12 |
27 |
Correct |
13 ms |
61532 KB |
n=100 |
28 |
Correct |
14 ms |
61528 KB |
n=500 |
29 |
Correct |
14 ms |
61532 KB |
n=500 |
30 |
Correct |
14 ms |
61528 KB |
n=500 |
31 |
Correct |
14 ms |
61532 KB |
n=500 |
32 |
Correct |
13 ms |
61528 KB |
n=500 |
33 |
Correct |
14 ms |
61704 KB |
n=500 |
34 |
Correct |
13 ms |
61532 KB |
n=500 |
35 |
Correct |
13 ms |
61532 KB |
n=500 |
36 |
Correct |
15 ms |
61652 KB |
n=500 |
37 |
Correct |
15 ms |
61528 KB |
n=500 |
38 |
Correct |
15 ms |
61528 KB |
n=500 |
39 |
Correct |
13 ms |
61532 KB |
n=500 |
40 |
Correct |
14 ms |
61532 KB |
n=500 |
41 |
Correct |
16 ms |
61528 KB |
n=500 |
42 |
Correct |
15 ms |
61532 KB |
n=500 |
43 |
Correct |
16 ms |
61656 KB |
n=500 |
44 |
Correct |
15 ms |
61528 KB |
n=500 |
45 |
Correct |
14 ms |
61668 KB |
n=500 |
46 |
Correct |
14 ms |
61528 KB |
n=500 |
47 |
Correct |
14 ms |
61528 KB |
n=500 |
48 |
Correct |
13 ms |
61532 KB |
n=500 |
49 |
Correct |
14 ms |
61528 KB |
n=500 |
50 |
Correct |
14 ms |
61528 KB |
n=500 |
51 |
Correct |
14 ms |
61528 KB |
n=500 |
52 |
Correct |
14 ms |
61532 KB |
n=500 |
53 |
Correct |
16 ms |
61528 KB |
n=500 |
54 |
Correct |
15 ms |
61676 KB |
n=500 |
55 |
Correct |
13 ms |
61532 KB |
n=278 |
56 |
Correct |
15 ms |
61532 KB |
n=500 |
57 |
Correct |
17 ms |
61532 KB |
n=500 |
58 |
Correct |
14 ms |
61580 KB |
n=500 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
61528 KB |
n=5 |
2 |
Correct |
13 ms |
61528 KB |
n=100 |
3 |
Correct |
14 ms |
61528 KB |
n=100 |
4 |
Correct |
13 ms |
61532 KB |
n=100 |
5 |
Correct |
13 ms |
61532 KB |
n=100 |
6 |
Correct |
13 ms |
61564 KB |
n=100 |
7 |
Correct |
13 ms |
61532 KB |
n=100 |
8 |
Correct |
13 ms |
61544 KB |
n=100 |
9 |
Correct |
13 ms |
61528 KB |
n=100 |
10 |
Correct |
15 ms |
61516 KB |
n=100 |
11 |
Correct |
14 ms |
61528 KB |
n=100 |
12 |
Correct |
13 ms |
61528 KB |
n=100 |
13 |
Correct |
14 ms |
61528 KB |
n=100 |
14 |
Correct |
13 ms |
61644 KB |
n=100 |
15 |
Correct |
13 ms |
61532 KB |
n=100 |
16 |
Correct |
13 ms |
61528 KB |
n=100 |
17 |
Correct |
13 ms |
61528 KB |
n=100 |
18 |
Correct |
13 ms |
61532 KB |
n=100 |
19 |
Correct |
13 ms |
61532 KB |
n=100 |
20 |
Correct |
13 ms |
61528 KB |
n=100 |
21 |
Correct |
13 ms |
61532 KB |
n=100 |
22 |
Correct |
14 ms |
61532 KB |
n=100 |
23 |
Correct |
13 ms |
61616 KB |
n=100 |
24 |
Correct |
14 ms |
61532 KB |
n=100 |
25 |
Correct |
13 ms |
61532 KB |
n=100 |
26 |
Correct |
14 ms |
61528 KB |
n=12 |
27 |
Correct |
13 ms |
61532 KB |
n=100 |
28 |
Correct |
14 ms |
61528 KB |
n=500 |
29 |
Correct |
14 ms |
61532 KB |
n=500 |
30 |
Correct |
14 ms |
61528 KB |
n=500 |
31 |
Correct |
14 ms |
61532 KB |
n=500 |
32 |
Correct |
13 ms |
61528 KB |
n=500 |
33 |
Correct |
14 ms |
61704 KB |
n=500 |
34 |
Correct |
13 ms |
61532 KB |
n=500 |
35 |
Correct |
13 ms |
61532 KB |
n=500 |
36 |
Correct |
15 ms |
61652 KB |
n=500 |
37 |
Correct |
15 ms |
61528 KB |
n=500 |
38 |
Correct |
15 ms |
61528 KB |
n=500 |
39 |
Correct |
13 ms |
61532 KB |
n=500 |
40 |
Correct |
14 ms |
61532 KB |
n=500 |
41 |
Correct |
16 ms |
61528 KB |
n=500 |
42 |
Correct |
15 ms |
61532 KB |
n=500 |
43 |
Correct |
16 ms |
61656 KB |
n=500 |
44 |
Correct |
15 ms |
61528 KB |
n=500 |
45 |
Correct |
14 ms |
61668 KB |
n=500 |
46 |
Correct |
14 ms |
61528 KB |
n=500 |
47 |
Correct |
14 ms |
61528 KB |
n=500 |
48 |
Correct |
13 ms |
61532 KB |
n=500 |
49 |
Correct |
14 ms |
61528 KB |
n=500 |
50 |
Correct |
14 ms |
61528 KB |
n=500 |
51 |
Correct |
14 ms |
61528 KB |
n=500 |
52 |
Correct |
14 ms |
61532 KB |
n=500 |
53 |
Correct |
16 ms |
61528 KB |
n=500 |
54 |
Correct |
15 ms |
61676 KB |
n=500 |
55 |
Correct |
13 ms |
61532 KB |
n=278 |
56 |
Correct |
15 ms |
61532 KB |
n=500 |
57 |
Correct |
17 ms |
61532 KB |
n=500 |
58 |
Correct |
14 ms |
61580 KB |
n=500 |
59 |
Correct |
14 ms |
61784 KB |
n=2000 |
60 |
Correct |
25 ms |
61932 KB |
n=2000 |
61 |
Correct |
27 ms |
61784 KB |
n=2000 |
62 |
Correct |
28 ms |
61836 KB |
n=2000 |
63 |
Correct |
17 ms |
61788 KB |
n=2000 |
64 |
Correct |
25 ms |
61788 KB |
n=2000 |
65 |
Correct |
16 ms |
61884 KB |
n=2000 |
66 |
Correct |
27 ms |
61788 KB |
n=2000 |
67 |
Correct |
15 ms |
61764 KB |
n=2000 |
68 |
Correct |
27 ms |
61784 KB |
n=2000 |
69 |
Correct |
32 ms |
61892 KB |
n=2000 |
70 |
Correct |
32 ms |
61788 KB |
n=2000 |
71 |
Correct |
32 ms |
61880 KB |
n=2000 |
72 |
Correct |
28 ms |
61788 KB |
n=2000 |
73 |
Correct |
23 ms |
61788 KB |
n=2000 |
74 |
Correct |
16 ms |
61824 KB |
n=1844 |
75 |
Correct |
25 ms |
61788 KB |
n=2000 |
76 |
Correct |
34 ms |
61784 KB |
n=2000 |
77 |
Correct |
32 ms |
61788 KB |
n=2000 |
78 |
Correct |
36 ms |
61788 KB |
n=2000 |
79 |
Correct |
15 ms |
61788 KB |
n=2000 |
80 |
Correct |
24 ms |
61788 KB |
n=2000 |
81 |
Correct |
25 ms |
61696 KB |
n=2000 |
82 |
Correct |
15 ms |
61900 KB |
n=2000 |
83 |
Correct |
25 ms |
61788 KB |
n=2000 |
84 |
Correct |
17 ms |
61784 KB |
n=2000 |
85 |
Correct |
24 ms |
61788 KB |
n=2000 |
86 |
Correct |
23 ms |
61784 KB |
n=2000 |
87 |
Correct |
17 ms |
61788 KB |
n=2000 |
88 |
Correct |
50 ms |
61784 KB |
n=2000 |
89 |
Correct |
53 ms |
61784 KB |
n=2000 |
90 |
Correct |
37 ms |
61940 KB |
n=2000 |
91 |
Correct |
18 ms |
61788 KB |
n=2000 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
61528 KB |
n=5 |
2 |
Correct |
13 ms |
61528 KB |
n=100 |
3 |
Correct |
14 ms |
61528 KB |
n=100 |
4 |
Correct |
13 ms |
61532 KB |
n=100 |
5 |
Correct |
13 ms |
61532 KB |
n=100 |
6 |
Correct |
13 ms |
61564 KB |
n=100 |
7 |
Correct |
13 ms |
61532 KB |
n=100 |
8 |
Correct |
13 ms |
61544 KB |
n=100 |
9 |
Correct |
13 ms |
61528 KB |
n=100 |
10 |
Correct |
15 ms |
61516 KB |
n=100 |
11 |
Correct |
14 ms |
61528 KB |
n=100 |
12 |
Correct |
13 ms |
61528 KB |
n=100 |
13 |
Correct |
14 ms |
61528 KB |
n=100 |
14 |
Correct |
13 ms |
61644 KB |
n=100 |
15 |
Correct |
13 ms |
61532 KB |
n=100 |
16 |
Correct |
13 ms |
61528 KB |
n=100 |
17 |
Correct |
13 ms |
61528 KB |
n=100 |
18 |
Correct |
13 ms |
61532 KB |
n=100 |
19 |
Correct |
13 ms |
61532 KB |
n=100 |
20 |
Correct |
13 ms |
61528 KB |
n=100 |
21 |
Correct |
13 ms |
61532 KB |
n=100 |
22 |
Correct |
14 ms |
61532 KB |
n=100 |
23 |
Correct |
13 ms |
61616 KB |
n=100 |
24 |
Correct |
14 ms |
61532 KB |
n=100 |
25 |
Correct |
13 ms |
61532 KB |
n=100 |
26 |
Correct |
14 ms |
61528 KB |
n=12 |
27 |
Correct |
13 ms |
61532 KB |
n=100 |
28 |
Correct |
14 ms |
61528 KB |
n=500 |
29 |
Correct |
14 ms |
61532 KB |
n=500 |
30 |
Correct |
14 ms |
61528 KB |
n=500 |
31 |
Correct |
14 ms |
61532 KB |
n=500 |
32 |
Correct |
13 ms |
61528 KB |
n=500 |
33 |
Correct |
14 ms |
61704 KB |
n=500 |
34 |
Correct |
13 ms |
61532 KB |
n=500 |
35 |
Correct |
13 ms |
61532 KB |
n=500 |
36 |
Correct |
15 ms |
61652 KB |
n=500 |
37 |
Correct |
15 ms |
61528 KB |
n=500 |
38 |
Correct |
15 ms |
61528 KB |
n=500 |
39 |
Correct |
13 ms |
61532 KB |
n=500 |
40 |
Correct |
14 ms |
61532 KB |
n=500 |
41 |
Correct |
16 ms |
61528 KB |
n=500 |
42 |
Correct |
15 ms |
61532 KB |
n=500 |
43 |
Correct |
16 ms |
61656 KB |
n=500 |
44 |
Correct |
15 ms |
61528 KB |
n=500 |
45 |
Correct |
14 ms |
61668 KB |
n=500 |
46 |
Correct |
14 ms |
61528 KB |
n=500 |
47 |
Correct |
14 ms |
61528 KB |
n=500 |
48 |
Correct |
13 ms |
61532 KB |
n=500 |
49 |
Correct |
14 ms |
61528 KB |
n=500 |
50 |
Correct |
14 ms |
61528 KB |
n=500 |
51 |
Correct |
14 ms |
61528 KB |
n=500 |
52 |
Correct |
14 ms |
61532 KB |
n=500 |
53 |
Correct |
16 ms |
61528 KB |
n=500 |
54 |
Correct |
15 ms |
61676 KB |
n=500 |
55 |
Correct |
13 ms |
61532 KB |
n=278 |
56 |
Correct |
15 ms |
61532 KB |
n=500 |
57 |
Correct |
17 ms |
61532 KB |
n=500 |
58 |
Correct |
14 ms |
61580 KB |
n=500 |
59 |
Correct |
14 ms |
61784 KB |
n=2000 |
60 |
Correct |
25 ms |
61932 KB |
n=2000 |
61 |
Correct |
27 ms |
61784 KB |
n=2000 |
62 |
Correct |
28 ms |
61836 KB |
n=2000 |
63 |
Correct |
17 ms |
61788 KB |
n=2000 |
64 |
Correct |
25 ms |
61788 KB |
n=2000 |
65 |
Correct |
16 ms |
61884 KB |
n=2000 |
66 |
Correct |
27 ms |
61788 KB |
n=2000 |
67 |
Correct |
15 ms |
61764 KB |
n=2000 |
68 |
Correct |
27 ms |
61784 KB |
n=2000 |
69 |
Correct |
32 ms |
61892 KB |
n=2000 |
70 |
Correct |
32 ms |
61788 KB |
n=2000 |
71 |
Correct |
32 ms |
61880 KB |
n=2000 |
72 |
Correct |
28 ms |
61788 KB |
n=2000 |
73 |
Correct |
23 ms |
61788 KB |
n=2000 |
74 |
Correct |
16 ms |
61824 KB |
n=1844 |
75 |
Correct |
25 ms |
61788 KB |
n=2000 |
76 |
Correct |
34 ms |
61784 KB |
n=2000 |
77 |
Correct |
32 ms |
61788 KB |
n=2000 |
78 |
Correct |
36 ms |
61788 KB |
n=2000 |
79 |
Correct |
15 ms |
61788 KB |
n=2000 |
80 |
Correct |
24 ms |
61788 KB |
n=2000 |
81 |
Correct |
25 ms |
61696 KB |
n=2000 |
82 |
Correct |
15 ms |
61900 KB |
n=2000 |
83 |
Correct |
25 ms |
61788 KB |
n=2000 |
84 |
Correct |
17 ms |
61784 KB |
n=2000 |
85 |
Correct |
24 ms |
61788 KB |
n=2000 |
86 |
Correct |
23 ms |
61784 KB |
n=2000 |
87 |
Correct |
17 ms |
61788 KB |
n=2000 |
88 |
Correct |
50 ms |
61784 KB |
n=2000 |
89 |
Correct |
53 ms |
61784 KB |
n=2000 |
90 |
Correct |
37 ms |
61940 KB |
n=2000 |
91 |
Correct |
18 ms |
61788 KB |
n=2000 |
92 |
Correct |
583 ms |
88780 KB |
n=200000 |
93 |
Execution timed out |
4013 ms |
89176 KB |
Time limit exceeded |
94 |
Halted |
0 ms |
0 KB |
- |