#include <bits/stdc++.h>
#pragma GCC optimize("O3", "unroll-loops")
#define ll long long
#define int long long
#define pb push_back
#define fi first
#define se second
#define lf (id<<1)
#define rg ((id<<1)|1)
#define md ((l+r)>>1)
#define ld long double
using namespace std;
typedef pair<int,int> pii;
typedef pair<pii, int> ipii;
const int MAXN = 2e5+10;
const int MAXA = 2e3+10;
const int INF = 1e18+10;
const int LOG = 19;
const int MOD = 1e9+7;
const int SQRT = 450;
const vector<int> NOL = {};
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const vector<int> dx = {1, -1, 0, 0};
const vector<int> dy = {0, 0, 1, -1};
int n, m, q;
int a[MAXN];
vector <int> adj[MAXN];
bool b[MAXN];
int anc[MAXN][LOG+5], dep[MAXN];
set <int> s[MAXN], t[MAXN];
void dfs(int nw, int par){
anc[nw][0] = par; dep[nw] = dep[par]+1;
for(auto nx : adj[nw]){
if(nx==par) continue;
dfs(nx, nw);
}
}
int LCA(int x, int y){
if(dep[x] > dep[y]) swap(x, y);
for(int i=LOG-1; i>=0; i--){
if(dep[anc[y][i]] >= dep[x])
y = anc[y][i];
}
if(x==y) return x;
for(int i=LOG-1; i>=0; i--){
if(anc[x][i] != anc[y][i]){
x = anc[x][i]; y = anc[y][i];
}
}
return anc[x][0];
}
signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n >> m >> q;
for(int i=1; i<=n-1; i++){
int x, y; cin >> x >> y;
adj[x].pb(y); adj[y].pb(x);
}
dfs(1, 0);
for(int j=1; j<LOG; j++)
for(int i=1; i<=n; i++)
anc[i][j] = anc[anc[i][j-1]][j-1];
for(int i=1; i<=m; i++) cin >> a[i];
for(int i=1; i<=m; i++){
s[a[i]].insert(i);
if(i!=m) t[LCA(a[i], a[i+1])].insert(i);
}
for(int xx=1; xx<=q; xx++){
int ty; cin >> ty;
if(ty==1){
int p, x; cin >> p >> x;
s[a[p]].erase(p);
if(p != 1) t[LCA(a[p-1], a[p])].erase(p-1);
if(p != m) t[LCA(a[p], a[p+1])].erase(p);
a[p] = x;
s[a[p]].insert(p);
if(p != 1) t[LCA(a[p-1], a[p])].insert(p-1);
if(p != m) t[LCA(a[p], a[p+1])].insert(p);
continue;
}
int l, r, x; cin >> l >> r >> x;
auto it = s[x].lower_bound(l);
if(it!=s[x].end() && l<=(*it) && (*it)<=r){
cout << (*it) << ' ' << (*it) << '\n';
continue;
}
it = t[x].lower_bound(l);
if(it!=t[x].end() && l<=(*it) && (*it)+1<=r){
cout << (*it) << ' ' << (*it)+1 << '\n';
continue;
}
cout << "-1 -1\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
27228 KB |
n=5 |
2 |
Correct |
4 ms |
27228 KB |
n=100 |
3 |
Correct |
4 ms |
27228 KB |
n=100 |
4 |
Correct |
4 ms |
27280 KB |
n=100 |
5 |
Correct |
4 ms |
27228 KB |
n=100 |
6 |
Correct |
4 ms |
27228 KB |
n=100 |
7 |
Correct |
4 ms |
27228 KB |
n=100 |
8 |
Correct |
4 ms |
27228 KB |
n=100 |
9 |
Correct |
4 ms |
27228 KB |
n=100 |
10 |
Correct |
4 ms |
27224 KB |
n=100 |
11 |
Correct |
4 ms |
27092 KB |
n=100 |
12 |
Correct |
5 ms |
27228 KB |
n=100 |
13 |
Correct |
4 ms |
27272 KB |
n=100 |
14 |
Correct |
4 ms |
27228 KB |
n=100 |
15 |
Correct |
4 ms |
27228 KB |
n=100 |
16 |
Correct |
5 ms |
27228 KB |
n=100 |
17 |
Correct |
4 ms |
27224 KB |
n=100 |
18 |
Correct |
4 ms |
27272 KB |
n=100 |
19 |
Correct |
4 ms |
27476 KB |
n=100 |
20 |
Correct |
5 ms |
27228 KB |
n=100 |
21 |
Correct |
4 ms |
27224 KB |
n=100 |
22 |
Correct |
5 ms |
27084 KB |
n=100 |
23 |
Correct |
4 ms |
27228 KB |
n=100 |
24 |
Correct |
4 ms |
27224 KB |
n=100 |
25 |
Correct |
4 ms |
27228 KB |
n=100 |
26 |
Correct |
4 ms |
27228 KB |
n=12 |
27 |
Correct |
4 ms |
27224 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
27228 KB |
n=5 |
2 |
Correct |
4 ms |
27228 KB |
n=100 |
3 |
Correct |
4 ms |
27228 KB |
n=100 |
4 |
Correct |
4 ms |
27280 KB |
n=100 |
5 |
Correct |
4 ms |
27228 KB |
n=100 |
6 |
Correct |
4 ms |
27228 KB |
n=100 |
7 |
Correct |
4 ms |
27228 KB |
n=100 |
8 |
Correct |
4 ms |
27228 KB |
n=100 |
9 |
Correct |
4 ms |
27228 KB |
n=100 |
10 |
Correct |
4 ms |
27224 KB |
n=100 |
11 |
Correct |
4 ms |
27092 KB |
n=100 |
12 |
Correct |
5 ms |
27228 KB |
n=100 |
13 |
Correct |
4 ms |
27272 KB |
n=100 |
14 |
Correct |
4 ms |
27228 KB |
n=100 |
15 |
Correct |
4 ms |
27228 KB |
n=100 |
16 |
Correct |
5 ms |
27228 KB |
n=100 |
17 |
Correct |
4 ms |
27224 KB |
n=100 |
18 |
Correct |
4 ms |
27272 KB |
n=100 |
19 |
Correct |
4 ms |
27476 KB |
n=100 |
20 |
Correct |
5 ms |
27228 KB |
n=100 |
21 |
Correct |
4 ms |
27224 KB |
n=100 |
22 |
Correct |
5 ms |
27084 KB |
n=100 |
23 |
Correct |
4 ms |
27228 KB |
n=100 |
24 |
Correct |
4 ms |
27224 KB |
n=100 |
25 |
Correct |
4 ms |
27228 KB |
n=100 |
26 |
Correct |
4 ms |
27228 KB |
n=12 |
27 |
Correct |
4 ms |
27224 KB |
n=100 |
28 |
Correct |
5 ms |
27228 KB |
n=500 |
29 |
Correct |
5 ms |
27228 KB |
n=500 |
30 |
Correct |
5 ms |
27228 KB |
n=500 |
31 |
Correct |
4 ms |
27228 KB |
n=500 |
32 |
Correct |
5 ms |
27228 KB |
n=500 |
33 |
Correct |
4 ms |
27336 KB |
n=500 |
34 |
Correct |
4 ms |
27228 KB |
n=500 |
35 |
Correct |
5 ms |
27224 KB |
n=500 |
36 |
Correct |
4 ms |
27228 KB |
n=500 |
37 |
Correct |
4 ms |
27228 KB |
n=500 |
38 |
Correct |
4 ms |
27228 KB |
n=500 |
39 |
Correct |
4 ms |
27324 KB |
n=500 |
40 |
Correct |
4 ms |
27228 KB |
n=500 |
41 |
Correct |
5 ms |
27228 KB |
n=500 |
42 |
Correct |
4 ms |
27228 KB |
n=500 |
43 |
Correct |
4 ms |
27224 KB |
n=500 |
44 |
Correct |
4 ms |
27228 KB |
n=500 |
45 |
Correct |
4 ms |
27224 KB |
n=500 |
46 |
Correct |
4 ms |
27228 KB |
n=500 |
47 |
Correct |
5 ms |
27228 KB |
n=500 |
48 |
Correct |
4 ms |
27228 KB |
n=500 |
49 |
Correct |
5 ms |
27224 KB |
n=500 |
50 |
Correct |
5 ms |
27228 KB |
n=500 |
51 |
Correct |
5 ms |
27228 KB |
n=500 |
52 |
Correct |
5 ms |
27224 KB |
n=500 |
53 |
Correct |
4 ms |
27228 KB |
n=500 |
54 |
Correct |
4 ms |
27228 KB |
n=500 |
55 |
Correct |
4 ms |
27228 KB |
n=278 |
56 |
Correct |
4 ms |
27228 KB |
n=500 |
57 |
Correct |
5 ms |
27228 KB |
n=500 |
58 |
Correct |
4 ms |
27228 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
27228 KB |
n=5 |
2 |
Correct |
4 ms |
27228 KB |
n=100 |
3 |
Correct |
4 ms |
27228 KB |
n=100 |
4 |
Correct |
4 ms |
27280 KB |
n=100 |
5 |
Correct |
4 ms |
27228 KB |
n=100 |
6 |
Correct |
4 ms |
27228 KB |
n=100 |
7 |
Correct |
4 ms |
27228 KB |
n=100 |
8 |
Correct |
4 ms |
27228 KB |
n=100 |
9 |
Correct |
4 ms |
27228 KB |
n=100 |
10 |
Correct |
4 ms |
27224 KB |
n=100 |
11 |
Correct |
4 ms |
27092 KB |
n=100 |
12 |
Correct |
5 ms |
27228 KB |
n=100 |
13 |
Correct |
4 ms |
27272 KB |
n=100 |
14 |
Correct |
4 ms |
27228 KB |
n=100 |
15 |
Correct |
4 ms |
27228 KB |
n=100 |
16 |
Correct |
5 ms |
27228 KB |
n=100 |
17 |
Correct |
4 ms |
27224 KB |
n=100 |
18 |
Correct |
4 ms |
27272 KB |
n=100 |
19 |
Correct |
4 ms |
27476 KB |
n=100 |
20 |
Correct |
5 ms |
27228 KB |
n=100 |
21 |
Correct |
4 ms |
27224 KB |
n=100 |
22 |
Correct |
5 ms |
27084 KB |
n=100 |
23 |
Correct |
4 ms |
27228 KB |
n=100 |
24 |
Correct |
4 ms |
27224 KB |
n=100 |
25 |
Correct |
4 ms |
27228 KB |
n=100 |
26 |
Correct |
4 ms |
27228 KB |
n=12 |
27 |
Correct |
4 ms |
27224 KB |
n=100 |
28 |
Correct |
5 ms |
27228 KB |
n=500 |
29 |
Correct |
5 ms |
27228 KB |
n=500 |
30 |
Correct |
5 ms |
27228 KB |
n=500 |
31 |
Correct |
4 ms |
27228 KB |
n=500 |
32 |
Correct |
5 ms |
27228 KB |
n=500 |
33 |
Correct |
4 ms |
27336 KB |
n=500 |
34 |
Correct |
4 ms |
27228 KB |
n=500 |
35 |
Correct |
5 ms |
27224 KB |
n=500 |
36 |
Correct |
4 ms |
27228 KB |
n=500 |
37 |
Correct |
4 ms |
27228 KB |
n=500 |
38 |
Correct |
4 ms |
27228 KB |
n=500 |
39 |
Correct |
4 ms |
27324 KB |
n=500 |
40 |
Correct |
4 ms |
27228 KB |
n=500 |
41 |
Correct |
5 ms |
27228 KB |
n=500 |
42 |
Correct |
4 ms |
27228 KB |
n=500 |
43 |
Correct |
4 ms |
27224 KB |
n=500 |
44 |
Correct |
4 ms |
27228 KB |
n=500 |
45 |
Correct |
4 ms |
27224 KB |
n=500 |
46 |
Correct |
4 ms |
27228 KB |
n=500 |
47 |
Correct |
5 ms |
27228 KB |
n=500 |
48 |
Correct |
4 ms |
27228 KB |
n=500 |
49 |
Correct |
5 ms |
27224 KB |
n=500 |
50 |
Correct |
5 ms |
27228 KB |
n=500 |
51 |
Correct |
5 ms |
27228 KB |
n=500 |
52 |
Correct |
5 ms |
27224 KB |
n=500 |
53 |
Correct |
4 ms |
27228 KB |
n=500 |
54 |
Correct |
4 ms |
27228 KB |
n=500 |
55 |
Correct |
4 ms |
27228 KB |
n=278 |
56 |
Correct |
4 ms |
27228 KB |
n=500 |
57 |
Correct |
5 ms |
27228 KB |
n=500 |
58 |
Correct |
4 ms |
27228 KB |
n=500 |
59 |
Correct |
7 ms |
29532 KB |
n=2000 |
60 |
Correct |
6 ms |
29532 KB |
n=2000 |
61 |
Correct |
6 ms |
29532 KB |
n=2000 |
62 |
Correct |
7 ms |
29528 KB |
n=2000 |
63 |
Correct |
6 ms |
29532 KB |
n=2000 |
64 |
Correct |
7 ms |
29532 KB |
n=2000 |
65 |
Correct |
6 ms |
29532 KB |
n=2000 |
66 |
Correct |
6 ms |
29532 KB |
n=2000 |
67 |
Correct |
7 ms |
29532 KB |
n=2000 |
68 |
Correct |
6 ms |
29532 KB |
n=2000 |
69 |
Correct |
6 ms |
29528 KB |
n=2000 |
70 |
Correct |
6 ms |
29532 KB |
n=2000 |
71 |
Correct |
5 ms |
29624 KB |
n=2000 |
72 |
Correct |
5 ms |
29532 KB |
n=2000 |
73 |
Correct |
5 ms |
29528 KB |
n=2000 |
74 |
Correct |
5 ms |
29532 KB |
n=1844 |
75 |
Correct |
5 ms |
29532 KB |
n=2000 |
76 |
Correct |
6 ms |
29608 KB |
n=2000 |
77 |
Correct |
7 ms |
29780 KB |
n=2000 |
78 |
Correct |
6 ms |
29532 KB |
n=2000 |
79 |
Correct |
7 ms |
29532 KB |
n=2000 |
80 |
Correct |
6 ms |
29532 KB |
n=2000 |
81 |
Correct |
7 ms |
29644 KB |
n=2000 |
82 |
Correct |
7 ms |
29528 KB |
n=2000 |
83 |
Correct |
7 ms |
29580 KB |
n=2000 |
84 |
Correct |
7 ms |
29532 KB |
n=2000 |
85 |
Correct |
8 ms |
29532 KB |
n=2000 |
86 |
Correct |
6 ms |
29528 KB |
n=2000 |
87 |
Correct |
6 ms |
29784 KB |
n=2000 |
88 |
Correct |
6 ms |
29672 KB |
n=2000 |
89 |
Correct |
7 ms |
29532 KB |
n=2000 |
90 |
Correct |
6 ms |
29544 KB |
n=2000 |
91 |
Correct |
6 ms |
29532 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
27228 KB |
n=5 |
2 |
Correct |
4 ms |
27228 KB |
n=100 |
3 |
Correct |
4 ms |
27228 KB |
n=100 |
4 |
Correct |
4 ms |
27280 KB |
n=100 |
5 |
Correct |
4 ms |
27228 KB |
n=100 |
6 |
Correct |
4 ms |
27228 KB |
n=100 |
7 |
Correct |
4 ms |
27228 KB |
n=100 |
8 |
Correct |
4 ms |
27228 KB |
n=100 |
9 |
Correct |
4 ms |
27228 KB |
n=100 |
10 |
Correct |
4 ms |
27224 KB |
n=100 |
11 |
Correct |
4 ms |
27092 KB |
n=100 |
12 |
Correct |
5 ms |
27228 KB |
n=100 |
13 |
Correct |
4 ms |
27272 KB |
n=100 |
14 |
Correct |
4 ms |
27228 KB |
n=100 |
15 |
Correct |
4 ms |
27228 KB |
n=100 |
16 |
Correct |
5 ms |
27228 KB |
n=100 |
17 |
Correct |
4 ms |
27224 KB |
n=100 |
18 |
Correct |
4 ms |
27272 KB |
n=100 |
19 |
Correct |
4 ms |
27476 KB |
n=100 |
20 |
Correct |
5 ms |
27228 KB |
n=100 |
21 |
Correct |
4 ms |
27224 KB |
n=100 |
22 |
Correct |
5 ms |
27084 KB |
n=100 |
23 |
Correct |
4 ms |
27228 KB |
n=100 |
24 |
Correct |
4 ms |
27224 KB |
n=100 |
25 |
Correct |
4 ms |
27228 KB |
n=100 |
26 |
Correct |
4 ms |
27228 KB |
n=12 |
27 |
Correct |
4 ms |
27224 KB |
n=100 |
28 |
Correct |
5 ms |
27228 KB |
n=500 |
29 |
Correct |
5 ms |
27228 KB |
n=500 |
30 |
Correct |
5 ms |
27228 KB |
n=500 |
31 |
Correct |
4 ms |
27228 KB |
n=500 |
32 |
Correct |
5 ms |
27228 KB |
n=500 |
33 |
Correct |
4 ms |
27336 KB |
n=500 |
34 |
Correct |
4 ms |
27228 KB |
n=500 |
35 |
Correct |
5 ms |
27224 KB |
n=500 |
36 |
Correct |
4 ms |
27228 KB |
n=500 |
37 |
Correct |
4 ms |
27228 KB |
n=500 |
38 |
Correct |
4 ms |
27228 KB |
n=500 |
39 |
Correct |
4 ms |
27324 KB |
n=500 |
40 |
Correct |
4 ms |
27228 KB |
n=500 |
41 |
Correct |
5 ms |
27228 KB |
n=500 |
42 |
Correct |
4 ms |
27228 KB |
n=500 |
43 |
Correct |
4 ms |
27224 KB |
n=500 |
44 |
Correct |
4 ms |
27228 KB |
n=500 |
45 |
Correct |
4 ms |
27224 KB |
n=500 |
46 |
Correct |
4 ms |
27228 KB |
n=500 |
47 |
Correct |
5 ms |
27228 KB |
n=500 |
48 |
Correct |
4 ms |
27228 KB |
n=500 |
49 |
Correct |
5 ms |
27224 KB |
n=500 |
50 |
Correct |
5 ms |
27228 KB |
n=500 |
51 |
Correct |
5 ms |
27228 KB |
n=500 |
52 |
Correct |
5 ms |
27224 KB |
n=500 |
53 |
Correct |
4 ms |
27228 KB |
n=500 |
54 |
Correct |
4 ms |
27228 KB |
n=500 |
55 |
Correct |
4 ms |
27228 KB |
n=278 |
56 |
Correct |
4 ms |
27228 KB |
n=500 |
57 |
Correct |
5 ms |
27228 KB |
n=500 |
58 |
Correct |
4 ms |
27228 KB |
n=500 |
59 |
Correct |
7 ms |
29532 KB |
n=2000 |
60 |
Correct |
6 ms |
29532 KB |
n=2000 |
61 |
Correct |
6 ms |
29532 KB |
n=2000 |
62 |
Correct |
7 ms |
29528 KB |
n=2000 |
63 |
Correct |
6 ms |
29532 KB |
n=2000 |
64 |
Correct |
7 ms |
29532 KB |
n=2000 |
65 |
Correct |
6 ms |
29532 KB |
n=2000 |
66 |
Correct |
6 ms |
29532 KB |
n=2000 |
67 |
Correct |
7 ms |
29532 KB |
n=2000 |
68 |
Correct |
6 ms |
29532 KB |
n=2000 |
69 |
Correct |
6 ms |
29528 KB |
n=2000 |
70 |
Correct |
6 ms |
29532 KB |
n=2000 |
71 |
Correct |
5 ms |
29624 KB |
n=2000 |
72 |
Correct |
5 ms |
29532 KB |
n=2000 |
73 |
Correct |
5 ms |
29528 KB |
n=2000 |
74 |
Correct |
5 ms |
29532 KB |
n=1844 |
75 |
Correct |
5 ms |
29532 KB |
n=2000 |
76 |
Correct |
6 ms |
29608 KB |
n=2000 |
77 |
Correct |
7 ms |
29780 KB |
n=2000 |
78 |
Correct |
6 ms |
29532 KB |
n=2000 |
79 |
Correct |
7 ms |
29532 KB |
n=2000 |
80 |
Correct |
6 ms |
29532 KB |
n=2000 |
81 |
Correct |
7 ms |
29644 KB |
n=2000 |
82 |
Correct |
7 ms |
29528 KB |
n=2000 |
83 |
Correct |
7 ms |
29580 KB |
n=2000 |
84 |
Correct |
7 ms |
29532 KB |
n=2000 |
85 |
Correct |
8 ms |
29532 KB |
n=2000 |
86 |
Correct |
6 ms |
29528 KB |
n=2000 |
87 |
Correct |
6 ms |
29784 KB |
n=2000 |
88 |
Correct |
6 ms |
29672 KB |
n=2000 |
89 |
Correct |
7 ms |
29532 KB |
n=2000 |
90 |
Correct |
6 ms |
29544 KB |
n=2000 |
91 |
Correct |
6 ms |
29532 KB |
n=2000 |
92 |
Correct |
429 ms |
95564 KB |
n=200000 |
93 |
Correct |
720 ms |
101968 KB |
n=200000 |
94 |
Correct |
735 ms |
103504 KB |
n=200000 |
95 |
Correct |
423 ms |
98752 KB |
n=200000 |
96 |
Correct |
374 ms |
98920 KB |
n=200000 |
97 |
Correct |
665 ms |
101568 KB |
n=200000 |
98 |
Correct |
411 ms |
98964 KB |
n=200000 |
99 |
Correct |
532 ms |
99208 KB |
n=200000 |
100 |
Correct |
395 ms |
98944 KB |
n=200000 |
101 |
Correct |
770 ms |
104016 KB |
n=200000 |
102 |
Correct |
255 ms |
100248 KB |
n=200000 |
103 |
Correct |
256 ms |
100180 KB |
n=200000 |
104 |
Correct |
249 ms |
100176 KB |
n=200000 |
105 |
Correct |
287 ms |
100688 KB |
n=200000 |
106 |
Correct |
238 ms |
100760 KB |
n=200000 |
107 |
Correct |
262 ms |
100692 KB |
n=200000 |
108 |
Correct |
469 ms |
99152 KB |
n=200000 |
109 |
Correct |
476 ms |
99156 KB |
n=200000 |
110 |
Correct |
503 ms |
99156 KB |
n=200000 |
111 |
Correct |
429 ms |
98320 KB |
n=200000 |
112 |
Correct |
708 ms |
103760 KB |
n=200000 |
113 |
Correct |
656 ms |
101676 KB |
n=200000 |
114 |
Correct |
403 ms |
98496 KB |
n=200000 |
115 |
Correct |
627 ms |
100432 KB |
n=200000 |
116 |
Correct |
418 ms |
99064 KB |
n=200000 |
117 |
Correct |
726 ms |
103760 KB |
n=200000 |
118 |
Correct |
652 ms |
100960 KB |
n=200000 |
119 |
Correct |
421 ms |
98952 KB |
n=200000 |
120 |
Correct |
676 ms |
102992 KB |
n=200000 |
121 |
Correct |
738 ms |
102796 KB |
n=200000 |
122 |
Correct |
756 ms |
103300 KB |
n=200000 |
123 |
Correct |
245 ms |
100432 KB |
n=200000 |
124 |
Correct |
123 ms |
45572 KB |
n=25264 |