#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define ll long long
#define ld long double
#define pii pair<int, int>
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(),x.rend()
#define prc(n) fixed << setprecision(n)
#define fastios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pi acos(-1);
const int inf = 1e9+7;
const int N = 2e5+5;
int n, m, q, a[N], tin[N], tout[N], l, t, up[N][32];
vector<int>edges[N];
set<int>ar[N];
set<int>lc[N];
void dfs(int u, int p){
tin[u] = ++t;
up[u][0] = p;
for(int i=1; i<=l; i++){
up[u][i] = up[up[u][i-1]][i-1];
}
for(auto x:edges[u]){
if(x == p) continue;
dfs(x, u);
}
tout[u] = ++t;
}
bool upper(int a, int b){
return tin[a] <= tin[b] && tout[a] >= tout[b];
}
int lca(int a, int b){
if(upper(a, b)) return a;
if(upper(b, a)) return b;
for(int i=l; i>=0; i--){
if(!upper(up[a][i], b)) a = up[a][i];
}
return up[a][0];
}
void solve(){
cin>>n>>m>>q;
for(int i=1;i<n;i++){
int a, b;
cin>>a>>b;
edges[a].pb(b);
edges[b].pb(a);
}
l = 1;
while((1<<l) <= n) l++;
dfs(1, 1);
for(int i=1;i<=m;i++){
cin>>a[i];
ar[a[i]].insert(i);
}
for(int i=1;i<m;i++){
lc[lca(a[i], a[i+1])].insert(i);
}
while(q--){
int t;
cin>>t;
if(t == 1){
int pos, val;
cin>>pos>>val;
ar[a[pos]].erase(pos);
if(pos > 1) lc[lca(a[pos], a[pos-1])].erase(pos-1);
if(pos < m) lc[lca(a[pos+1], a[pos])].erase(pos);
a[pos] = val;
if(pos > 1) lc[lca(a[pos], a[pos-1])].insert(pos-1);
if(pos < m) lc[lca(a[pos+1], a[pos])].insert(pos);
ar[a[pos]].insert(pos);
}
else{
int l, r, val, la = -1, ra = -1;;
cin>>l>>r>>val;
auto it = ar[val].lb(l);
if(it != ar[val].end()) if(*it <= r) la = ra = *it;
it = lc[val].lb(l);
if(it != lc[val].end()) if(*it < r) la = *it, ra = *it+1;
cout<<la<<" "<<ra<<"\n";
}
}
return;
}
int main(){
fastios
int t = 1;
//cin>>t;
while(t--) solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
23788 KB |
n=5 |
2 |
Correct |
16 ms |
23916 KB |
n=100 |
3 |
Correct |
16 ms |
23916 KB |
n=100 |
4 |
Correct |
16 ms |
23916 KB |
n=100 |
5 |
Correct |
17 ms |
23916 KB |
n=100 |
6 |
Correct |
16 ms |
23916 KB |
n=100 |
7 |
Correct |
16 ms |
23916 KB |
n=100 |
8 |
Correct |
16 ms |
23916 KB |
n=100 |
9 |
Correct |
16 ms |
23916 KB |
n=100 |
10 |
Correct |
16 ms |
23916 KB |
n=100 |
11 |
Correct |
16 ms |
23916 KB |
n=100 |
12 |
Correct |
16 ms |
23916 KB |
n=100 |
13 |
Correct |
16 ms |
23916 KB |
n=100 |
14 |
Correct |
16 ms |
23916 KB |
n=100 |
15 |
Correct |
16 ms |
23916 KB |
n=100 |
16 |
Correct |
16 ms |
23916 KB |
n=100 |
17 |
Correct |
17 ms |
23916 KB |
n=100 |
18 |
Correct |
16 ms |
23916 KB |
n=100 |
19 |
Correct |
16 ms |
23916 KB |
n=100 |
20 |
Correct |
16 ms |
23916 KB |
n=100 |
21 |
Correct |
16 ms |
23916 KB |
n=100 |
22 |
Correct |
16 ms |
23916 KB |
n=100 |
23 |
Correct |
18 ms |
23916 KB |
n=100 |
24 |
Correct |
16 ms |
23916 KB |
n=100 |
25 |
Correct |
16 ms |
23916 KB |
n=100 |
26 |
Correct |
16 ms |
23788 KB |
n=12 |
27 |
Correct |
16 ms |
23916 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
23788 KB |
n=5 |
2 |
Correct |
16 ms |
23916 KB |
n=100 |
3 |
Correct |
16 ms |
23916 KB |
n=100 |
4 |
Correct |
16 ms |
23916 KB |
n=100 |
5 |
Correct |
17 ms |
23916 KB |
n=100 |
6 |
Correct |
16 ms |
23916 KB |
n=100 |
7 |
Correct |
16 ms |
23916 KB |
n=100 |
8 |
Correct |
16 ms |
23916 KB |
n=100 |
9 |
Correct |
16 ms |
23916 KB |
n=100 |
10 |
Correct |
16 ms |
23916 KB |
n=100 |
11 |
Correct |
16 ms |
23916 KB |
n=100 |
12 |
Correct |
16 ms |
23916 KB |
n=100 |
13 |
Correct |
16 ms |
23916 KB |
n=100 |
14 |
Correct |
16 ms |
23916 KB |
n=100 |
15 |
Correct |
16 ms |
23916 KB |
n=100 |
16 |
Correct |
16 ms |
23916 KB |
n=100 |
17 |
Correct |
17 ms |
23916 KB |
n=100 |
18 |
Correct |
16 ms |
23916 KB |
n=100 |
19 |
Correct |
16 ms |
23916 KB |
n=100 |
20 |
Correct |
16 ms |
23916 KB |
n=100 |
21 |
Correct |
16 ms |
23916 KB |
n=100 |
22 |
Correct |
16 ms |
23916 KB |
n=100 |
23 |
Correct |
18 ms |
23916 KB |
n=100 |
24 |
Correct |
16 ms |
23916 KB |
n=100 |
25 |
Correct |
16 ms |
23916 KB |
n=100 |
26 |
Correct |
16 ms |
23788 KB |
n=12 |
27 |
Correct |
16 ms |
23916 KB |
n=100 |
28 |
Correct |
17 ms |
23916 KB |
n=500 |
29 |
Correct |
18 ms |
24172 KB |
n=500 |
30 |
Correct |
17 ms |
23916 KB |
n=500 |
31 |
Correct |
17 ms |
24044 KB |
n=500 |
32 |
Correct |
17 ms |
23916 KB |
n=500 |
33 |
Correct |
18 ms |
23916 KB |
n=500 |
34 |
Correct |
17 ms |
23916 KB |
n=500 |
35 |
Correct |
17 ms |
24044 KB |
n=500 |
36 |
Correct |
18 ms |
23916 KB |
n=500 |
37 |
Correct |
17 ms |
23916 KB |
n=500 |
38 |
Correct |
18 ms |
23916 KB |
n=500 |
39 |
Correct |
17 ms |
23916 KB |
n=500 |
40 |
Correct |
17 ms |
23916 KB |
n=500 |
41 |
Correct |
18 ms |
23916 KB |
n=500 |
42 |
Correct |
17 ms |
23916 KB |
n=500 |
43 |
Correct |
17 ms |
23916 KB |
n=500 |
44 |
Correct |
17 ms |
23916 KB |
n=500 |
45 |
Correct |
17 ms |
23916 KB |
n=500 |
46 |
Correct |
17 ms |
24044 KB |
n=500 |
47 |
Correct |
17 ms |
24044 KB |
n=500 |
48 |
Correct |
17 ms |
23916 KB |
n=500 |
49 |
Correct |
18 ms |
24044 KB |
n=500 |
50 |
Correct |
17 ms |
23916 KB |
n=500 |
51 |
Correct |
17 ms |
23916 KB |
n=500 |
52 |
Correct |
18 ms |
24044 KB |
n=500 |
53 |
Correct |
17 ms |
23916 KB |
n=500 |
54 |
Correct |
17 ms |
24044 KB |
n=500 |
55 |
Correct |
17 ms |
24044 KB |
n=278 |
56 |
Correct |
17 ms |
24044 KB |
n=500 |
57 |
Correct |
17 ms |
24044 KB |
n=500 |
58 |
Correct |
17 ms |
23916 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
23788 KB |
n=5 |
2 |
Correct |
16 ms |
23916 KB |
n=100 |
3 |
Correct |
16 ms |
23916 KB |
n=100 |
4 |
Correct |
16 ms |
23916 KB |
n=100 |
5 |
Correct |
17 ms |
23916 KB |
n=100 |
6 |
Correct |
16 ms |
23916 KB |
n=100 |
7 |
Correct |
16 ms |
23916 KB |
n=100 |
8 |
Correct |
16 ms |
23916 KB |
n=100 |
9 |
Correct |
16 ms |
23916 KB |
n=100 |
10 |
Correct |
16 ms |
23916 KB |
n=100 |
11 |
Correct |
16 ms |
23916 KB |
n=100 |
12 |
Correct |
16 ms |
23916 KB |
n=100 |
13 |
Correct |
16 ms |
23916 KB |
n=100 |
14 |
Correct |
16 ms |
23916 KB |
n=100 |
15 |
Correct |
16 ms |
23916 KB |
n=100 |
16 |
Correct |
16 ms |
23916 KB |
n=100 |
17 |
Correct |
17 ms |
23916 KB |
n=100 |
18 |
Correct |
16 ms |
23916 KB |
n=100 |
19 |
Correct |
16 ms |
23916 KB |
n=100 |
20 |
Correct |
16 ms |
23916 KB |
n=100 |
21 |
Correct |
16 ms |
23916 KB |
n=100 |
22 |
Correct |
16 ms |
23916 KB |
n=100 |
23 |
Correct |
18 ms |
23916 KB |
n=100 |
24 |
Correct |
16 ms |
23916 KB |
n=100 |
25 |
Correct |
16 ms |
23916 KB |
n=100 |
26 |
Correct |
16 ms |
23788 KB |
n=12 |
27 |
Correct |
16 ms |
23916 KB |
n=100 |
28 |
Correct |
17 ms |
23916 KB |
n=500 |
29 |
Correct |
18 ms |
24172 KB |
n=500 |
30 |
Correct |
17 ms |
23916 KB |
n=500 |
31 |
Correct |
17 ms |
24044 KB |
n=500 |
32 |
Correct |
17 ms |
23916 KB |
n=500 |
33 |
Correct |
18 ms |
23916 KB |
n=500 |
34 |
Correct |
17 ms |
23916 KB |
n=500 |
35 |
Correct |
17 ms |
24044 KB |
n=500 |
36 |
Correct |
18 ms |
23916 KB |
n=500 |
37 |
Correct |
17 ms |
23916 KB |
n=500 |
38 |
Correct |
18 ms |
23916 KB |
n=500 |
39 |
Correct |
17 ms |
23916 KB |
n=500 |
40 |
Correct |
17 ms |
23916 KB |
n=500 |
41 |
Correct |
18 ms |
23916 KB |
n=500 |
42 |
Correct |
17 ms |
23916 KB |
n=500 |
43 |
Correct |
17 ms |
23916 KB |
n=500 |
44 |
Correct |
17 ms |
23916 KB |
n=500 |
45 |
Correct |
17 ms |
23916 KB |
n=500 |
46 |
Correct |
17 ms |
24044 KB |
n=500 |
47 |
Correct |
17 ms |
24044 KB |
n=500 |
48 |
Correct |
17 ms |
23916 KB |
n=500 |
49 |
Correct |
18 ms |
24044 KB |
n=500 |
50 |
Correct |
17 ms |
23916 KB |
n=500 |
51 |
Correct |
17 ms |
23916 KB |
n=500 |
52 |
Correct |
18 ms |
24044 KB |
n=500 |
53 |
Correct |
17 ms |
23916 KB |
n=500 |
54 |
Correct |
17 ms |
24044 KB |
n=500 |
55 |
Correct |
17 ms |
24044 KB |
n=278 |
56 |
Correct |
17 ms |
24044 KB |
n=500 |
57 |
Correct |
17 ms |
24044 KB |
n=500 |
58 |
Correct |
17 ms |
23916 KB |
n=500 |
59 |
Correct |
20 ms |
24428 KB |
n=2000 |
60 |
Correct |
19 ms |
24428 KB |
n=2000 |
61 |
Correct |
20 ms |
24556 KB |
n=2000 |
62 |
Correct |
20 ms |
24428 KB |
n=2000 |
63 |
Correct |
20 ms |
24428 KB |
n=2000 |
64 |
Correct |
20 ms |
24428 KB |
n=2000 |
65 |
Correct |
20 ms |
24428 KB |
n=2000 |
66 |
Correct |
19 ms |
24428 KB |
n=2000 |
67 |
Correct |
20 ms |
24428 KB |
n=2000 |
68 |
Correct |
20 ms |
24428 KB |
n=2000 |
69 |
Correct |
19 ms |
24428 KB |
n=2000 |
70 |
Correct |
19 ms |
24428 KB |
n=2000 |
71 |
Correct |
20 ms |
24556 KB |
n=2000 |
72 |
Correct |
19 ms |
24428 KB |
n=2000 |
73 |
Correct |
19 ms |
24428 KB |
n=2000 |
74 |
Correct |
19 ms |
24300 KB |
n=1844 |
75 |
Correct |
19 ms |
24428 KB |
n=2000 |
76 |
Correct |
20 ms |
24428 KB |
n=2000 |
77 |
Correct |
20 ms |
24428 KB |
n=2000 |
78 |
Correct |
20 ms |
24428 KB |
n=2000 |
79 |
Correct |
20 ms |
24428 KB |
n=2000 |
80 |
Correct |
19 ms |
24428 KB |
n=2000 |
81 |
Correct |
20 ms |
24428 KB |
n=2000 |
82 |
Correct |
21 ms |
24428 KB |
n=2000 |
83 |
Correct |
20 ms |
24428 KB |
n=2000 |
84 |
Correct |
20 ms |
24428 KB |
n=2000 |
85 |
Correct |
20 ms |
24428 KB |
n=2000 |
86 |
Correct |
20 ms |
24428 KB |
n=2000 |
87 |
Correct |
20 ms |
24428 KB |
n=2000 |
88 |
Correct |
20 ms |
24428 KB |
n=2000 |
89 |
Correct |
19 ms |
24428 KB |
n=2000 |
90 |
Correct |
19 ms |
24428 KB |
n=2000 |
91 |
Correct |
19 ms |
24428 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
23788 KB |
n=5 |
2 |
Correct |
16 ms |
23916 KB |
n=100 |
3 |
Correct |
16 ms |
23916 KB |
n=100 |
4 |
Correct |
16 ms |
23916 KB |
n=100 |
5 |
Correct |
17 ms |
23916 KB |
n=100 |
6 |
Correct |
16 ms |
23916 KB |
n=100 |
7 |
Correct |
16 ms |
23916 KB |
n=100 |
8 |
Correct |
16 ms |
23916 KB |
n=100 |
9 |
Correct |
16 ms |
23916 KB |
n=100 |
10 |
Correct |
16 ms |
23916 KB |
n=100 |
11 |
Correct |
16 ms |
23916 KB |
n=100 |
12 |
Correct |
16 ms |
23916 KB |
n=100 |
13 |
Correct |
16 ms |
23916 KB |
n=100 |
14 |
Correct |
16 ms |
23916 KB |
n=100 |
15 |
Correct |
16 ms |
23916 KB |
n=100 |
16 |
Correct |
16 ms |
23916 KB |
n=100 |
17 |
Correct |
17 ms |
23916 KB |
n=100 |
18 |
Correct |
16 ms |
23916 KB |
n=100 |
19 |
Correct |
16 ms |
23916 KB |
n=100 |
20 |
Correct |
16 ms |
23916 KB |
n=100 |
21 |
Correct |
16 ms |
23916 KB |
n=100 |
22 |
Correct |
16 ms |
23916 KB |
n=100 |
23 |
Correct |
18 ms |
23916 KB |
n=100 |
24 |
Correct |
16 ms |
23916 KB |
n=100 |
25 |
Correct |
16 ms |
23916 KB |
n=100 |
26 |
Correct |
16 ms |
23788 KB |
n=12 |
27 |
Correct |
16 ms |
23916 KB |
n=100 |
28 |
Correct |
17 ms |
23916 KB |
n=500 |
29 |
Correct |
18 ms |
24172 KB |
n=500 |
30 |
Correct |
17 ms |
23916 KB |
n=500 |
31 |
Correct |
17 ms |
24044 KB |
n=500 |
32 |
Correct |
17 ms |
23916 KB |
n=500 |
33 |
Correct |
18 ms |
23916 KB |
n=500 |
34 |
Correct |
17 ms |
23916 KB |
n=500 |
35 |
Correct |
17 ms |
24044 KB |
n=500 |
36 |
Correct |
18 ms |
23916 KB |
n=500 |
37 |
Correct |
17 ms |
23916 KB |
n=500 |
38 |
Correct |
18 ms |
23916 KB |
n=500 |
39 |
Correct |
17 ms |
23916 KB |
n=500 |
40 |
Correct |
17 ms |
23916 KB |
n=500 |
41 |
Correct |
18 ms |
23916 KB |
n=500 |
42 |
Correct |
17 ms |
23916 KB |
n=500 |
43 |
Correct |
17 ms |
23916 KB |
n=500 |
44 |
Correct |
17 ms |
23916 KB |
n=500 |
45 |
Correct |
17 ms |
23916 KB |
n=500 |
46 |
Correct |
17 ms |
24044 KB |
n=500 |
47 |
Correct |
17 ms |
24044 KB |
n=500 |
48 |
Correct |
17 ms |
23916 KB |
n=500 |
49 |
Correct |
18 ms |
24044 KB |
n=500 |
50 |
Correct |
17 ms |
23916 KB |
n=500 |
51 |
Correct |
17 ms |
23916 KB |
n=500 |
52 |
Correct |
18 ms |
24044 KB |
n=500 |
53 |
Correct |
17 ms |
23916 KB |
n=500 |
54 |
Correct |
17 ms |
24044 KB |
n=500 |
55 |
Correct |
17 ms |
24044 KB |
n=278 |
56 |
Correct |
17 ms |
24044 KB |
n=500 |
57 |
Correct |
17 ms |
24044 KB |
n=500 |
58 |
Correct |
17 ms |
23916 KB |
n=500 |
59 |
Correct |
20 ms |
24428 KB |
n=2000 |
60 |
Correct |
19 ms |
24428 KB |
n=2000 |
61 |
Correct |
20 ms |
24556 KB |
n=2000 |
62 |
Correct |
20 ms |
24428 KB |
n=2000 |
63 |
Correct |
20 ms |
24428 KB |
n=2000 |
64 |
Correct |
20 ms |
24428 KB |
n=2000 |
65 |
Correct |
20 ms |
24428 KB |
n=2000 |
66 |
Correct |
19 ms |
24428 KB |
n=2000 |
67 |
Correct |
20 ms |
24428 KB |
n=2000 |
68 |
Correct |
20 ms |
24428 KB |
n=2000 |
69 |
Correct |
19 ms |
24428 KB |
n=2000 |
70 |
Correct |
19 ms |
24428 KB |
n=2000 |
71 |
Correct |
20 ms |
24556 KB |
n=2000 |
72 |
Correct |
19 ms |
24428 KB |
n=2000 |
73 |
Correct |
19 ms |
24428 KB |
n=2000 |
74 |
Correct |
19 ms |
24300 KB |
n=1844 |
75 |
Correct |
19 ms |
24428 KB |
n=2000 |
76 |
Correct |
20 ms |
24428 KB |
n=2000 |
77 |
Correct |
20 ms |
24428 KB |
n=2000 |
78 |
Correct |
20 ms |
24428 KB |
n=2000 |
79 |
Correct |
20 ms |
24428 KB |
n=2000 |
80 |
Correct |
19 ms |
24428 KB |
n=2000 |
81 |
Correct |
20 ms |
24428 KB |
n=2000 |
82 |
Correct |
21 ms |
24428 KB |
n=2000 |
83 |
Correct |
20 ms |
24428 KB |
n=2000 |
84 |
Correct |
20 ms |
24428 KB |
n=2000 |
85 |
Correct |
20 ms |
24428 KB |
n=2000 |
86 |
Correct |
20 ms |
24428 KB |
n=2000 |
87 |
Correct |
20 ms |
24428 KB |
n=2000 |
88 |
Correct |
20 ms |
24428 KB |
n=2000 |
89 |
Correct |
19 ms |
24428 KB |
n=2000 |
90 |
Correct |
19 ms |
24428 KB |
n=2000 |
91 |
Correct |
19 ms |
24428 KB |
n=2000 |
92 |
Correct |
857 ms |
78520 KB |
n=200000 |
93 |
Correct |
952 ms |
82284 KB |
n=200000 |
94 |
Correct |
714 ms |
85356 KB |
n=200000 |
95 |
Correct |
825 ms |
78304 KB |
n=200000 |
96 |
Correct |
831 ms |
78524 KB |
n=200000 |
97 |
Correct |
1038 ms |
81260 KB |
n=200000 |
98 |
Correct |
834 ms |
78312 KB |
n=200000 |
99 |
Correct |
1022 ms |
77676 KB |
n=200000 |
100 |
Correct |
843 ms |
78184 KB |
n=200000 |
101 |
Correct |
653 ms |
86764 KB |
n=200000 |
102 |
Correct |
501 ms |
79212 KB |
n=200000 |
103 |
Correct |
497 ms |
79212 KB |
n=200000 |
104 |
Correct |
498 ms |
79080 KB |
n=200000 |
105 |
Correct |
511 ms |
78804 KB |
n=200000 |
106 |
Correct |
519 ms |
79024 KB |
n=200000 |
107 |
Correct |
503 ms |
78828 KB |
n=200000 |
108 |
Correct |
922 ms |
77968 KB |
n=200000 |
109 |
Correct |
917 ms |
77932 KB |
n=200000 |
110 |
Correct |
908 ms |
78060 KB |
n=200000 |
111 |
Correct |
890 ms |
78132 KB |
n=200000 |
112 |
Correct |
690 ms |
85612 KB |
n=200000 |
113 |
Correct |
1010 ms |
81132 KB |
n=200000 |
114 |
Correct |
891 ms |
78176 KB |
n=200000 |
115 |
Correct |
1280 ms |
78956 KB |
n=200000 |
116 |
Correct |
789 ms |
78048 KB |
n=200000 |
117 |
Correct |
655 ms |
86124 KB |
n=200000 |
118 |
Correct |
1112 ms |
80108 KB |
n=200000 |
119 |
Correct |
778 ms |
77920 KB |
n=200000 |
120 |
Correct |
593 ms |
86380 KB |
n=200000 |
121 |
Correct |
597 ms |
86508 KB |
n=200000 |
122 |
Correct |
601 ms |
86764 KB |
n=200000 |
123 |
Correct |
536 ms |
78572 KB |
n=200000 |
124 |
Correct |
202 ms |
38204 KB |
n=25264 |