#include <bits/stdc++.h>
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define optimus_prime ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define fxd(x) fixed << setprecision(x)
#define all(a) (a.begin() , a.end())
#define popcount(x) __builtin_popcount(x)
#define lwb lower_bound
#define upb upper_bound
#define dl double long
#define ll long long
#define int long long
#define pb push_back
#define sz() size()
#define F first
#define S second
using namespace std;
const ll N = 1e5+9;
const ll L = 18;
ll n , m , q , a[N] , tin[N] , tout[N] , timer , up[N][L+9];
vector <int> g[N];
set <int> st[N] , st1[N];
void calc(ll cur , ll p){
tin[cur]=++timer;
up[cur][0]=p;
for (int i = 1 ; i <= L ; i++)up[cur][i]=up[up[cur][i-1]][i-1];
for (auto to : g[cur]){
if (to!=p)calc(to , cur);
}
tout[cur]=timer;
}
bool upper(ll a , ll b){
return (tin[a]<=tin[b]&&tout[b]<=tout[a]);
}
ll lca(ll a , ll b){
if (a && (!b || upper(a , b)))return a;
if (b && (!a || upper(b , a)))return b;
for (int i = L ; i >= 0 ; i--){
if (!up[a][i])continue;
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++){
ll u , v;
cin >> u >> v;
g[u].pb(v);
g[v].pb(u);
}
calc(1 , 0);
for (int i = 1 ; i <= m ; i++){
cin >> a[i];
st[a[i]].insert(i);
if (i>1)st1[lca(a[i-1] , a[i])].insert(i-1);
}
while (q--){
ll tp;
cin >> tp;
if (tp==1){
ll pos , v;
cin >> pos >> v;
if (pos<m)st1[lca(a[pos] , a[pos+1])].erase(pos);
if (pos>1)st1[lca(a[pos-1] , a[pos])].erase(pos-1);
st[a[pos]].erase(pos);
a[pos]=v;
st[a[pos]].insert(pos);
if (pos<m)st1[lca(a[pos] , a[pos+1])].insert(pos);
if (pos>1)st1[lca(a[pos-1] , a[pos])].insert(pos-1);
}
else {
ll l , r , v;
cin >> l >> r >> v;
if (st[v].lwb(l)!=st[v].end() && (*st[v].lwb(l))<=r){
ll x=*(st[v].lwb(l));
cout << x << " " << x << "\n";
}
else if (st1[v].lwb(l)!=st1[v].end() && (*st1[v].lwb(l))<r){
ll x=*(st1[v].lwb(l));
cout << x << " " << x+1 << "\n";
}
else cout << "-1 -1\n";
}
}
}
signed main() {
optimus_prime;
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
14936 KB |
n=5 |
2 |
Correct |
3 ms |
14940 KB |
n=100 |
3 |
Correct |
4 ms |
14940 KB |
n=100 |
4 |
Correct |
3 ms |
14996 KB |
n=100 |
5 |
Correct |
3 ms |
14940 KB |
n=100 |
6 |
Correct |
3 ms |
14936 KB |
n=100 |
7 |
Correct |
3 ms |
14936 KB |
n=100 |
8 |
Correct |
3 ms |
14940 KB |
n=100 |
9 |
Correct |
3 ms |
14940 KB |
n=100 |
10 |
Correct |
3 ms |
14940 KB |
n=100 |
11 |
Correct |
3 ms |
14936 KB |
n=100 |
12 |
Correct |
4 ms |
15196 KB |
n=100 |
13 |
Correct |
3 ms |
14940 KB |
n=100 |
14 |
Correct |
3 ms |
14940 KB |
n=100 |
15 |
Correct |
3 ms |
14940 KB |
n=100 |
16 |
Correct |
3 ms |
14992 KB |
n=100 |
17 |
Correct |
3 ms |
14940 KB |
n=100 |
18 |
Correct |
3 ms |
14996 KB |
n=100 |
19 |
Correct |
3 ms |
14940 KB |
n=100 |
20 |
Correct |
2 ms |
14940 KB |
n=100 |
21 |
Correct |
3 ms |
14940 KB |
n=100 |
22 |
Correct |
3 ms |
14940 KB |
n=100 |
23 |
Correct |
2 ms |
14936 KB |
n=100 |
24 |
Correct |
3 ms |
14940 KB |
n=100 |
25 |
Correct |
3 ms |
14940 KB |
n=100 |
26 |
Correct |
3 ms |
14936 KB |
n=12 |
27 |
Correct |
3 ms |
14940 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
14936 KB |
n=5 |
2 |
Correct |
3 ms |
14940 KB |
n=100 |
3 |
Correct |
4 ms |
14940 KB |
n=100 |
4 |
Correct |
3 ms |
14996 KB |
n=100 |
5 |
Correct |
3 ms |
14940 KB |
n=100 |
6 |
Correct |
3 ms |
14936 KB |
n=100 |
7 |
Correct |
3 ms |
14936 KB |
n=100 |
8 |
Correct |
3 ms |
14940 KB |
n=100 |
9 |
Correct |
3 ms |
14940 KB |
n=100 |
10 |
Correct |
3 ms |
14940 KB |
n=100 |
11 |
Correct |
3 ms |
14936 KB |
n=100 |
12 |
Correct |
4 ms |
15196 KB |
n=100 |
13 |
Correct |
3 ms |
14940 KB |
n=100 |
14 |
Correct |
3 ms |
14940 KB |
n=100 |
15 |
Correct |
3 ms |
14940 KB |
n=100 |
16 |
Correct |
3 ms |
14992 KB |
n=100 |
17 |
Correct |
3 ms |
14940 KB |
n=100 |
18 |
Correct |
3 ms |
14996 KB |
n=100 |
19 |
Correct |
3 ms |
14940 KB |
n=100 |
20 |
Correct |
2 ms |
14940 KB |
n=100 |
21 |
Correct |
3 ms |
14940 KB |
n=100 |
22 |
Correct |
3 ms |
14940 KB |
n=100 |
23 |
Correct |
2 ms |
14936 KB |
n=100 |
24 |
Correct |
3 ms |
14940 KB |
n=100 |
25 |
Correct |
3 ms |
14940 KB |
n=100 |
26 |
Correct |
3 ms |
14936 KB |
n=12 |
27 |
Correct |
3 ms |
14940 KB |
n=100 |
28 |
Correct |
3 ms |
14936 KB |
n=500 |
29 |
Correct |
3 ms |
15136 KB |
n=500 |
30 |
Correct |
3 ms |
14940 KB |
n=500 |
31 |
Correct |
3 ms |
14940 KB |
n=500 |
32 |
Correct |
4 ms |
14936 KB |
n=500 |
33 |
Correct |
3 ms |
14936 KB |
n=500 |
34 |
Correct |
3 ms |
14940 KB |
n=500 |
35 |
Correct |
3 ms |
14940 KB |
n=500 |
36 |
Correct |
3 ms |
14940 KB |
n=500 |
37 |
Correct |
3 ms |
14936 KB |
n=500 |
38 |
Correct |
5 ms |
14936 KB |
n=500 |
39 |
Correct |
3 ms |
14940 KB |
n=500 |
40 |
Correct |
3 ms |
15000 KB |
n=500 |
41 |
Correct |
3 ms |
14940 KB |
n=500 |
42 |
Correct |
3 ms |
14940 KB |
n=500 |
43 |
Correct |
3 ms |
14940 KB |
n=500 |
44 |
Correct |
3 ms |
14940 KB |
n=500 |
45 |
Correct |
3 ms |
14940 KB |
n=500 |
46 |
Correct |
3 ms |
15000 KB |
n=500 |
47 |
Correct |
3 ms |
14940 KB |
n=500 |
48 |
Correct |
3 ms |
14936 KB |
n=500 |
49 |
Correct |
3 ms |
14940 KB |
n=500 |
50 |
Correct |
3 ms |
14936 KB |
n=500 |
51 |
Correct |
3 ms |
15004 KB |
n=500 |
52 |
Correct |
3 ms |
14940 KB |
n=500 |
53 |
Correct |
3 ms |
14940 KB |
n=500 |
54 |
Correct |
3 ms |
14940 KB |
n=500 |
55 |
Correct |
3 ms |
14940 KB |
n=278 |
56 |
Correct |
3 ms |
14940 KB |
n=500 |
57 |
Correct |
3 ms |
14940 KB |
n=500 |
58 |
Correct |
3 ms |
14940 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
14936 KB |
n=5 |
2 |
Correct |
3 ms |
14940 KB |
n=100 |
3 |
Correct |
4 ms |
14940 KB |
n=100 |
4 |
Correct |
3 ms |
14996 KB |
n=100 |
5 |
Correct |
3 ms |
14940 KB |
n=100 |
6 |
Correct |
3 ms |
14936 KB |
n=100 |
7 |
Correct |
3 ms |
14936 KB |
n=100 |
8 |
Correct |
3 ms |
14940 KB |
n=100 |
9 |
Correct |
3 ms |
14940 KB |
n=100 |
10 |
Correct |
3 ms |
14940 KB |
n=100 |
11 |
Correct |
3 ms |
14936 KB |
n=100 |
12 |
Correct |
4 ms |
15196 KB |
n=100 |
13 |
Correct |
3 ms |
14940 KB |
n=100 |
14 |
Correct |
3 ms |
14940 KB |
n=100 |
15 |
Correct |
3 ms |
14940 KB |
n=100 |
16 |
Correct |
3 ms |
14992 KB |
n=100 |
17 |
Correct |
3 ms |
14940 KB |
n=100 |
18 |
Correct |
3 ms |
14996 KB |
n=100 |
19 |
Correct |
3 ms |
14940 KB |
n=100 |
20 |
Correct |
2 ms |
14940 KB |
n=100 |
21 |
Correct |
3 ms |
14940 KB |
n=100 |
22 |
Correct |
3 ms |
14940 KB |
n=100 |
23 |
Correct |
2 ms |
14936 KB |
n=100 |
24 |
Correct |
3 ms |
14940 KB |
n=100 |
25 |
Correct |
3 ms |
14940 KB |
n=100 |
26 |
Correct |
3 ms |
14936 KB |
n=12 |
27 |
Correct |
3 ms |
14940 KB |
n=100 |
28 |
Correct |
3 ms |
14936 KB |
n=500 |
29 |
Correct |
3 ms |
15136 KB |
n=500 |
30 |
Correct |
3 ms |
14940 KB |
n=500 |
31 |
Correct |
3 ms |
14940 KB |
n=500 |
32 |
Correct |
4 ms |
14936 KB |
n=500 |
33 |
Correct |
3 ms |
14936 KB |
n=500 |
34 |
Correct |
3 ms |
14940 KB |
n=500 |
35 |
Correct |
3 ms |
14940 KB |
n=500 |
36 |
Correct |
3 ms |
14940 KB |
n=500 |
37 |
Correct |
3 ms |
14936 KB |
n=500 |
38 |
Correct |
5 ms |
14936 KB |
n=500 |
39 |
Correct |
3 ms |
14940 KB |
n=500 |
40 |
Correct |
3 ms |
15000 KB |
n=500 |
41 |
Correct |
3 ms |
14940 KB |
n=500 |
42 |
Correct |
3 ms |
14940 KB |
n=500 |
43 |
Correct |
3 ms |
14940 KB |
n=500 |
44 |
Correct |
3 ms |
14940 KB |
n=500 |
45 |
Correct |
3 ms |
14940 KB |
n=500 |
46 |
Correct |
3 ms |
15000 KB |
n=500 |
47 |
Correct |
3 ms |
14940 KB |
n=500 |
48 |
Correct |
3 ms |
14936 KB |
n=500 |
49 |
Correct |
3 ms |
14940 KB |
n=500 |
50 |
Correct |
3 ms |
14936 KB |
n=500 |
51 |
Correct |
3 ms |
15004 KB |
n=500 |
52 |
Correct |
3 ms |
14940 KB |
n=500 |
53 |
Correct |
3 ms |
14940 KB |
n=500 |
54 |
Correct |
3 ms |
14940 KB |
n=500 |
55 |
Correct |
3 ms |
14940 KB |
n=278 |
56 |
Correct |
3 ms |
14940 KB |
n=500 |
57 |
Correct |
3 ms |
14940 KB |
n=500 |
58 |
Correct |
3 ms |
14940 KB |
n=500 |
59 |
Correct |
5 ms |
15196 KB |
n=2000 |
60 |
Correct |
4 ms |
15196 KB |
n=2000 |
61 |
Correct |
5 ms |
15260 KB |
n=2000 |
62 |
Correct |
5 ms |
15192 KB |
n=2000 |
63 |
Correct |
5 ms |
15192 KB |
n=2000 |
64 |
Correct |
5 ms |
15196 KB |
n=2000 |
65 |
Correct |
5 ms |
15196 KB |
n=2000 |
66 |
Correct |
5 ms |
15196 KB |
n=2000 |
67 |
Correct |
5 ms |
15196 KB |
n=2000 |
68 |
Correct |
5 ms |
15196 KB |
n=2000 |
69 |
Correct |
4 ms |
15196 KB |
n=2000 |
70 |
Correct |
4 ms |
15196 KB |
n=2000 |
71 |
Correct |
5 ms |
15192 KB |
n=2000 |
72 |
Correct |
5 ms |
15292 KB |
n=2000 |
73 |
Correct |
4 ms |
15196 KB |
n=2000 |
74 |
Correct |
5 ms |
15192 KB |
n=1844 |
75 |
Correct |
4 ms |
15196 KB |
n=2000 |
76 |
Correct |
5 ms |
15120 KB |
n=2000 |
77 |
Correct |
5 ms |
15196 KB |
n=2000 |
78 |
Correct |
5 ms |
15196 KB |
n=2000 |
79 |
Correct |
5 ms |
15196 KB |
n=2000 |
80 |
Correct |
4 ms |
15292 KB |
n=2000 |
81 |
Correct |
5 ms |
15196 KB |
n=2000 |
82 |
Correct |
5 ms |
15192 KB |
n=2000 |
83 |
Correct |
5 ms |
15196 KB |
n=2000 |
84 |
Correct |
5 ms |
15196 KB |
n=2000 |
85 |
Correct |
5 ms |
15448 KB |
n=2000 |
86 |
Correct |
5 ms |
15212 KB |
n=2000 |
87 |
Correct |
5 ms |
15196 KB |
n=2000 |
88 |
Correct |
4 ms |
15196 KB |
n=2000 |
89 |
Correct |
4 ms |
15196 KB |
n=2000 |
90 |
Correct |
4 ms |
15196 KB |
n=2000 |
91 |
Correct |
4 ms |
15196 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
14936 KB |
n=5 |
2 |
Correct |
3 ms |
14940 KB |
n=100 |
3 |
Correct |
4 ms |
14940 KB |
n=100 |
4 |
Correct |
3 ms |
14996 KB |
n=100 |
5 |
Correct |
3 ms |
14940 KB |
n=100 |
6 |
Correct |
3 ms |
14936 KB |
n=100 |
7 |
Correct |
3 ms |
14936 KB |
n=100 |
8 |
Correct |
3 ms |
14940 KB |
n=100 |
9 |
Correct |
3 ms |
14940 KB |
n=100 |
10 |
Correct |
3 ms |
14940 KB |
n=100 |
11 |
Correct |
3 ms |
14936 KB |
n=100 |
12 |
Correct |
4 ms |
15196 KB |
n=100 |
13 |
Correct |
3 ms |
14940 KB |
n=100 |
14 |
Correct |
3 ms |
14940 KB |
n=100 |
15 |
Correct |
3 ms |
14940 KB |
n=100 |
16 |
Correct |
3 ms |
14992 KB |
n=100 |
17 |
Correct |
3 ms |
14940 KB |
n=100 |
18 |
Correct |
3 ms |
14996 KB |
n=100 |
19 |
Correct |
3 ms |
14940 KB |
n=100 |
20 |
Correct |
2 ms |
14940 KB |
n=100 |
21 |
Correct |
3 ms |
14940 KB |
n=100 |
22 |
Correct |
3 ms |
14940 KB |
n=100 |
23 |
Correct |
2 ms |
14936 KB |
n=100 |
24 |
Correct |
3 ms |
14940 KB |
n=100 |
25 |
Correct |
3 ms |
14940 KB |
n=100 |
26 |
Correct |
3 ms |
14936 KB |
n=12 |
27 |
Correct |
3 ms |
14940 KB |
n=100 |
28 |
Correct |
3 ms |
14936 KB |
n=500 |
29 |
Correct |
3 ms |
15136 KB |
n=500 |
30 |
Correct |
3 ms |
14940 KB |
n=500 |
31 |
Correct |
3 ms |
14940 KB |
n=500 |
32 |
Correct |
4 ms |
14936 KB |
n=500 |
33 |
Correct |
3 ms |
14936 KB |
n=500 |
34 |
Correct |
3 ms |
14940 KB |
n=500 |
35 |
Correct |
3 ms |
14940 KB |
n=500 |
36 |
Correct |
3 ms |
14940 KB |
n=500 |
37 |
Correct |
3 ms |
14936 KB |
n=500 |
38 |
Correct |
5 ms |
14936 KB |
n=500 |
39 |
Correct |
3 ms |
14940 KB |
n=500 |
40 |
Correct |
3 ms |
15000 KB |
n=500 |
41 |
Correct |
3 ms |
14940 KB |
n=500 |
42 |
Correct |
3 ms |
14940 KB |
n=500 |
43 |
Correct |
3 ms |
14940 KB |
n=500 |
44 |
Correct |
3 ms |
14940 KB |
n=500 |
45 |
Correct |
3 ms |
14940 KB |
n=500 |
46 |
Correct |
3 ms |
15000 KB |
n=500 |
47 |
Correct |
3 ms |
14940 KB |
n=500 |
48 |
Correct |
3 ms |
14936 KB |
n=500 |
49 |
Correct |
3 ms |
14940 KB |
n=500 |
50 |
Correct |
3 ms |
14936 KB |
n=500 |
51 |
Correct |
3 ms |
15004 KB |
n=500 |
52 |
Correct |
3 ms |
14940 KB |
n=500 |
53 |
Correct |
3 ms |
14940 KB |
n=500 |
54 |
Correct |
3 ms |
14940 KB |
n=500 |
55 |
Correct |
3 ms |
14940 KB |
n=278 |
56 |
Correct |
3 ms |
14940 KB |
n=500 |
57 |
Correct |
3 ms |
14940 KB |
n=500 |
58 |
Correct |
3 ms |
14940 KB |
n=500 |
59 |
Correct |
5 ms |
15196 KB |
n=2000 |
60 |
Correct |
4 ms |
15196 KB |
n=2000 |
61 |
Correct |
5 ms |
15260 KB |
n=2000 |
62 |
Correct |
5 ms |
15192 KB |
n=2000 |
63 |
Correct |
5 ms |
15192 KB |
n=2000 |
64 |
Correct |
5 ms |
15196 KB |
n=2000 |
65 |
Correct |
5 ms |
15196 KB |
n=2000 |
66 |
Correct |
5 ms |
15196 KB |
n=2000 |
67 |
Correct |
5 ms |
15196 KB |
n=2000 |
68 |
Correct |
5 ms |
15196 KB |
n=2000 |
69 |
Correct |
4 ms |
15196 KB |
n=2000 |
70 |
Correct |
4 ms |
15196 KB |
n=2000 |
71 |
Correct |
5 ms |
15192 KB |
n=2000 |
72 |
Correct |
5 ms |
15292 KB |
n=2000 |
73 |
Correct |
4 ms |
15196 KB |
n=2000 |
74 |
Correct |
5 ms |
15192 KB |
n=1844 |
75 |
Correct |
4 ms |
15196 KB |
n=2000 |
76 |
Correct |
5 ms |
15120 KB |
n=2000 |
77 |
Correct |
5 ms |
15196 KB |
n=2000 |
78 |
Correct |
5 ms |
15196 KB |
n=2000 |
79 |
Correct |
5 ms |
15196 KB |
n=2000 |
80 |
Correct |
4 ms |
15292 KB |
n=2000 |
81 |
Correct |
5 ms |
15196 KB |
n=2000 |
82 |
Correct |
5 ms |
15192 KB |
n=2000 |
83 |
Correct |
5 ms |
15196 KB |
n=2000 |
84 |
Correct |
5 ms |
15196 KB |
n=2000 |
85 |
Correct |
5 ms |
15448 KB |
n=2000 |
86 |
Correct |
5 ms |
15212 KB |
n=2000 |
87 |
Correct |
5 ms |
15196 KB |
n=2000 |
88 |
Correct |
4 ms |
15196 KB |
n=2000 |
89 |
Correct |
4 ms |
15196 KB |
n=2000 |
90 |
Correct |
4 ms |
15196 KB |
n=2000 |
91 |
Correct |
4 ms |
15196 KB |
n=2000 |
92 |
Runtime error |
53 ms |
51708 KB |
Execution killed with signal 11 |
93 |
Halted |
0 ms |
0 KB |
- |