#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define sz(x) (int)x.size()
#define ALL(v) v.begin(),v.end()
#define MASK(k) (1LL << (k))
#define BIT(x, i) (((x) >> (i)) & 1)
#define oo (ll)1e18
#define INF (ll)1e9
#define MOD (ll)(1e9 + 7)
using namespace std;
template<class T1, class T2>
bool maximize(T1 &a, T2 b){if(a < b){a = b; return true;} return false;}
template<class T1, class T2>
bool minimize(T1 &a, T2 b){if(a > b){a = b; return true;} return false;}
template<class T1, class T2>
void add(T1 &a, T2 b){a += b; if(a >= MOD) a -= MOD;}
template<class T1, class T2>
void sub(T1 &a, T2 b){a -= b; if(a < 0) a += MOD;}
template<class T>
void cps(T &v){sort(ALL(v)); v.resize(unique(ALL(v)) - v.begin());}
const int MAX = 2e5 + 10, LOG = 18;
int N, M, Q;
vector<int> adj[MAX];
int h[MAX], d[MAX][LOG], a[MAX];
void dfs(int u, int p){
for(int v: adj[u]) if(v != p){
h[v] = h[u] + 1;
d[v][0] = u;
for(int i=1; i<LOG; i++){
d[v][i] = d[d[v][i - 1]][i - 1];
}
dfs(v, u);
}
}
int lca(int u, int v){
if(h[u] < h[v]) swap(u, v);
int delta = h[u] - h[v];
for(int i=0; i<LOG; i++) if(BIT(delta, i)){
u = d[u][i];
}
if(u == v) return u;
for(int i=LOG-1; i>=0; i--) if(d[u][i] != d[v][i]){
u = d[u][i];
v = d[v][i];
}
return d[u][0];
}
set<int> st[2][MAX];
void solve(){
cin >> N >> M >> Q;
for(int i=1; i<N; i++){
int u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
for(int i=1; i<=M; i++){
cin >> a[i];
}
dfs(1, 0);
for(int i=2; i<=M; i++){
st[1][lca(a[i - 1], a[i])].insert(i);
}
for(int i=1; i<=M; i++){
st[0][a[i]].insert(i);
}
while(Q--){
int t; cin >> t;
if(t == 1){
int i, u;
cin >> i >> u;
st[0][a[i]].erase(i);
if(i > 1) st[1][lca(a[i - 1], a[i])].erase(i);
if(i < M) st[1][lca(a[i], a[i + 1])].erase(i + 1);
a[i] = u;
st[0][a[i]].insert(i);
if(i > 1) st[1][lca(a[i - 1], a[i])].insert(i);
if(i < M) st[1][lca(a[i], a[i + 1])].insert(i + 1);
}
if(t == 2){
int l, r, u;
cin >> l >> r >> u;
auto it = st[0][u].lower_bound(l);
if(it != st[0][u].end() && *it <= r){
cout << *it << ' ' << *it << '\n';
continue;
}
it = st[1][u].upper_bound(l);
if(it != st[1][u].end() && *it <= r){
cout << *it - 1 << ' ' << *it << '\n';
continue;
}
cout << -1 << ' ' << -1 << '\n';
}
}
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
// freopen("deggraph.inp", "r", stdin);
// freopen("deggraph.out", "w", stdout);
int t = 1;
// cin >> t;
while(t--){
solve();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
23896 KB |
n=5 |
2 |
Correct |
11 ms |
23980 KB |
n=100 |
3 |
Correct |
11 ms |
23900 KB |
n=100 |
4 |
Correct |
10 ms |
23896 KB |
n=100 |
5 |
Correct |
11 ms |
23900 KB |
n=100 |
6 |
Correct |
11 ms |
23952 KB |
n=100 |
7 |
Correct |
9 ms |
23900 KB |
n=100 |
8 |
Correct |
9 ms |
23900 KB |
n=100 |
9 |
Correct |
11 ms |
23984 KB |
n=100 |
10 |
Correct |
11 ms |
23896 KB |
n=100 |
11 |
Correct |
10 ms |
23900 KB |
n=100 |
12 |
Correct |
11 ms |
23896 KB |
n=100 |
13 |
Correct |
12 ms |
23900 KB |
n=100 |
14 |
Correct |
11 ms |
23784 KB |
n=100 |
15 |
Correct |
11 ms |
23900 KB |
n=100 |
16 |
Correct |
9 ms |
23900 KB |
n=100 |
17 |
Correct |
10 ms |
23900 KB |
n=100 |
18 |
Correct |
11 ms |
23900 KB |
n=100 |
19 |
Correct |
10 ms |
23896 KB |
n=100 |
20 |
Correct |
9 ms |
23900 KB |
n=100 |
21 |
Correct |
9 ms |
23856 KB |
n=100 |
22 |
Correct |
11 ms |
23900 KB |
n=100 |
23 |
Correct |
11 ms |
23900 KB |
n=100 |
24 |
Correct |
10 ms |
23928 KB |
n=100 |
25 |
Correct |
11 ms |
23900 KB |
n=100 |
26 |
Correct |
11 ms |
23900 KB |
n=12 |
27 |
Correct |
10 ms |
23900 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
23896 KB |
n=5 |
2 |
Correct |
11 ms |
23980 KB |
n=100 |
3 |
Correct |
11 ms |
23900 KB |
n=100 |
4 |
Correct |
10 ms |
23896 KB |
n=100 |
5 |
Correct |
11 ms |
23900 KB |
n=100 |
6 |
Correct |
11 ms |
23952 KB |
n=100 |
7 |
Correct |
9 ms |
23900 KB |
n=100 |
8 |
Correct |
9 ms |
23900 KB |
n=100 |
9 |
Correct |
11 ms |
23984 KB |
n=100 |
10 |
Correct |
11 ms |
23896 KB |
n=100 |
11 |
Correct |
10 ms |
23900 KB |
n=100 |
12 |
Correct |
11 ms |
23896 KB |
n=100 |
13 |
Correct |
12 ms |
23900 KB |
n=100 |
14 |
Correct |
11 ms |
23784 KB |
n=100 |
15 |
Correct |
11 ms |
23900 KB |
n=100 |
16 |
Correct |
9 ms |
23900 KB |
n=100 |
17 |
Correct |
10 ms |
23900 KB |
n=100 |
18 |
Correct |
11 ms |
23900 KB |
n=100 |
19 |
Correct |
10 ms |
23896 KB |
n=100 |
20 |
Correct |
9 ms |
23900 KB |
n=100 |
21 |
Correct |
9 ms |
23856 KB |
n=100 |
22 |
Correct |
11 ms |
23900 KB |
n=100 |
23 |
Correct |
11 ms |
23900 KB |
n=100 |
24 |
Correct |
10 ms |
23928 KB |
n=100 |
25 |
Correct |
11 ms |
23900 KB |
n=100 |
26 |
Correct |
11 ms |
23900 KB |
n=12 |
27 |
Correct |
10 ms |
23900 KB |
n=100 |
28 |
Correct |
10 ms |
23900 KB |
n=500 |
29 |
Correct |
12 ms |
23900 KB |
n=500 |
30 |
Correct |
12 ms |
23896 KB |
n=500 |
31 |
Correct |
11 ms |
23896 KB |
n=500 |
32 |
Correct |
11 ms |
23900 KB |
n=500 |
33 |
Correct |
12 ms |
23896 KB |
n=500 |
34 |
Correct |
12 ms |
23960 KB |
n=500 |
35 |
Correct |
12 ms |
23880 KB |
n=500 |
36 |
Correct |
15 ms |
24024 KB |
n=500 |
37 |
Correct |
11 ms |
23896 KB |
n=500 |
38 |
Correct |
11 ms |
23900 KB |
n=500 |
39 |
Correct |
11 ms |
23900 KB |
n=500 |
40 |
Correct |
12 ms |
23900 KB |
n=500 |
41 |
Correct |
11 ms |
23900 KB |
n=500 |
42 |
Correct |
12 ms |
23868 KB |
n=500 |
43 |
Correct |
14 ms |
23900 KB |
n=500 |
44 |
Correct |
11 ms |
23896 KB |
n=500 |
45 |
Correct |
12 ms |
23900 KB |
n=500 |
46 |
Correct |
12 ms |
23900 KB |
n=500 |
47 |
Correct |
11 ms |
23900 KB |
n=500 |
48 |
Correct |
11 ms |
23896 KB |
n=500 |
49 |
Correct |
11 ms |
23900 KB |
n=500 |
50 |
Correct |
12 ms |
23900 KB |
n=500 |
51 |
Correct |
11 ms |
23900 KB |
n=500 |
52 |
Correct |
14 ms |
23900 KB |
n=500 |
53 |
Correct |
13 ms |
23896 KB |
n=500 |
54 |
Correct |
12 ms |
23900 KB |
n=500 |
55 |
Correct |
12 ms |
23900 KB |
n=278 |
56 |
Correct |
11 ms |
23900 KB |
n=500 |
57 |
Correct |
12 ms |
23896 KB |
n=500 |
58 |
Correct |
12 ms |
23896 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
23896 KB |
n=5 |
2 |
Correct |
11 ms |
23980 KB |
n=100 |
3 |
Correct |
11 ms |
23900 KB |
n=100 |
4 |
Correct |
10 ms |
23896 KB |
n=100 |
5 |
Correct |
11 ms |
23900 KB |
n=100 |
6 |
Correct |
11 ms |
23952 KB |
n=100 |
7 |
Correct |
9 ms |
23900 KB |
n=100 |
8 |
Correct |
9 ms |
23900 KB |
n=100 |
9 |
Correct |
11 ms |
23984 KB |
n=100 |
10 |
Correct |
11 ms |
23896 KB |
n=100 |
11 |
Correct |
10 ms |
23900 KB |
n=100 |
12 |
Correct |
11 ms |
23896 KB |
n=100 |
13 |
Correct |
12 ms |
23900 KB |
n=100 |
14 |
Correct |
11 ms |
23784 KB |
n=100 |
15 |
Correct |
11 ms |
23900 KB |
n=100 |
16 |
Correct |
9 ms |
23900 KB |
n=100 |
17 |
Correct |
10 ms |
23900 KB |
n=100 |
18 |
Correct |
11 ms |
23900 KB |
n=100 |
19 |
Correct |
10 ms |
23896 KB |
n=100 |
20 |
Correct |
9 ms |
23900 KB |
n=100 |
21 |
Correct |
9 ms |
23856 KB |
n=100 |
22 |
Correct |
11 ms |
23900 KB |
n=100 |
23 |
Correct |
11 ms |
23900 KB |
n=100 |
24 |
Correct |
10 ms |
23928 KB |
n=100 |
25 |
Correct |
11 ms |
23900 KB |
n=100 |
26 |
Correct |
11 ms |
23900 KB |
n=12 |
27 |
Correct |
10 ms |
23900 KB |
n=100 |
28 |
Correct |
10 ms |
23900 KB |
n=500 |
29 |
Correct |
12 ms |
23900 KB |
n=500 |
30 |
Correct |
12 ms |
23896 KB |
n=500 |
31 |
Correct |
11 ms |
23896 KB |
n=500 |
32 |
Correct |
11 ms |
23900 KB |
n=500 |
33 |
Correct |
12 ms |
23896 KB |
n=500 |
34 |
Correct |
12 ms |
23960 KB |
n=500 |
35 |
Correct |
12 ms |
23880 KB |
n=500 |
36 |
Correct |
15 ms |
24024 KB |
n=500 |
37 |
Correct |
11 ms |
23896 KB |
n=500 |
38 |
Correct |
11 ms |
23900 KB |
n=500 |
39 |
Correct |
11 ms |
23900 KB |
n=500 |
40 |
Correct |
12 ms |
23900 KB |
n=500 |
41 |
Correct |
11 ms |
23900 KB |
n=500 |
42 |
Correct |
12 ms |
23868 KB |
n=500 |
43 |
Correct |
14 ms |
23900 KB |
n=500 |
44 |
Correct |
11 ms |
23896 KB |
n=500 |
45 |
Correct |
12 ms |
23900 KB |
n=500 |
46 |
Correct |
12 ms |
23900 KB |
n=500 |
47 |
Correct |
11 ms |
23900 KB |
n=500 |
48 |
Correct |
11 ms |
23896 KB |
n=500 |
49 |
Correct |
11 ms |
23900 KB |
n=500 |
50 |
Correct |
12 ms |
23900 KB |
n=500 |
51 |
Correct |
11 ms |
23900 KB |
n=500 |
52 |
Correct |
14 ms |
23900 KB |
n=500 |
53 |
Correct |
13 ms |
23896 KB |
n=500 |
54 |
Correct |
12 ms |
23900 KB |
n=500 |
55 |
Correct |
12 ms |
23900 KB |
n=278 |
56 |
Correct |
11 ms |
23900 KB |
n=500 |
57 |
Correct |
12 ms |
23896 KB |
n=500 |
58 |
Correct |
12 ms |
23896 KB |
n=500 |
59 |
Correct |
14 ms |
24412 KB |
n=2000 |
60 |
Correct |
14 ms |
24412 KB |
n=2000 |
61 |
Correct |
13 ms |
24408 KB |
n=2000 |
62 |
Correct |
14 ms |
24412 KB |
n=2000 |
63 |
Correct |
13 ms |
24412 KB |
n=2000 |
64 |
Correct |
13 ms |
24408 KB |
n=2000 |
65 |
Correct |
13 ms |
24408 KB |
n=2000 |
66 |
Correct |
13 ms |
24412 KB |
n=2000 |
67 |
Correct |
14 ms |
24412 KB |
n=2000 |
68 |
Correct |
13 ms |
24452 KB |
n=2000 |
69 |
Correct |
13 ms |
24412 KB |
n=2000 |
70 |
Correct |
13 ms |
24388 KB |
n=2000 |
71 |
Correct |
14 ms |
24412 KB |
n=2000 |
72 |
Correct |
13 ms |
24412 KB |
n=2000 |
73 |
Correct |
13 ms |
24412 KB |
n=2000 |
74 |
Correct |
13 ms |
24412 KB |
n=1844 |
75 |
Correct |
15 ms |
24408 KB |
n=2000 |
76 |
Correct |
14 ms |
24220 KB |
n=2000 |
77 |
Correct |
13 ms |
24412 KB |
n=2000 |
78 |
Correct |
15 ms |
24412 KB |
n=2000 |
79 |
Correct |
13 ms |
24412 KB |
n=2000 |
80 |
Correct |
14 ms |
24412 KB |
n=2000 |
81 |
Correct |
13 ms |
24408 KB |
n=2000 |
82 |
Correct |
13 ms |
24408 KB |
n=2000 |
83 |
Correct |
12 ms |
24512 KB |
n=2000 |
84 |
Correct |
11 ms |
24320 KB |
n=2000 |
85 |
Correct |
12 ms |
24412 KB |
n=2000 |
86 |
Correct |
13 ms |
24412 KB |
n=2000 |
87 |
Correct |
14 ms |
24408 KB |
n=2000 |
88 |
Correct |
13 ms |
24476 KB |
n=2000 |
89 |
Correct |
13 ms |
24408 KB |
n=2000 |
90 |
Correct |
12 ms |
24668 KB |
n=2000 |
91 |
Correct |
13 ms |
24412 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
23896 KB |
n=5 |
2 |
Correct |
11 ms |
23980 KB |
n=100 |
3 |
Correct |
11 ms |
23900 KB |
n=100 |
4 |
Correct |
10 ms |
23896 KB |
n=100 |
5 |
Correct |
11 ms |
23900 KB |
n=100 |
6 |
Correct |
11 ms |
23952 KB |
n=100 |
7 |
Correct |
9 ms |
23900 KB |
n=100 |
8 |
Correct |
9 ms |
23900 KB |
n=100 |
9 |
Correct |
11 ms |
23984 KB |
n=100 |
10 |
Correct |
11 ms |
23896 KB |
n=100 |
11 |
Correct |
10 ms |
23900 KB |
n=100 |
12 |
Correct |
11 ms |
23896 KB |
n=100 |
13 |
Correct |
12 ms |
23900 KB |
n=100 |
14 |
Correct |
11 ms |
23784 KB |
n=100 |
15 |
Correct |
11 ms |
23900 KB |
n=100 |
16 |
Correct |
9 ms |
23900 KB |
n=100 |
17 |
Correct |
10 ms |
23900 KB |
n=100 |
18 |
Correct |
11 ms |
23900 KB |
n=100 |
19 |
Correct |
10 ms |
23896 KB |
n=100 |
20 |
Correct |
9 ms |
23900 KB |
n=100 |
21 |
Correct |
9 ms |
23856 KB |
n=100 |
22 |
Correct |
11 ms |
23900 KB |
n=100 |
23 |
Correct |
11 ms |
23900 KB |
n=100 |
24 |
Correct |
10 ms |
23928 KB |
n=100 |
25 |
Correct |
11 ms |
23900 KB |
n=100 |
26 |
Correct |
11 ms |
23900 KB |
n=12 |
27 |
Correct |
10 ms |
23900 KB |
n=100 |
28 |
Correct |
10 ms |
23900 KB |
n=500 |
29 |
Correct |
12 ms |
23900 KB |
n=500 |
30 |
Correct |
12 ms |
23896 KB |
n=500 |
31 |
Correct |
11 ms |
23896 KB |
n=500 |
32 |
Correct |
11 ms |
23900 KB |
n=500 |
33 |
Correct |
12 ms |
23896 KB |
n=500 |
34 |
Correct |
12 ms |
23960 KB |
n=500 |
35 |
Correct |
12 ms |
23880 KB |
n=500 |
36 |
Correct |
15 ms |
24024 KB |
n=500 |
37 |
Correct |
11 ms |
23896 KB |
n=500 |
38 |
Correct |
11 ms |
23900 KB |
n=500 |
39 |
Correct |
11 ms |
23900 KB |
n=500 |
40 |
Correct |
12 ms |
23900 KB |
n=500 |
41 |
Correct |
11 ms |
23900 KB |
n=500 |
42 |
Correct |
12 ms |
23868 KB |
n=500 |
43 |
Correct |
14 ms |
23900 KB |
n=500 |
44 |
Correct |
11 ms |
23896 KB |
n=500 |
45 |
Correct |
12 ms |
23900 KB |
n=500 |
46 |
Correct |
12 ms |
23900 KB |
n=500 |
47 |
Correct |
11 ms |
23900 KB |
n=500 |
48 |
Correct |
11 ms |
23896 KB |
n=500 |
49 |
Correct |
11 ms |
23900 KB |
n=500 |
50 |
Correct |
12 ms |
23900 KB |
n=500 |
51 |
Correct |
11 ms |
23900 KB |
n=500 |
52 |
Correct |
14 ms |
23900 KB |
n=500 |
53 |
Correct |
13 ms |
23896 KB |
n=500 |
54 |
Correct |
12 ms |
23900 KB |
n=500 |
55 |
Correct |
12 ms |
23900 KB |
n=278 |
56 |
Correct |
11 ms |
23900 KB |
n=500 |
57 |
Correct |
12 ms |
23896 KB |
n=500 |
58 |
Correct |
12 ms |
23896 KB |
n=500 |
59 |
Correct |
14 ms |
24412 KB |
n=2000 |
60 |
Correct |
14 ms |
24412 KB |
n=2000 |
61 |
Correct |
13 ms |
24408 KB |
n=2000 |
62 |
Correct |
14 ms |
24412 KB |
n=2000 |
63 |
Correct |
13 ms |
24412 KB |
n=2000 |
64 |
Correct |
13 ms |
24408 KB |
n=2000 |
65 |
Correct |
13 ms |
24408 KB |
n=2000 |
66 |
Correct |
13 ms |
24412 KB |
n=2000 |
67 |
Correct |
14 ms |
24412 KB |
n=2000 |
68 |
Correct |
13 ms |
24452 KB |
n=2000 |
69 |
Correct |
13 ms |
24412 KB |
n=2000 |
70 |
Correct |
13 ms |
24388 KB |
n=2000 |
71 |
Correct |
14 ms |
24412 KB |
n=2000 |
72 |
Correct |
13 ms |
24412 KB |
n=2000 |
73 |
Correct |
13 ms |
24412 KB |
n=2000 |
74 |
Correct |
13 ms |
24412 KB |
n=1844 |
75 |
Correct |
15 ms |
24408 KB |
n=2000 |
76 |
Correct |
14 ms |
24220 KB |
n=2000 |
77 |
Correct |
13 ms |
24412 KB |
n=2000 |
78 |
Correct |
15 ms |
24412 KB |
n=2000 |
79 |
Correct |
13 ms |
24412 KB |
n=2000 |
80 |
Correct |
14 ms |
24412 KB |
n=2000 |
81 |
Correct |
13 ms |
24408 KB |
n=2000 |
82 |
Correct |
13 ms |
24408 KB |
n=2000 |
83 |
Correct |
12 ms |
24512 KB |
n=2000 |
84 |
Correct |
11 ms |
24320 KB |
n=2000 |
85 |
Correct |
12 ms |
24412 KB |
n=2000 |
86 |
Correct |
13 ms |
24412 KB |
n=2000 |
87 |
Correct |
14 ms |
24408 KB |
n=2000 |
88 |
Correct |
13 ms |
24476 KB |
n=2000 |
89 |
Correct |
13 ms |
24408 KB |
n=2000 |
90 |
Correct |
12 ms |
24668 KB |
n=2000 |
91 |
Correct |
13 ms |
24412 KB |
n=2000 |
92 |
Correct |
458 ms |
73040 KB |
n=200000 |
93 |
Correct |
575 ms |
79516 KB |
n=200000 |
94 |
Correct |
573 ms |
83900 KB |
n=200000 |
95 |
Correct |
418 ms |
72640 KB |
n=200000 |
96 |
Correct |
371 ms |
72896 KB |
n=200000 |
97 |
Correct |
489 ms |
78164 KB |
n=200000 |
98 |
Correct |
369 ms |
72752 KB |
n=200000 |
99 |
Correct |
474 ms |
73040 KB |
n=200000 |
100 |
Correct |
416 ms |
72908 KB |
n=200000 |
101 |
Correct |
535 ms |
85584 KB |
n=200000 |
102 |
Correct |
255 ms |
73888 KB |
n=200000 |
103 |
Correct |
244 ms |
74068 KB |
n=200000 |
104 |
Correct |
242 ms |
74068 KB |
n=200000 |
105 |
Correct |
247 ms |
74324 KB |
n=200000 |
106 |
Correct |
260 ms |
74328 KB |
n=200000 |
107 |
Correct |
244 ms |
74320 KB |
n=200000 |
108 |
Correct |
452 ms |
72788 KB |
n=200000 |
109 |
Correct |
438 ms |
72788 KB |
n=200000 |
110 |
Correct |
437 ms |
72788 KB |
n=200000 |
111 |
Correct |
413 ms |
72264 KB |
n=200000 |
112 |
Correct |
547 ms |
84220 KB |
n=200000 |
113 |
Correct |
550 ms |
78164 KB |
n=200000 |
114 |
Correct |
420 ms |
72388 KB |
n=200000 |
115 |
Correct |
582 ms |
75460 KB |
n=200000 |
116 |
Correct |
432 ms |
72896 KB |
n=200000 |
117 |
Correct |
536 ms |
84828 KB |
n=200000 |
118 |
Correct |
555 ms |
76612 KB |
n=200000 |
119 |
Correct |
427 ms |
72904 KB |
n=200000 |
120 |
Correct |
502 ms |
84564 KB |
n=200000 |
121 |
Correct |
488 ms |
84560 KB |
n=200000 |
122 |
Correct |
480 ms |
84820 KB |
n=200000 |
123 |
Correct |
259 ms |
74400 KB |
n=200000 |
124 |
Correct |
121 ms |
38736 KB |
n=25264 |