#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<long long, long long>
#define pb push_back
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
const ll N = 2e5 + 100;
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll block = 350;
ll n,m,q;
vector<ll>adj[N];
ll up[N][20], d[N], a[N];
set<ll>s[N], g[N];
void dfs(ll u, ll par){
for(auto v : adj[u]){
if(v == par) continue;
up[v][0] = u;
for(int i = 1; i <= 19;i++) up[v][i] = up[up[v][i-1]][i-1];
d[v] = d[u] + 1;
dfs(v, u);
}
}
ll lca(ll u, ll v){
if(d[u] != d[v]){
if(d[u] < d[v]) swap(u, v);
ll k = d[u] - d[v];
for(int i = 19; i >= 0;i--) if(k & (1 << i)) u = up[u][i];
}
if(u == v) return u;
for(int i = 19; i >= 0;i--) if(up[u][i] != up[v][i]) u = up[u][i], v = up[v][i];
return up[u][0];
}
void to_thic_cau(){
cin >> n >> m >> q;
for(int i = 1; i <= n - 1;i++){
ll u,v; cin >> u >> v;
adj[u].pb(v); adj[v].pb(u);
}
dfs(1, 0);
for(int i = 1; i <= m;i++){
cin >> a[i];
s[a[i]].insert(i);
if(i >= 2) g[lca(a[i], a[i-1])].insert(i);
}
while(q--){
ll t; cin >> t;
if(t == 1){
ll pos, v; cin >> pos >> v;
s[a[pos]].erase(pos);
if(pos > 1) g[lca(a[pos], a[pos-1])].erase(pos);
if(pos < m) g[lca(a[pos], a[pos+1])].erase(pos + 1);
a[pos] = v;
s[a[pos]].insert(pos);
if(pos > 1) g[lca(a[pos], a[pos-1])].insert(pos);
if(pos < m) g[lca(a[pos], a[pos+1])].insert(pos + 1);
}
else{
ll l,r,v; cin >> l >> r >> v;
auto it = s[v].lower_bound(l);
if(it != s[v].end() && *it <= r){
cout << (*it) << ' ' << (*it) << '\n';
continue;
}
it = g[v].upper_bound(l);
if(it != g[v].end() && *it <= r){
cout << (*it) - 1 << ' ' << (*it) << '\n';
continue;
}
cout << -1 << ' ' << -1 << '\n';
}
}
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
ll tc = 1;
//cin >> tc;
while(tc--) to_thic_cau();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23896 KB |
n=5 |
2 |
Correct |
12 ms |
23900 KB |
n=100 |
3 |
Correct |
11 ms |
23900 KB |
n=100 |
4 |
Correct |
10 ms |
23900 KB |
n=100 |
5 |
Correct |
9 ms |
23900 KB |
n=100 |
6 |
Correct |
11 ms |
23900 KB |
n=100 |
7 |
Correct |
10 ms |
23900 KB |
n=100 |
8 |
Correct |
10 ms |
24008 KB |
n=100 |
9 |
Correct |
12 ms |
23900 KB |
n=100 |
10 |
Correct |
13 ms |
23896 KB |
n=100 |
11 |
Correct |
12 ms |
23900 KB |
n=100 |
12 |
Correct |
11 ms |
23896 KB |
n=100 |
13 |
Correct |
11 ms |
23900 KB |
n=100 |
14 |
Correct |
11 ms |
23900 KB |
n=100 |
15 |
Correct |
11 ms |
23900 KB |
n=100 |
16 |
Correct |
11 ms |
23900 KB |
n=100 |
17 |
Correct |
9 ms |
23900 KB |
n=100 |
18 |
Correct |
10 ms |
23820 KB |
n=100 |
19 |
Correct |
11 ms |
23896 KB |
n=100 |
20 |
Correct |
14 ms |
23896 KB |
n=100 |
21 |
Correct |
14 ms |
23772 KB |
n=100 |
22 |
Correct |
14 ms |
23900 KB |
n=100 |
23 |
Correct |
10 ms |
23896 KB |
n=100 |
24 |
Correct |
9 ms |
23932 KB |
n=100 |
25 |
Correct |
10 ms |
24008 KB |
n=100 |
26 |
Correct |
10 ms |
23900 KB |
n=12 |
27 |
Correct |
11 ms |
23896 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23896 KB |
n=5 |
2 |
Correct |
12 ms |
23900 KB |
n=100 |
3 |
Correct |
11 ms |
23900 KB |
n=100 |
4 |
Correct |
10 ms |
23900 KB |
n=100 |
5 |
Correct |
9 ms |
23900 KB |
n=100 |
6 |
Correct |
11 ms |
23900 KB |
n=100 |
7 |
Correct |
10 ms |
23900 KB |
n=100 |
8 |
Correct |
10 ms |
24008 KB |
n=100 |
9 |
Correct |
12 ms |
23900 KB |
n=100 |
10 |
Correct |
13 ms |
23896 KB |
n=100 |
11 |
Correct |
12 ms |
23900 KB |
n=100 |
12 |
Correct |
11 ms |
23896 KB |
n=100 |
13 |
Correct |
11 ms |
23900 KB |
n=100 |
14 |
Correct |
11 ms |
23900 KB |
n=100 |
15 |
Correct |
11 ms |
23900 KB |
n=100 |
16 |
Correct |
11 ms |
23900 KB |
n=100 |
17 |
Correct |
9 ms |
23900 KB |
n=100 |
18 |
Correct |
10 ms |
23820 KB |
n=100 |
19 |
Correct |
11 ms |
23896 KB |
n=100 |
20 |
Correct |
14 ms |
23896 KB |
n=100 |
21 |
Correct |
14 ms |
23772 KB |
n=100 |
22 |
Correct |
14 ms |
23900 KB |
n=100 |
23 |
Correct |
10 ms |
23896 KB |
n=100 |
24 |
Correct |
9 ms |
23932 KB |
n=100 |
25 |
Correct |
10 ms |
24008 KB |
n=100 |
26 |
Correct |
10 ms |
23900 KB |
n=12 |
27 |
Correct |
11 ms |
23896 KB |
n=100 |
28 |
Correct |
11 ms |
23896 KB |
n=500 |
29 |
Correct |
12 ms |
24156 KB |
n=500 |
30 |
Correct |
11 ms |
24156 KB |
n=500 |
31 |
Correct |
11 ms |
24152 KB |
n=500 |
32 |
Correct |
11 ms |
23976 KB |
n=500 |
33 |
Correct |
14 ms |
24156 KB |
n=500 |
34 |
Correct |
13 ms |
23896 KB |
n=500 |
35 |
Correct |
11 ms |
24156 KB |
n=500 |
36 |
Correct |
10 ms |
23900 KB |
n=500 |
37 |
Correct |
11 ms |
23900 KB |
n=500 |
38 |
Correct |
11 ms |
23900 KB |
n=500 |
39 |
Correct |
12 ms |
24156 KB |
n=500 |
40 |
Correct |
12 ms |
23896 KB |
n=500 |
41 |
Correct |
11 ms |
23900 KB |
n=500 |
42 |
Correct |
13 ms |
23900 KB |
n=500 |
43 |
Correct |
12 ms |
23900 KB |
n=500 |
44 |
Correct |
12 ms |
24104 KB |
n=500 |
45 |
Correct |
14 ms |
23900 KB |
n=500 |
46 |
Correct |
11 ms |
24176 KB |
n=500 |
47 |
Correct |
11 ms |
24152 KB |
n=500 |
48 |
Correct |
12 ms |
23900 KB |
n=500 |
49 |
Correct |
11 ms |
24156 KB |
n=500 |
50 |
Correct |
12 ms |
23900 KB |
n=500 |
51 |
Correct |
12 ms |
24156 KB |
n=500 |
52 |
Correct |
11 ms |
24060 KB |
n=500 |
53 |
Correct |
12 ms |
24156 KB |
n=500 |
54 |
Correct |
12 ms |
24156 KB |
n=500 |
55 |
Correct |
12 ms |
24008 KB |
n=278 |
56 |
Correct |
10 ms |
24156 KB |
n=500 |
57 |
Correct |
10 ms |
24172 KB |
n=500 |
58 |
Correct |
12 ms |
23900 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23896 KB |
n=5 |
2 |
Correct |
12 ms |
23900 KB |
n=100 |
3 |
Correct |
11 ms |
23900 KB |
n=100 |
4 |
Correct |
10 ms |
23900 KB |
n=100 |
5 |
Correct |
9 ms |
23900 KB |
n=100 |
6 |
Correct |
11 ms |
23900 KB |
n=100 |
7 |
Correct |
10 ms |
23900 KB |
n=100 |
8 |
Correct |
10 ms |
24008 KB |
n=100 |
9 |
Correct |
12 ms |
23900 KB |
n=100 |
10 |
Correct |
13 ms |
23896 KB |
n=100 |
11 |
Correct |
12 ms |
23900 KB |
n=100 |
12 |
Correct |
11 ms |
23896 KB |
n=100 |
13 |
Correct |
11 ms |
23900 KB |
n=100 |
14 |
Correct |
11 ms |
23900 KB |
n=100 |
15 |
Correct |
11 ms |
23900 KB |
n=100 |
16 |
Correct |
11 ms |
23900 KB |
n=100 |
17 |
Correct |
9 ms |
23900 KB |
n=100 |
18 |
Correct |
10 ms |
23820 KB |
n=100 |
19 |
Correct |
11 ms |
23896 KB |
n=100 |
20 |
Correct |
14 ms |
23896 KB |
n=100 |
21 |
Correct |
14 ms |
23772 KB |
n=100 |
22 |
Correct |
14 ms |
23900 KB |
n=100 |
23 |
Correct |
10 ms |
23896 KB |
n=100 |
24 |
Correct |
9 ms |
23932 KB |
n=100 |
25 |
Correct |
10 ms |
24008 KB |
n=100 |
26 |
Correct |
10 ms |
23900 KB |
n=12 |
27 |
Correct |
11 ms |
23896 KB |
n=100 |
28 |
Correct |
11 ms |
23896 KB |
n=500 |
29 |
Correct |
12 ms |
24156 KB |
n=500 |
30 |
Correct |
11 ms |
24156 KB |
n=500 |
31 |
Correct |
11 ms |
24152 KB |
n=500 |
32 |
Correct |
11 ms |
23976 KB |
n=500 |
33 |
Correct |
14 ms |
24156 KB |
n=500 |
34 |
Correct |
13 ms |
23896 KB |
n=500 |
35 |
Correct |
11 ms |
24156 KB |
n=500 |
36 |
Correct |
10 ms |
23900 KB |
n=500 |
37 |
Correct |
11 ms |
23900 KB |
n=500 |
38 |
Correct |
11 ms |
23900 KB |
n=500 |
39 |
Correct |
12 ms |
24156 KB |
n=500 |
40 |
Correct |
12 ms |
23896 KB |
n=500 |
41 |
Correct |
11 ms |
23900 KB |
n=500 |
42 |
Correct |
13 ms |
23900 KB |
n=500 |
43 |
Correct |
12 ms |
23900 KB |
n=500 |
44 |
Correct |
12 ms |
24104 KB |
n=500 |
45 |
Correct |
14 ms |
23900 KB |
n=500 |
46 |
Correct |
11 ms |
24176 KB |
n=500 |
47 |
Correct |
11 ms |
24152 KB |
n=500 |
48 |
Correct |
12 ms |
23900 KB |
n=500 |
49 |
Correct |
11 ms |
24156 KB |
n=500 |
50 |
Correct |
12 ms |
23900 KB |
n=500 |
51 |
Correct |
12 ms |
24156 KB |
n=500 |
52 |
Correct |
11 ms |
24060 KB |
n=500 |
53 |
Correct |
12 ms |
24156 KB |
n=500 |
54 |
Correct |
12 ms |
24156 KB |
n=500 |
55 |
Correct |
12 ms |
24008 KB |
n=278 |
56 |
Correct |
10 ms |
24156 KB |
n=500 |
57 |
Correct |
10 ms |
24172 KB |
n=500 |
58 |
Correct |
12 ms |
23900 KB |
n=500 |
59 |
Correct |
14 ms |
24412 KB |
n=2000 |
60 |
Correct |
18 ms |
24668 KB |
n=2000 |
61 |
Correct |
16 ms |
24668 KB |
n=2000 |
62 |
Correct |
16 ms |
24668 KB |
n=2000 |
63 |
Correct |
15 ms |
24412 KB |
n=2000 |
64 |
Correct |
13 ms |
24668 KB |
n=2000 |
65 |
Correct |
15 ms |
24412 KB |
n=2000 |
66 |
Correct |
13 ms |
24664 KB |
n=2000 |
67 |
Correct |
14 ms |
24408 KB |
n=2000 |
68 |
Correct |
14 ms |
24664 KB |
n=2000 |
69 |
Correct |
13 ms |
24408 KB |
n=2000 |
70 |
Correct |
13 ms |
24412 KB |
n=2000 |
71 |
Correct |
15 ms |
24412 KB |
n=2000 |
72 |
Correct |
12 ms |
24412 KB |
n=2000 |
73 |
Correct |
13 ms |
24408 KB |
n=2000 |
74 |
Correct |
12 ms |
24412 KB |
n=1844 |
75 |
Correct |
12 ms |
24412 KB |
n=2000 |
76 |
Correct |
20 ms |
24412 KB |
n=2000 |
77 |
Correct |
14 ms |
24408 KB |
n=2000 |
78 |
Correct |
12 ms |
24412 KB |
n=2000 |
79 |
Correct |
14 ms |
24412 KB |
n=2000 |
80 |
Correct |
17 ms |
24668 KB |
n=2000 |
81 |
Correct |
14 ms |
24664 KB |
n=2000 |
82 |
Correct |
13 ms |
24408 KB |
n=2000 |
83 |
Correct |
14 ms |
24664 KB |
n=2000 |
84 |
Correct |
13 ms |
24412 KB |
n=2000 |
85 |
Correct |
14 ms |
24492 KB |
n=2000 |
86 |
Correct |
17 ms |
24664 KB |
n=2000 |
87 |
Correct |
14 ms |
24408 KB |
n=2000 |
88 |
Correct |
14 ms |
24752 KB |
n=2000 |
89 |
Correct |
14 ms |
24668 KB |
n=2000 |
90 |
Correct |
16 ms |
24664 KB |
n=2000 |
91 |
Correct |
13 ms |
24408 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23896 KB |
n=5 |
2 |
Correct |
12 ms |
23900 KB |
n=100 |
3 |
Correct |
11 ms |
23900 KB |
n=100 |
4 |
Correct |
10 ms |
23900 KB |
n=100 |
5 |
Correct |
9 ms |
23900 KB |
n=100 |
6 |
Correct |
11 ms |
23900 KB |
n=100 |
7 |
Correct |
10 ms |
23900 KB |
n=100 |
8 |
Correct |
10 ms |
24008 KB |
n=100 |
9 |
Correct |
12 ms |
23900 KB |
n=100 |
10 |
Correct |
13 ms |
23896 KB |
n=100 |
11 |
Correct |
12 ms |
23900 KB |
n=100 |
12 |
Correct |
11 ms |
23896 KB |
n=100 |
13 |
Correct |
11 ms |
23900 KB |
n=100 |
14 |
Correct |
11 ms |
23900 KB |
n=100 |
15 |
Correct |
11 ms |
23900 KB |
n=100 |
16 |
Correct |
11 ms |
23900 KB |
n=100 |
17 |
Correct |
9 ms |
23900 KB |
n=100 |
18 |
Correct |
10 ms |
23820 KB |
n=100 |
19 |
Correct |
11 ms |
23896 KB |
n=100 |
20 |
Correct |
14 ms |
23896 KB |
n=100 |
21 |
Correct |
14 ms |
23772 KB |
n=100 |
22 |
Correct |
14 ms |
23900 KB |
n=100 |
23 |
Correct |
10 ms |
23896 KB |
n=100 |
24 |
Correct |
9 ms |
23932 KB |
n=100 |
25 |
Correct |
10 ms |
24008 KB |
n=100 |
26 |
Correct |
10 ms |
23900 KB |
n=12 |
27 |
Correct |
11 ms |
23896 KB |
n=100 |
28 |
Correct |
11 ms |
23896 KB |
n=500 |
29 |
Correct |
12 ms |
24156 KB |
n=500 |
30 |
Correct |
11 ms |
24156 KB |
n=500 |
31 |
Correct |
11 ms |
24152 KB |
n=500 |
32 |
Correct |
11 ms |
23976 KB |
n=500 |
33 |
Correct |
14 ms |
24156 KB |
n=500 |
34 |
Correct |
13 ms |
23896 KB |
n=500 |
35 |
Correct |
11 ms |
24156 KB |
n=500 |
36 |
Correct |
10 ms |
23900 KB |
n=500 |
37 |
Correct |
11 ms |
23900 KB |
n=500 |
38 |
Correct |
11 ms |
23900 KB |
n=500 |
39 |
Correct |
12 ms |
24156 KB |
n=500 |
40 |
Correct |
12 ms |
23896 KB |
n=500 |
41 |
Correct |
11 ms |
23900 KB |
n=500 |
42 |
Correct |
13 ms |
23900 KB |
n=500 |
43 |
Correct |
12 ms |
23900 KB |
n=500 |
44 |
Correct |
12 ms |
24104 KB |
n=500 |
45 |
Correct |
14 ms |
23900 KB |
n=500 |
46 |
Correct |
11 ms |
24176 KB |
n=500 |
47 |
Correct |
11 ms |
24152 KB |
n=500 |
48 |
Correct |
12 ms |
23900 KB |
n=500 |
49 |
Correct |
11 ms |
24156 KB |
n=500 |
50 |
Correct |
12 ms |
23900 KB |
n=500 |
51 |
Correct |
12 ms |
24156 KB |
n=500 |
52 |
Correct |
11 ms |
24060 KB |
n=500 |
53 |
Correct |
12 ms |
24156 KB |
n=500 |
54 |
Correct |
12 ms |
24156 KB |
n=500 |
55 |
Correct |
12 ms |
24008 KB |
n=278 |
56 |
Correct |
10 ms |
24156 KB |
n=500 |
57 |
Correct |
10 ms |
24172 KB |
n=500 |
58 |
Correct |
12 ms |
23900 KB |
n=500 |
59 |
Correct |
14 ms |
24412 KB |
n=2000 |
60 |
Correct |
18 ms |
24668 KB |
n=2000 |
61 |
Correct |
16 ms |
24668 KB |
n=2000 |
62 |
Correct |
16 ms |
24668 KB |
n=2000 |
63 |
Correct |
15 ms |
24412 KB |
n=2000 |
64 |
Correct |
13 ms |
24668 KB |
n=2000 |
65 |
Correct |
15 ms |
24412 KB |
n=2000 |
66 |
Correct |
13 ms |
24664 KB |
n=2000 |
67 |
Correct |
14 ms |
24408 KB |
n=2000 |
68 |
Correct |
14 ms |
24664 KB |
n=2000 |
69 |
Correct |
13 ms |
24408 KB |
n=2000 |
70 |
Correct |
13 ms |
24412 KB |
n=2000 |
71 |
Correct |
15 ms |
24412 KB |
n=2000 |
72 |
Correct |
12 ms |
24412 KB |
n=2000 |
73 |
Correct |
13 ms |
24408 KB |
n=2000 |
74 |
Correct |
12 ms |
24412 KB |
n=1844 |
75 |
Correct |
12 ms |
24412 KB |
n=2000 |
76 |
Correct |
20 ms |
24412 KB |
n=2000 |
77 |
Correct |
14 ms |
24408 KB |
n=2000 |
78 |
Correct |
12 ms |
24412 KB |
n=2000 |
79 |
Correct |
14 ms |
24412 KB |
n=2000 |
80 |
Correct |
17 ms |
24668 KB |
n=2000 |
81 |
Correct |
14 ms |
24664 KB |
n=2000 |
82 |
Correct |
13 ms |
24408 KB |
n=2000 |
83 |
Correct |
14 ms |
24664 KB |
n=2000 |
84 |
Correct |
13 ms |
24412 KB |
n=2000 |
85 |
Correct |
14 ms |
24492 KB |
n=2000 |
86 |
Correct |
17 ms |
24664 KB |
n=2000 |
87 |
Correct |
14 ms |
24408 KB |
n=2000 |
88 |
Correct |
14 ms |
24752 KB |
n=2000 |
89 |
Correct |
14 ms |
24668 KB |
n=2000 |
90 |
Correct |
16 ms |
24664 KB |
n=2000 |
91 |
Correct |
13 ms |
24408 KB |
n=2000 |
92 |
Correct |
522 ms |
92680 KB |
n=200000 |
93 |
Correct |
787 ms |
98936 KB |
n=200000 |
94 |
Correct |
835 ms |
103184 KB |
n=200000 |
95 |
Correct |
488 ms |
92456 KB |
n=200000 |
96 |
Correct |
483 ms |
92352 KB |
n=200000 |
97 |
Correct |
733 ms |
97876 KB |
n=200000 |
98 |
Correct |
497 ms |
92348 KB |
n=200000 |
99 |
Correct |
649 ms |
92744 KB |
n=200000 |
100 |
Correct |
497 ms |
92612 KB |
n=200000 |
101 |
Correct |
707 ms |
104420 KB |
n=200000 |
102 |
Correct |
289 ms |
93776 KB |
n=200000 |
103 |
Correct |
294 ms |
93780 KB |
n=200000 |
104 |
Correct |
318 ms |
93816 KB |
n=200000 |
105 |
Correct |
295 ms |
94288 KB |
n=200000 |
106 |
Correct |
329 ms |
94324 KB |
n=200000 |
107 |
Correct |
332 ms |
94292 KB |
n=200000 |
108 |
Correct |
584 ms |
92752 KB |
n=200000 |
109 |
Correct |
612 ms |
92756 KB |
n=200000 |
110 |
Correct |
619 ms |
92772 KB |
n=200000 |
111 |
Correct |
500 ms |
91872 KB |
n=200000 |
112 |
Correct |
766 ms |
103252 KB |
n=200000 |
113 |
Correct |
719 ms |
97848 KB |
n=200000 |
114 |
Correct |
503 ms |
91992 KB |
n=200000 |
115 |
Correct |
761 ms |
95060 KB |
n=200000 |
116 |
Correct |
497 ms |
92708 KB |
n=200000 |
117 |
Correct |
737 ms |
103792 KB |
n=200000 |
118 |
Correct |
706 ms |
96436 KB |
n=200000 |
119 |
Correct |
474 ms |
92612 KB |
n=200000 |
120 |
Correct |
683 ms |
103356 KB |
n=200000 |
121 |
Correct |
696 ms |
103316 KB |
n=200000 |
122 |
Correct |
630 ms |
103760 KB |
n=200000 |
123 |
Correct |
324 ms |
93976 KB |
n=200000 |
124 |
Correct |
124 ms |
41556 KB |
n=25264 |