#include<bits/stdc++.h>
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
*/
using namespace std;
#pragma GCC optimize ("unroll-loops,Ofast,O3")
#pragma GCC target("avx,avx2,fma")
#define F first
#define S second
#define sz(x) (int)x.size()
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define NFS ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ;
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef long long ll;
const int E = 1e6+777;
const long long inf = 1e18+777;
const int N = 2e5+77;
const int MOD = 1e9+7;
const int LG = 18;
int n, m, que, a[N], timer;
int tin[N], tout[N], up[N][LG+2];
vector<int> g[N];
void dfs(int v, int p){
tin[v] = ++timer;
up[v][0] = p;
for(int i = 1; i <= LG; ++i){
up[v][i] = up[up[v][i-1]][i-1];
}
for(int to : g[v]){
if(to != p){
dfs(to, v);
}
}
tout[v] = timer;
}
bool upper(int v, int u){
return tin[v] <= tin[u] && tout[u] <= tout[v];
}
int lca(int v, int u){
if(upper(v, u)) return v;
if(upper(u, v)) return u;
for(int i = LG; i >= 0; --i){
if(!upper(up[v][i], u)){
v = up[v][i];
}
}
return up[v][0];
}
inline void update(int pos, int v){
a[pos] = v;
}
inline pair<int,int> get(int L, int R, int v){
for(int i = L; i <= R; ++i){
if(i + 1 <= R && lca(a[i],a[i+1]) == v){
return {i, i+1};
}else if(a[i] == v){
return {i, i};
}
}
return {-1, -1};
}
int main(){NFS;
cin >> n >> m >> que;
for(int i = 1, u, v; i < n; ++i){
cin >> u >> v;
g[u].pb(v);
g[v].pb(u);
}
dfs(1, 1);
for(int i = 1; i <= m; ++i){
cin >> a[i];
}
for(int type,l,r,v; que--;){
cin >> type;
if(type == 1){
cin >> l >> v;
update(l, v);
}else{
cin >> l >> r >> v;
pair<int,int> res = get(l, r, v);
cout << res.F << ' ' << res.S << '\n';
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
n=5 |
2 |
Correct |
3 ms |
4940 KB |
n=100 |
3 |
Correct |
3 ms |
4940 KB |
n=100 |
4 |
Correct |
3 ms |
4940 KB |
n=100 |
5 |
Correct |
3 ms |
4940 KB |
n=100 |
6 |
Correct |
3 ms |
4940 KB |
n=100 |
7 |
Correct |
3 ms |
4940 KB |
n=100 |
8 |
Correct |
4 ms |
4940 KB |
n=100 |
9 |
Correct |
4 ms |
4940 KB |
n=100 |
10 |
Correct |
4 ms |
4940 KB |
n=100 |
11 |
Correct |
3 ms |
4940 KB |
n=100 |
12 |
Correct |
3 ms |
4940 KB |
n=100 |
13 |
Correct |
3 ms |
4940 KB |
n=100 |
14 |
Correct |
2 ms |
4940 KB |
n=100 |
15 |
Correct |
3 ms |
4940 KB |
n=100 |
16 |
Correct |
3 ms |
4940 KB |
n=100 |
17 |
Correct |
3 ms |
4940 KB |
n=100 |
18 |
Correct |
3 ms |
5068 KB |
n=100 |
19 |
Correct |
3 ms |
4940 KB |
n=100 |
20 |
Correct |
3 ms |
4940 KB |
n=100 |
21 |
Correct |
3 ms |
4940 KB |
n=100 |
22 |
Correct |
3 ms |
4940 KB |
n=100 |
23 |
Correct |
3 ms |
4940 KB |
n=100 |
24 |
Correct |
3 ms |
4940 KB |
n=100 |
25 |
Correct |
3 ms |
4940 KB |
n=100 |
26 |
Correct |
2 ms |
4940 KB |
n=12 |
27 |
Correct |
3 ms |
4940 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
n=5 |
2 |
Correct |
3 ms |
4940 KB |
n=100 |
3 |
Correct |
3 ms |
4940 KB |
n=100 |
4 |
Correct |
3 ms |
4940 KB |
n=100 |
5 |
Correct |
3 ms |
4940 KB |
n=100 |
6 |
Correct |
3 ms |
4940 KB |
n=100 |
7 |
Correct |
3 ms |
4940 KB |
n=100 |
8 |
Correct |
4 ms |
4940 KB |
n=100 |
9 |
Correct |
4 ms |
4940 KB |
n=100 |
10 |
Correct |
4 ms |
4940 KB |
n=100 |
11 |
Correct |
3 ms |
4940 KB |
n=100 |
12 |
Correct |
3 ms |
4940 KB |
n=100 |
13 |
Correct |
3 ms |
4940 KB |
n=100 |
14 |
Correct |
2 ms |
4940 KB |
n=100 |
15 |
Correct |
3 ms |
4940 KB |
n=100 |
16 |
Correct |
3 ms |
4940 KB |
n=100 |
17 |
Correct |
3 ms |
4940 KB |
n=100 |
18 |
Correct |
3 ms |
5068 KB |
n=100 |
19 |
Correct |
3 ms |
4940 KB |
n=100 |
20 |
Correct |
3 ms |
4940 KB |
n=100 |
21 |
Correct |
3 ms |
4940 KB |
n=100 |
22 |
Correct |
3 ms |
4940 KB |
n=100 |
23 |
Correct |
3 ms |
4940 KB |
n=100 |
24 |
Correct |
3 ms |
4940 KB |
n=100 |
25 |
Correct |
3 ms |
4940 KB |
n=100 |
26 |
Correct |
2 ms |
4940 KB |
n=12 |
27 |
Correct |
3 ms |
4940 KB |
n=100 |
28 |
Correct |
4 ms |
5068 KB |
n=500 |
29 |
Correct |
4 ms |
5068 KB |
n=500 |
30 |
Correct |
4 ms |
5068 KB |
n=500 |
31 |
Correct |
4 ms |
5068 KB |
n=500 |
32 |
Correct |
4 ms |
5068 KB |
n=500 |
33 |
Correct |
6 ms |
5104 KB |
n=500 |
34 |
Correct |
4 ms |
5068 KB |
n=500 |
35 |
Correct |
3 ms |
5068 KB |
n=500 |
36 |
Correct |
19 ms |
5068 KB |
n=500 |
37 |
Correct |
16 ms |
5068 KB |
n=500 |
38 |
Correct |
17 ms |
5092 KB |
n=500 |
39 |
Correct |
13 ms |
5100 KB |
n=500 |
40 |
Correct |
10 ms |
5068 KB |
n=500 |
41 |
Correct |
10 ms |
5096 KB |
n=500 |
42 |
Correct |
11 ms |
5100 KB |
n=500 |
43 |
Correct |
11 ms |
5096 KB |
n=500 |
44 |
Correct |
11 ms |
5096 KB |
n=500 |
45 |
Correct |
3 ms |
5068 KB |
n=500 |
46 |
Correct |
3 ms |
5068 KB |
n=500 |
47 |
Correct |
4 ms |
5068 KB |
n=500 |
48 |
Correct |
3 ms |
5068 KB |
n=500 |
49 |
Correct |
3 ms |
5068 KB |
n=500 |
50 |
Correct |
7 ms |
5068 KB |
n=500 |
51 |
Correct |
5 ms |
5068 KB |
n=500 |
52 |
Correct |
3 ms |
5068 KB |
n=500 |
53 |
Correct |
5 ms |
5068 KB |
n=500 |
54 |
Correct |
4 ms |
5068 KB |
n=500 |
55 |
Correct |
3 ms |
5068 KB |
n=278 |
56 |
Correct |
4 ms |
5068 KB |
n=500 |
57 |
Correct |
4 ms |
5068 KB |
n=500 |
58 |
Correct |
17 ms |
5068 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
n=5 |
2 |
Correct |
3 ms |
4940 KB |
n=100 |
3 |
Correct |
3 ms |
4940 KB |
n=100 |
4 |
Correct |
3 ms |
4940 KB |
n=100 |
5 |
Correct |
3 ms |
4940 KB |
n=100 |
6 |
Correct |
3 ms |
4940 KB |
n=100 |
7 |
Correct |
3 ms |
4940 KB |
n=100 |
8 |
Correct |
4 ms |
4940 KB |
n=100 |
9 |
Correct |
4 ms |
4940 KB |
n=100 |
10 |
Correct |
4 ms |
4940 KB |
n=100 |
11 |
Correct |
3 ms |
4940 KB |
n=100 |
12 |
Correct |
3 ms |
4940 KB |
n=100 |
13 |
Correct |
3 ms |
4940 KB |
n=100 |
14 |
Correct |
2 ms |
4940 KB |
n=100 |
15 |
Correct |
3 ms |
4940 KB |
n=100 |
16 |
Correct |
3 ms |
4940 KB |
n=100 |
17 |
Correct |
3 ms |
4940 KB |
n=100 |
18 |
Correct |
3 ms |
5068 KB |
n=100 |
19 |
Correct |
3 ms |
4940 KB |
n=100 |
20 |
Correct |
3 ms |
4940 KB |
n=100 |
21 |
Correct |
3 ms |
4940 KB |
n=100 |
22 |
Correct |
3 ms |
4940 KB |
n=100 |
23 |
Correct |
3 ms |
4940 KB |
n=100 |
24 |
Correct |
3 ms |
4940 KB |
n=100 |
25 |
Correct |
3 ms |
4940 KB |
n=100 |
26 |
Correct |
2 ms |
4940 KB |
n=12 |
27 |
Correct |
3 ms |
4940 KB |
n=100 |
28 |
Correct |
4 ms |
5068 KB |
n=500 |
29 |
Correct |
4 ms |
5068 KB |
n=500 |
30 |
Correct |
4 ms |
5068 KB |
n=500 |
31 |
Correct |
4 ms |
5068 KB |
n=500 |
32 |
Correct |
4 ms |
5068 KB |
n=500 |
33 |
Correct |
6 ms |
5104 KB |
n=500 |
34 |
Correct |
4 ms |
5068 KB |
n=500 |
35 |
Correct |
3 ms |
5068 KB |
n=500 |
36 |
Correct |
19 ms |
5068 KB |
n=500 |
37 |
Correct |
16 ms |
5068 KB |
n=500 |
38 |
Correct |
17 ms |
5092 KB |
n=500 |
39 |
Correct |
13 ms |
5100 KB |
n=500 |
40 |
Correct |
10 ms |
5068 KB |
n=500 |
41 |
Correct |
10 ms |
5096 KB |
n=500 |
42 |
Correct |
11 ms |
5100 KB |
n=500 |
43 |
Correct |
11 ms |
5096 KB |
n=500 |
44 |
Correct |
11 ms |
5096 KB |
n=500 |
45 |
Correct |
3 ms |
5068 KB |
n=500 |
46 |
Correct |
3 ms |
5068 KB |
n=500 |
47 |
Correct |
4 ms |
5068 KB |
n=500 |
48 |
Correct |
3 ms |
5068 KB |
n=500 |
49 |
Correct |
3 ms |
5068 KB |
n=500 |
50 |
Correct |
7 ms |
5068 KB |
n=500 |
51 |
Correct |
5 ms |
5068 KB |
n=500 |
52 |
Correct |
3 ms |
5068 KB |
n=500 |
53 |
Correct |
5 ms |
5068 KB |
n=500 |
54 |
Correct |
4 ms |
5068 KB |
n=500 |
55 |
Correct |
3 ms |
5068 KB |
n=278 |
56 |
Correct |
4 ms |
5068 KB |
n=500 |
57 |
Correct |
4 ms |
5068 KB |
n=500 |
58 |
Correct |
17 ms |
5068 KB |
n=500 |
59 |
Correct |
5 ms |
5196 KB |
n=2000 |
60 |
Correct |
6 ms |
5324 KB |
n=2000 |
61 |
Correct |
17 ms |
5324 KB |
n=2000 |
62 |
Correct |
19 ms |
5316 KB |
n=2000 |
63 |
Correct |
4 ms |
5196 KB |
n=2000 |
64 |
Correct |
21 ms |
5332 KB |
n=2000 |
65 |
Correct |
4 ms |
5196 KB |
n=2000 |
66 |
Correct |
17 ms |
5372 KB |
n=2000 |
67 |
Correct |
8 ms |
5284 KB |
n=2000 |
68 |
Correct |
22 ms |
5336 KB |
n=2000 |
69 |
Correct |
243 ms |
5404 KB |
n=2000 |
70 |
Correct |
246 ms |
5268 KB |
n=2000 |
71 |
Correct |
251 ms |
5264 KB |
n=2000 |
72 |
Correct |
120 ms |
5280 KB |
n=2000 |
73 |
Correct |
121 ms |
5268 KB |
n=2000 |
74 |
Correct |
5 ms |
5196 KB |
n=1844 |
75 |
Correct |
146 ms |
5280 KB |
n=2000 |
76 |
Correct |
118 ms |
5272 KB |
n=2000 |
77 |
Correct |
123 ms |
5264 KB |
n=2000 |
78 |
Correct |
126 ms |
5264 KB |
n=2000 |
79 |
Correct |
5 ms |
5288 KB |
n=2000 |
80 |
Correct |
11 ms |
5380 KB |
n=2000 |
81 |
Correct |
18 ms |
5332 KB |
n=2000 |
82 |
Correct |
4 ms |
5196 KB |
n=2000 |
83 |
Correct |
13 ms |
5368 KB |
n=2000 |
84 |
Correct |
69 ms |
5280 KB |
n=2000 |
85 |
Correct |
40 ms |
5196 KB |
n=2000 |
86 |
Correct |
53 ms |
5300 KB |
n=2000 |
87 |
Correct |
75 ms |
5284 KB |
n=2000 |
88 |
Correct |
21 ms |
5324 KB |
n=2000 |
89 |
Correct |
18 ms |
5404 KB |
n=2000 |
90 |
Correct |
11 ms |
5324 KB |
n=2000 |
91 |
Correct |
181 ms |
5268 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
n=5 |
2 |
Correct |
3 ms |
4940 KB |
n=100 |
3 |
Correct |
3 ms |
4940 KB |
n=100 |
4 |
Correct |
3 ms |
4940 KB |
n=100 |
5 |
Correct |
3 ms |
4940 KB |
n=100 |
6 |
Correct |
3 ms |
4940 KB |
n=100 |
7 |
Correct |
3 ms |
4940 KB |
n=100 |
8 |
Correct |
4 ms |
4940 KB |
n=100 |
9 |
Correct |
4 ms |
4940 KB |
n=100 |
10 |
Correct |
4 ms |
4940 KB |
n=100 |
11 |
Correct |
3 ms |
4940 KB |
n=100 |
12 |
Correct |
3 ms |
4940 KB |
n=100 |
13 |
Correct |
3 ms |
4940 KB |
n=100 |
14 |
Correct |
2 ms |
4940 KB |
n=100 |
15 |
Correct |
3 ms |
4940 KB |
n=100 |
16 |
Correct |
3 ms |
4940 KB |
n=100 |
17 |
Correct |
3 ms |
4940 KB |
n=100 |
18 |
Correct |
3 ms |
5068 KB |
n=100 |
19 |
Correct |
3 ms |
4940 KB |
n=100 |
20 |
Correct |
3 ms |
4940 KB |
n=100 |
21 |
Correct |
3 ms |
4940 KB |
n=100 |
22 |
Correct |
3 ms |
4940 KB |
n=100 |
23 |
Correct |
3 ms |
4940 KB |
n=100 |
24 |
Correct |
3 ms |
4940 KB |
n=100 |
25 |
Correct |
3 ms |
4940 KB |
n=100 |
26 |
Correct |
2 ms |
4940 KB |
n=12 |
27 |
Correct |
3 ms |
4940 KB |
n=100 |
28 |
Correct |
4 ms |
5068 KB |
n=500 |
29 |
Correct |
4 ms |
5068 KB |
n=500 |
30 |
Correct |
4 ms |
5068 KB |
n=500 |
31 |
Correct |
4 ms |
5068 KB |
n=500 |
32 |
Correct |
4 ms |
5068 KB |
n=500 |
33 |
Correct |
6 ms |
5104 KB |
n=500 |
34 |
Correct |
4 ms |
5068 KB |
n=500 |
35 |
Correct |
3 ms |
5068 KB |
n=500 |
36 |
Correct |
19 ms |
5068 KB |
n=500 |
37 |
Correct |
16 ms |
5068 KB |
n=500 |
38 |
Correct |
17 ms |
5092 KB |
n=500 |
39 |
Correct |
13 ms |
5100 KB |
n=500 |
40 |
Correct |
10 ms |
5068 KB |
n=500 |
41 |
Correct |
10 ms |
5096 KB |
n=500 |
42 |
Correct |
11 ms |
5100 KB |
n=500 |
43 |
Correct |
11 ms |
5096 KB |
n=500 |
44 |
Correct |
11 ms |
5096 KB |
n=500 |
45 |
Correct |
3 ms |
5068 KB |
n=500 |
46 |
Correct |
3 ms |
5068 KB |
n=500 |
47 |
Correct |
4 ms |
5068 KB |
n=500 |
48 |
Correct |
3 ms |
5068 KB |
n=500 |
49 |
Correct |
3 ms |
5068 KB |
n=500 |
50 |
Correct |
7 ms |
5068 KB |
n=500 |
51 |
Correct |
5 ms |
5068 KB |
n=500 |
52 |
Correct |
3 ms |
5068 KB |
n=500 |
53 |
Correct |
5 ms |
5068 KB |
n=500 |
54 |
Correct |
4 ms |
5068 KB |
n=500 |
55 |
Correct |
3 ms |
5068 KB |
n=278 |
56 |
Correct |
4 ms |
5068 KB |
n=500 |
57 |
Correct |
4 ms |
5068 KB |
n=500 |
58 |
Correct |
17 ms |
5068 KB |
n=500 |
59 |
Correct |
5 ms |
5196 KB |
n=2000 |
60 |
Correct |
6 ms |
5324 KB |
n=2000 |
61 |
Correct |
17 ms |
5324 KB |
n=2000 |
62 |
Correct |
19 ms |
5316 KB |
n=2000 |
63 |
Correct |
4 ms |
5196 KB |
n=2000 |
64 |
Correct |
21 ms |
5332 KB |
n=2000 |
65 |
Correct |
4 ms |
5196 KB |
n=2000 |
66 |
Correct |
17 ms |
5372 KB |
n=2000 |
67 |
Correct |
8 ms |
5284 KB |
n=2000 |
68 |
Correct |
22 ms |
5336 KB |
n=2000 |
69 |
Correct |
243 ms |
5404 KB |
n=2000 |
70 |
Correct |
246 ms |
5268 KB |
n=2000 |
71 |
Correct |
251 ms |
5264 KB |
n=2000 |
72 |
Correct |
120 ms |
5280 KB |
n=2000 |
73 |
Correct |
121 ms |
5268 KB |
n=2000 |
74 |
Correct |
5 ms |
5196 KB |
n=1844 |
75 |
Correct |
146 ms |
5280 KB |
n=2000 |
76 |
Correct |
118 ms |
5272 KB |
n=2000 |
77 |
Correct |
123 ms |
5264 KB |
n=2000 |
78 |
Correct |
126 ms |
5264 KB |
n=2000 |
79 |
Correct |
5 ms |
5288 KB |
n=2000 |
80 |
Correct |
11 ms |
5380 KB |
n=2000 |
81 |
Correct |
18 ms |
5332 KB |
n=2000 |
82 |
Correct |
4 ms |
5196 KB |
n=2000 |
83 |
Correct |
13 ms |
5368 KB |
n=2000 |
84 |
Correct |
69 ms |
5280 KB |
n=2000 |
85 |
Correct |
40 ms |
5196 KB |
n=2000 |
86 |
Correct |
53 ms |
5300 KB |
n=2000 |
87 |
Correct |
75 ms |
5284 KB |
n=2000 |
88 |
Correct |
21 ms |
5324 KB |
n=2000 |
89 |
Correct |
18 ms |
5404 KB |
n=2000 |
90 |
Correct |
11 ms |
5324 KB |
n=2000 |
91 |
Correct |
181 ms |
5268 KB |
n=2000 |
92 |
Correct |
761 ms |
31244 KB |
n=200000 |
93 |
Execution timed out |
4062 ms |
35444 KB |
Time limit exceeded |
94 |
Halted |
0 ms |
0 KB |
- |