#include<bits/stdc++.h>
#include<fstream>
#pragma GCC optimize("Ofast,O3,unroll-loops")
#pragma GCC target("avx2")
using namespace std;
//ifstream fin("FEEDING.INP");
//ofstream fout("FEEDING.OUT");
#define sz(a) (int)a.size()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
const int base = 74;
const int mxn = 2e5 + 5;
int n, m, q;
vt<int>adj[mxn + 1];
int dep[mxn + 1], up[mxn + 1][18], a[mxn + 1], tin[mxn + 1], tt = 0, tout[mxn + 1], inf = 1e9;
void dfs(int s, int pre){
tin[s] = ++tt;
for(auto i: adj[s]){
if(i != pre){
dep[i] = dep[s] + 1;
dfs(i, s); up[i][0] = s;
}
}
tout[s] = tt;
}
int lca(int u, int v){
if(dep[u] < dep[v])swap(u, v);
int k = dep[u] - dep[v];
forr(i, 0, 18){
if(k & (1 << i)){
u = up[u][i];
}
}
if(u == v)return(u);
dorr(i, 17, 0){
if(up[u][i] != up[v][i]){
u = up[u][i]; v = up[v][i];
}
}
return(up[u][0]);
}
set<int>cand[mxn + 1], app[mxn + 1];
signed main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m >> q;
// if there exist answer, either its (i, i) or (i, i + 1)
forr(i, 1, n){
int u, v; cin >> u >> v;
adj[u].pb(v); adj[v].pb(u);
}
dfs(1, -1);
forr(i, 1, 18){
for(int j = 1; j <= n; j++){
up[j][i] = up[up[j][i - 1]][i - 1];
}
}
for(int i = 1; i <= m; i++){
cin >> a[i]; app[a[i]].insert(i);
}
for(int i = 2; i <= m; i++){
cand[lca(a[i - 1], a[i])].insert(i - 1);
}
while(q--){
int idq; cin >> idq;
if(idq == 1){
int id, x; cin >> id >> x;
if(id > 1)cand[lca(a[id - 1], a[id])].erase(id - 1);
if(id < m)cand[lca(a[id], a[id + 1])].erase(id);
app[a[id]].erase(id);
a[id] = x;
if(id > 1)cand[lca(a[id - 1], a[id])].insert(id - 1);
if(id < m)cand[lca(a[id], a[id + 1])].insert(id);
app[a[id]].insert(id);
}else{
int l, r, v; cin >> l >> r >> v;
auto it = app[v].lower_bound(l);
if(it != app[v].end() && *it <= r){
cout << *it << " " << *it << "\n";
}else{
auto it2 = cand[v].lower_bound(l);
if(it2 != cand[v].end() && *it2 < r){
cout << *it2 << " " << *it2 + 1 << "\n";
}else{
cout << -1 << " " << -1 << "\n";
}
}
}
}
return(0);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
n=5 |
2 |
Correct |
13 ms |
23816 KB |
n=100 |
3 |
Correct |
12 ms |
23764 KB |
n=100 |
4 |
Correct |
11 ms |
23764 KB |
n=100 |
5 |
Correct |
12 ms |
23816 KB |
n=100 |
6 |
Correct |
12 ms |
23852 KB |
n=100 |
7 |
Correct |
12 ms |
23768 KB |
n=100 |
8 |
Correct |
12 ms |
23764 KB |
n=100 |
9 |
Correct |
12 ms |
23816 KB |
n=100 |
10 |
Correct |
12 ms |
23744 KB |
n=100 |
11 |
Correct |
12 ms |
23816 KB |
n=100 |
12 |
Correct |
12 ms |
23764 KB |
n=100 |
13 |
Correct |
12 ms |
23812 KB |
n=100 |
14 |
Correct |
12 ms |
23736 KB |
n=100 |
15 |
Correct |
11 ms |
23816 KB |
n=100 |
16 |
Correct |
12 ms |
23764 KB |
n=100 |
17 |
Correct |
12 ms |
23812 KB |
n=100 |
18 |
Correct |
12 ms |
23816 KB |
n=100 |
19 |
Correct |
11 ms |
23764 KB |
n=100 |
20 |
Correct |
12 ms |
23764 KB |
n=100 |
21 |
Correct |
12 ms |
23764 KB |
n=100 |
22 |
Correct |
12 ms |
23744 KB |
n=100 |
23 |
Correct |
12 ms |
23764 KB |
n=100 |
24 |
Correct |
15 ms |
23936 KB |
n=100 |
25 |
Correct |
12 ms |
23764 KB |
n=100 |
26 |
Correct |
12 ms |
23764 KB |
n=12 |
27 |
Correct |
12 ms |
23824 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
n=5 |
2 |
Correct |
13 ms |
23816 KB |
n=100 |
3 |
Correct |
12 ms |
23764 KB |
n=100 |
4 |
Correct |
11 ms |
23764 KB |
n=100 |
5 |
Correct |
12 ms |
23816 KB |
n=100 |
6 |
Correct |
12 ms |
23852 KB |
n=100 |
7 |
Correct |
12 ms |
23768 KB |
n=100 |
8 |
Correct |
12 ms |
23764 KB |
n=100 |
9 |
Correct |
12 ms |
23816 KB |
n=100 |
10 |
Correct |
12 ms |
23744 KB |
n=100 |
11 |
Correct |
12 ms |
23816 KB |
n=100 |
12 |
Correct |
12 ms |
23764 KB |
n=100 |
13 |
Correct |
12 ms |
23812 KB |
n=100 |
14 |
Correct |
12 ms |
23736 KB |
n=100 |
15 |
Correct |
11 ms |
23816 KB |
n=100 |
16 |
Correct |
12 ms |
23764 KB |
n=100 |
17 |
Correct |
12 ms |
23812 KB |
n=100 |
18 |
Correct |
12 ms |
23816 KB |
n=100 |
19 |
Correct |
11 ms |
23764 KB |
n=100 |
20 |
Correct |
12 ms |
23764 KB |
n=100 |
21 |
Correct |
12 ms |
23764 KB |
n=100 |
22 |
Correct |
12 ms |
23744 KB |
n=100 |
23 |
Correct |
12 ms |
23764 KB |
n=100 |
24 |
Correct |
15 ms |
23936 KB |
n=100 |
25 |
Correct |
12 ms |
23764 KB |
n=100 |
26 |
Correct |
12 ms |
23764 KB |
n=12 |
27 |
Correct |
12 ms |
23824 KB |
n=100 |
28 |
Correct |
12 ms |
23940 KB |
n=500 |
29 |
Correct |
12 ms |
23900 KB |
n=500 |
30 |
Correct |
12 ms |
23952 KB |
n=500 |
31 |
Correct |
12 ms |
23892 KB |
n=500 |
32 |
Correct |
13 ms |
23948 KB |
n=500 |
33 |
Correct |
12 ms |
23952 KB |
n=500 |
34 |
Correct |
12 ms |
23948 KB |
n=500 |
35 |
Correct |
12 ms |
23896 KB |
n=500 |
36 |
Correct |
13 ms |
23892 KB |
n=500 |
37 |
Correct |
12 ms |
23892 KB |
n=500 |
38 |
Correct |
12 ms |
23864 KB |
n=500 |
39 |
Correct |
12 ms |
23892 KB |
n=500 |
40 |
Correct |
12 ms |
23948 KB |
n=500 |
41 |
Correct |
12 ms |
23892 KB |
n=500 |
42 |
Correct |
12 ms |
23904 KB |
n=500 |
43 |
Correct |
12 ms |
23928 KB |
n=500 |
44 |
Correct |
12 ms |
23892 KB |
n=500 |
45 |
Correct |
12 ms |
23948 KB |
n=500 |
46 |
Correct |
12 ms |
23952 KB |
n=500 |
47 |
Correct |
14 ms |
23988 KB |
n=500 |
48 |
Correct |
12 ms |
23892 KB |
n=500 |
49 |
Correct |
12 ms |
23892 KB |
n=500 |
50 |
Correct |
12 ms |
23892 KB |
n=500 |
51 |
Correct |
12 ms |
23892 KB |
n=500 |
52 |
Correct |
12 ms |
23892 KB |
n=500 |
53 |
Correct |
13 ms |
23952 KB |
n=500 |
54 |
Correct |
12 ms |
23896 KB |
n=500 |
55 |
Correct |
11 ms |
23832 KB |
n=278 |
56 |
Correct |
12 ms |
23892 KB |
n=500 |
57 |
Correct |
14 ms |
23952 KB |
n=500 |
58 |
Correct |
13 ms |
23892 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
n=5 |
2 |
Correct |
13 ms |
23816 KB |
n=100 |
3 |
Correct |
12 ms |
23764 KB |
n=100 |
4 |
Correct |
11 ms |
23764 KB |
n=100 |
5 |
Correct |
12 ms |
23816 KB |
n=100 |
6 |
Correct |
12 ms |
23852 KB |
n=100 |
7 |
Correct |
12 ms |
23768 KB |
n=100 |
8 |
Correct |
12 ms |
23764 KB |
n=100 |
9 |
Correct |
12 ms |
23816 KB |
n=100 |
10 |
Correct |
12 ms |
23744 KB |
n=100 |
11 |
Correct |
12 ms |
23816 KB |
n=100 |
12 |
Correct |
12 ms |
23764 KB |
n=100 |
13 |
Correct |
12 ms |
23812 KB |
n=100 |
14 |
Correct |
12 ms |
23736 KB |
n=100 |
15 |
Correct |
11 ms |
23816 KB |
n=100 |
16 |
Correct |
12 ms |
23764 KB |
n=100 |
17 |
Correct |
12 ms |
23812 KB |
n=100 |
18 |
Correct |
12 ms |
23816 KB |
n=100 |
19 |
Correct |
11 ms |
23764 KB |
n=100 |
20 |
Correct |
12 ms |
23764 KB |
n=100 |
21 |
Correct |
12 ms |
23764 KB |
n=100 |
22 |
Correct |
12 ms |
23744 KB |
n=100 |
23 |
Correct |
12 ms |
23764 KB |
n=100 |
24 |
Correct |
15 ms |
23936 KB |
n=100 |
25 |
Correct |
12 ms |
23764 KB |
n=100 |
26 |
Correct |
12 ms |
23764 KB |
n=12 |
27 |
Correct |
12 ms |
23824 KB |
n=100 |
28 |
Correct |
12 ms |
23940 KB |
n=500 |
29 |
Correct |
12 ms |
23900 KB |
n=500 |
30 |
Correct |
12 ms |
23952 KB |
n=500 |
31 |
Correct |
12 ms |
23892 KB |
n=500 |
32 |
Correct |
13 ms |
23948 KB |
n=500 |
33 |
Correct |
12 ms |
23952 KB |
n=500 |
34 |
Correct |
12 ms |
23948 KB |
n=500 |
35 |
Correct |
12 ms |
23896 KB |
n=500 |
36 |
Correct |
13 ms |
23892 KB |
n=500 |
37 |
Correct |
12 ms |
23892 KB |
n=500 |
38 |
Correct |
12 ms |
23864 KB |
n=500 |
39 |
Correct |
12 ms |
23892 KB |
n=500 |
40 |
Correct |
12 ms |
23948 KB |
n=500 |
41 |
Correct |
12 ms |
23892 KB |
n=500 |
42 |
Correct |
12 ms |
23904 KB |
n=500 |
43 |
Correct |
12 ms |
23928 KB |
n=500 |
44 |
Correct |
12 ms |
23892 KB |
n=500 |
45 |
Correct |
12 ms |
23948 KB |
n=500 |
46 |
Correct |
12 ms |
23952 KB |
n=500 |
47 |
Correct |
14 ms |
23988 KB |
n=500 |
48 |
Correct |
12 ms |
23892 KB |
n=500 |
49 |
Correct |
12 ms |
23892 KB |
n=500 |
50 |
Correct |
12 ms |
23892 KB |
n=500 |
51 |
Correct |
12 ms |
23892 KB |
n=500 |
52 |
Correct |
12 ms |
23892 KB |
n=500 |
53 |
Correct |
13 ms |
23952 KB |
n=500 |
54 |
Correct |
12 ms |
23896 KB |
n=500 |
55 |
Correct |
11 ms |
23832 KB |
n=278 |
56 |
Correct |
12 ms |
23892 KB |
n=500 |
57 |
Correct |
14 ms |
23952 KB |
n=500 |
58 |
Correct |
13 ms |
23892 KB |
n=500 |
59 |
Correct |
13 ms |
24208 KB |
n=2000 |
60 |
Correct |
15 ms |
24276 KB |
n=2000 |
61 |
Correct |
14 ms |
24336 KB |
n=2000 |
62 |
Correct |
14 ms |
24256 KB |
n=2000 |
63 |
Correct |
14 ms |
24208 KB |
n=2000 |
64 |
Correct |
15 ms |
24264 KB |
n=2000 |
65 |
Correct |
14 ms |
24276 KB |
n=2000 |
66 |
Correct |
14 ms |
24276 KB |
n=2000 |
67 |
Correct |
16 ms |
24276 KB |
n=2000 |
68 |
Correct |
14 ms |
24336 KB |
n=2000 |
69 |
Correct |
15 ms |
24276 KB |
n=2000 |
70 |
Correct |
13 ms |
24208 KB |
n=2000 |
71 |
Correct |
15 ms |
24276 KB |
n=2000 |
72 |
Correct |
14 ms |
24304 KB |
n=2000 |
73 |
Correct |
14 ms |
24288 KB |
n=2000 |
74 |
Correct |
14 ms |
24276 KB |
n=1844 |
75 |
Correct |
14 ms |
24200 KB |
n=2000 |
76 |
Correct |
14 ms |
24216 KB |
n=2000 |
77 |
Correct |
14 ms |
24212 KB |
n=2000 |
78 |
Correct |
14 ms |
24276 KB |
n=2000 |
79 |
Correct |
13 ms |
24208 KB |
n=2000 |
80 |
Correct |
15 ms |
24276 KB |
n=2000 |
81 |
Correct |
14 ms |
24340 KB |
n=2000 |
82 |
Correct |
14 ms |
24276 KB |
n=2000 |
83 |
Correct |
14 ms |
24356 KB |
n=2000 |
84 |
Correct |
14 ms |
24296 KB |
n=2000 |
85 |
Correct |
14 ms |
24288 KB |
n=2000 |
86 |
Correct |
14 ms |
24276 KB |
n=2000 |
87 |
Correct |
15 ms |
24228 KB |
n=2000 |
88 |
Correct |
14 ms |
24272 KB |
n=2000 |
89 |
Correct |
14 ms |
24276 KB |
n=2000 |
90 |
Correct |
14 ms |
24356 KB |
n=2000 |
91 |
Correct |
14 ms |
24208 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
n=5 |
2 |
Correct |
13 ms |
23816 KB |
n=100 |
3 |
Correct |
12 ms |
23764 KB |
n=100 |
4 |
Correct |
11 ms |
23764 KB |
n=100 |
5 |
Correct |
12 ms |
23816 KB |
n=100 |
6 |
Correct |
12 ms |
23852 KB |
n=100 |
7 |
Correct |
12 ms |
23768 KB |
n=100 |
8 |
Correct |
12 ms |
23764 KB |
n=100 |
9 |
Correct |
12 ms |
23816 KB |
n=100 |
10 |
Correct |
12 ms |
23744 KB |
n=100 |
11 |
Correct |
12 ms |
23816 KB |
n=100 |
12 |
Correct |
12 ms |
23764 KB |
n=100 |
13 |
Correct |
12 ms |
23812 KB |
n=100 |
14 |
Correct |
12 ms |
23736 KB |
n=100 |
15 |
Correct |
11 ms |
23816 KB |
n=100 |
16 |
Correct |
12 ms |
23764 KB |
n=100 |
17 |
Correct |
12 ms |
23812 KB |
n=100 |
18 |
Correct |
12 ms |
23816 KB |
n=100 |
19 |
Correct |
11 ms |
23764 KB |
n=100 |
20 |
Correct |
12 ms |
23764 KB |
n=100 |
21 |
Correct |
12 ms |
23764 KB |
n=100 |
22 |
Correct |
12 ms |
23744 KB |
n=100 |
23 |
Correct |
12 ms |
23764 KB |
n=100 |
24 |
Correct |
15 ms |
23936 KB |
n=100 |
25 |
Correct |
12 ms |
23764 KB |
n=100 |
26 |
Correct |
12 ms |
23764 KB |
n=12 |
27 |
Correct |
12 ms |
23824 KB |
n=100 |
28 |
Correct |
12 ms |
23940 KB |
n=500 |
29 |
Correct |
12 ms |
23900 KB |
n=500 |
30 |
Correct |
12 ms |
23952 KB |
n=500 |
31 |
Correct |
12 ms |
23892 KB |
n=500 |
32 |
Correct |
13 ms |
23948 KB |
n=500 |
33 |
Correct |
12 ms |
23952 KB |
n=500 |
34 |
Correct |
12 ms |
23948 KB |
n=500 |
35 |
Correct |
12 ms |
23896 KB |
n=500 |
36 |
Correct |
13 ms |
23892 KB |
n=500 |
37 |
Correct |
12 ms |
23892 KB |
n=500 |
38 |
Correct |
12 ms |
23864 KB |
n=500 |
39 |
Correct |
12 ms |
23892 KB |
n=500 |
40 |
Correct |
12 ms |
23948 KB |
n=500 |
41 |
Correct |
12 ms |
23892 KB |
n=500 |
42 |
Correct |
12 ms |
23904 KB |
n=500 |
43 |
Correct |
12 ms |
23928 KB |
n=500 |
44 |
Correct |
12 ms |
23892 KB |
n=500 |
45 |
Correct |
12 ms |
23948 KB |
n=500 |
46 |
Correct |
12 ms |
23952 KB |
n=500 |
47 |
Correct |
14 ms |
23988 KB |
n=500 |
48 |
Correct |
12 ms |
23892 KB |
n=500 |
49 |
Correct |
12 ms |
23892 KB |
n=500 |
50 |
Correct |
12 ms |
23892 KB |
n=500 |
51 |
Correct |
12 ms |
23892 KB |
n=500 |
52 |
Correct |
12 ms |
23892 KB |
n=500 |
53 |
Correct |
13 ms |
23952 KB |
n=500 |
54 |
Correct |
12 ms |
23896 KB |
n=500 |
55 |
Correct |
11 ms |
23832 KB |
n=278 |
56 |
Correct |
12 ms |
23892 KB |
n=500 |
57 |
Correct |
14 ms |
23952 KB |
n=500 |
58 |
Correct |
13 ms |
23892 KB |
n=500 |
59 |
Correct |
13 ms |
24208 KB |
n=2000 |
60 |
Correct |
15 ms |
24276 KB |
n=2000 |
61 |
Correct |
14 ms |
24336 KB |
n=2000 |
62 |
Correct |
14 ms |
24256 KB |
n=2000 |
63 |
Correct |
14 ms |
24208 KB |
n=2000 |
64 |
Correct |
15 ms |
24264 KB |
n=2000 |
65 |
Correct |
14 ms |
24276 KB |
n=2000 |
66 |
Correct |
14 ms |
24276 KB |
n=2000 |
67 |
Correct |
16 ms |
24276 KB |
n=2000 |
68 |
Correct |
14 ms |
24336 KB |
n=2000 |
69 |
Correct |
15 ms |
24276 KB |
n=2000 |
70 |
Correct |
13 ms |
24208 KB |
n=2000 |
71 |
Correct |
15 ms |
24276 KB |
n=2000 |
72 |
Correct |
14 ms |
24304 KB |
n=2000 |
73 |
Correct |
14 ms |
24288 KB |
n=2000 |
74 |
Correct |
14 ms |
24276 KB |
n=1844 |
75 |
Correct |
14 ms |
24200 KB |
n=2000 |
76 |
Correct |
14 ms |
24216 KB |
n=2000 |
77 |
Correct |
14 ms |
24212 KB |
n=2000 |
78 |
Correct |
14 ms |
24276 KB |
n=2000 |
79 |
Correct |
13 ms |
24208 KB |
n=2000 |
80 |
Correct |
15 ms |
24276 KB |
n=2000 |
81 |
Correct |
14 ms |
24340 KB |
n=2000 |
82 |
Correct |
14 ms |
24276 KB |
n=2000 |
83 |
Correct |
14 ms |
24356 KB |
n=2000 |
84 |
Correct |
14 ms |
24296 KB |
n=2000 |
85 |
Correct |
14 ms |
24288 KB |
n=2000 |
86 |
Correct |
14 ms |
24276 KB |
n=2000 |
87 |
Correct |
15 ms |
24228 KB |
n=2000 |
88 |
Correct |
14 ms |
24272 KB |
n=2000 |
89 |
Correct |
14 ms |
24276 KB |
n=2000 |
90 |
Correct |
14 ms |
24356 KB |
n=2000 |
91 |
Correct |
14 ms |
24208 KB |
n=2000 |
92 |
Correct |
539 ms |
68876 KB |
n=200000 |
93 |
Correct |
695 ms |
78224 KB |
n=200000 |
94 |
Correct |
618 ms |
80724 KB |
n=200000 |
95 |
Correct |
582 ms |
74292 KB |
n=200000 |
96 |
Correct |
524 ms |
74464 KB |
n=200000 |
97 |
Correct |
939 ms |
77584 KB |
n=200000 |
98 |
Correct |
666 ms |
74300 KB |
n=200000 |
99 |
Correct |
637 ms |
74528 KB |
n=200000 |
100 |
Correct |
598 ms |
74352 KB |
n=200000 |
101 |
Correct |
762 ms |
81560 KB |
n=200000 |
102 |
Correct |
341 ms |
75528 KB |
n=200000 |
103 |
Correct |
306 ms |
75548 KB |
n=200000 |
104 |
Correct |
348 ms |
75556 KB |
n=200000 |
105 |
Correct |
303 ms |
75936 KB |
n=200000 |
106 |
Correct |
326 ms |
75920 KB |
n=200000 |
107 |
Correct |
300 ms |
75904 KB |
n=200000 |
108 |
Correct |
557 ms |
74444 KB |
n=200000 |
109 |
Correct |
563 ms |
74356 KB |
n=200000 |
110 |
Correct |
563 ms |
74356 KB |
n=200000 |
111 |
Correct |
538 ms |
73932 KB |
n=200000 |
112 |
Correct |
633 ms |
80948 KB |
n=200000 |
113 |
Correct |
703 ms |
77688 KB |
n=200000 |
114 |
Correct |
499 ms |
73932 KB |
n=200000 |
115 |
Correct |
747 ms |
76060 KB |
n=200000 |
116 |
Correct |
493 ms |
74548 KB |
n=200000 |
117 |
Correct |
609 ms |
81092 KB |
n=200000 |
118 |
Correct |
705 ms |
76620 KB |
n=200000 |
119 |
Correct |
492 ms |
74540 KB |
n=200000 |
120 |
Correct |
559 ms |
80588 KB |
n=200000 |
121 |
Correct |
547 ms |
80600 KB |
n=200000 |
122 |
Correct |
541 ms |
80872 KB |
n=200000 |
123 |
Correct |
282 ms |
75732 KB |
n=200000 |
124 |
Correct |
124 ms |
38416 KB |
n=25264 |