#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define debug(x) cerr << #x << " " << x << "\n"
#define debugs(x) cerr << #x << " " << x << " "
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair <ll, ll> pii;
typedef pair <long double, pii> muchie;
const ll NMAX = 200001;
const ll VMAX = 21;
const ll INF = (1LL << 59);
const ll MOD = 998244353;
const ll BLOCK = 318;
const ll base = 31;
const ll nr_of_bits = 21;
vector <int> v[NMAX];
int dp[NMAX][nr_of_bits + 1];
set <pii> st[NMAX];
int a[NMAX], m;
pii timp[NMAX];
int stamp;
bool isParent(int a, int b){
return timp[a].first <= timp[b].first && timp[b].second <= timp[a].second;
}
int LCA(int a, int b){
if(isParent(a, b))
return a;
if(isParent(b, a))
return b;
int r = b, pas = nr_of_bits;
while(pas >= 0){
int nxt = dp[r][pas];
if(nxt != 0 && !isParent(nxt, a))
r = nxt;
pas--;
}
if(!isParent(r, a))
r = dp[r][0];
return r;
}
void sterge(int stt, int dr){
if(stt < 1)
return;
if(dr > m)
return;
int lca = LCA(a[stt], a[dr]);
st[lca].erase({stt, dr});
}
void pune(int stt, int dr){
if(stt < 1)
return;
if(dr > m)
return;
int lca = LCA(a[stt], a[dr]);
st[lca].insert({stt, dr});
}
void DFS(int node, int p){
dp[node][0] = p;
timp[node].first = ++stamp;
for(auto x : v[node]){
if(x == p)
continue;
DFS(x, node);
}
timp[node].second = stamp;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, q, i, j;
cin >> n >> m >> q;
for(i = 1; i < n; i++){
int x, y;
cin >> x >> y;
v[x].push_back(y);
v[y].push_back(x);
}
DFS(1, 0);
for(j = 1; j <= nr_of_bits; j++){
for(i = 1; i <= n; i++){
dp[i][j] = dp[dp[i][j - 1]][j - 1];
}
}
for(i = 1; i <= m; i++){
cin >> a[i];
st[a[i]].insert({i, i});
}
for(i = 2; i <= m; i++){
pune(i - 1, i);
}
while(q--){
int c, l, r;
cin >> c >> l >> r;
if(c == 1){
st[a[l]].erase({l, l});
sterge(l - 1, l);
sterge(l, l + 1);
a[l] = r;
pune(l - 1, l);
pune(l, l + 1);
st[a[l]].insert({l, l});
}else{
int x;
cin >> x;
pii it = *st[x].lower_bound({l, 0});
if(st[x].lower_bound({l, 0}) == st[x].end()){
cout << "-1 -1\n";
continue;
}
if(it.first >= l && it.second <= r){
cout << it.first << " " << it.second << "\n";
}else{
cout << "-1 -1\n";
}
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
14412 KB |
n=5 |
2 |
Correct |
8 ms |
14412 KB |
n=100 |
3 |
Correct |
8 ms |
14412 KB |
n=100 |
4 |
Correct |
8 ms |
14444 KB |
n=100 |
5 |
Correct |
8 ms |
14412 KB |
n=100 |
6 |
Correct |
8 ms |
14412 KB |
n=100 |
7 |
Correct |
10 ms |
14412 KB |
n=100 |
8 |
Correct |
8 ms |
14444 KB |
n=100 |
9 |
Correct |
8 ms |
14412 KB |
n=100 |
10 |
Correct |
8 ms |
14412 KB |
n=100 |
11 |
Correct |
8 ms |
14412 KB |
n=100 |
12 |
Correct |
11 ms |
14404 KB |
n=100 |
13 |
Correct |
8 ms |
14412 KB |
n=100 |
14 |
Correct |
9 ms |
14448 KB |
n=100 |
15 |
Correct |
8 ms |
14448 KB |
n=100 |
16 |
Correct |
8 ms |
14412 KB |
n=100 |
17 |
Correct |
8 ms |
14412 KB |
n=100 |
18 |
Correct |
9 ms |
14448 KB |
n=100 |
19 |
Correct |
8 ms |
14412 KB |
n=100 |
20 |
Correct |
9 ms |
14448 KB |
n=100 |
21 |
Correct |
9 ms |
14416 KB |
n=100 |
22 |
Correct |
8 ms |
14412 KB |
n=100 |
23 |
Correct |
9 ms |
14412 KB |
n=100 |
24 |
Correct |
9 ms |
14412 KB |
n=100 |
25 |
Correct |
8 ms |
14412 KB |
n=100 |
26 |
Correct |
9 ms |
14412 KB |
n=12 |
27 |
Correct |
7 ms |
14412 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
14412 KB |
n=5 |
2 |
Correct |
8 ms |
14412 KB |
n=100 |
3 |
Correct |
8 ms |
14412 KB |
n=100 |
4 |
Correct |
8 ms |
14444 KB |
n=100 |
5 |
Correct |
8 ms |
14412 KB |
n=100 |
6 |
Correct |
8 ms |
14412 KB |
n=100 |
7 |
Correct |
10 ms |
14412 KB |
n=100 |
8 |
Correct |
8 ms |
14444 KB |
n=100 |
9 |
Correct |
8 ms |
14412 KB |
n=100 |
10 |
Correct |
8 ms |
14412 KB |
n=100 |
11 |
Correct |
8 ms |
14412 KB |
n=100 |
12 |
Correct |
11 ms |
14404 KB |
n=100 |
13 |
Correct |
8 ms |
14412 KB |
n=100 |
14 |
Correct |
9 ms |
14448 KB |
n=100 |
15 |
Correct |
8 ms |
14448 KB |
n=100 |
16 |
Correct |
8 ms |
14412 KB |
n=100 |
17 |
Correct |
8 ms |
14412 KB |
n=100 |
18 |
Correct |
9 ms |
14448 KB |
n=100 |
19 |
Correct |
8 ms |
14412 KB |
n=100 |
20 |
Correct |
9 ms |
14448 KB |
n=100 |
21 |
Correct |
9 ms |
14416 KB |
n=100 |
22 |
Correct |
8 ms |
14412 KB |
n=100 |
23 |
Correct |
9 ms |
14412 KB |
n=100 |
24 |
Correct |
9 ms |
14412 KB |
n=100 |
25 |
Correct |
8 ms |
14412 KB |
n=100 |
26 |
Correct |
9 ms |
14412 KB |
n=12 |
27 |
Correct |
7 ms |
14412 KB |
n=100 |
28 |
Correct |
10 ms |
14532 KB |
n=500 |
29 |
Correct |
8 ms |
14560 KB |
n=500 |
30 |
Correct |
8 ms |
14540 KB |
n=500 |
31 |
Correct |
8 ms |
14540 KB |
n=500 |
32 |
Correct |
8 ms |
14540 KB |
n=500 |
33 |
Correct |
9 ms |
14572 KB |
n=500 |
34 |
Correct |
9 ms |
14504 KB |
n=500 |
35 |
Correct |
10 ms |
14540 KB |
n=500 |
36 |
Correct |
8 ms |
14540 KB |
n=500 |
37 |
Correct |
8 ms |
14540 KB |
n=500 |
38 |
Correct |
8 ms |
14540 KB |
n=500 |
39 |
Correct |
9 ms |
14568 KB |
n=500 |
40 |
Correct |
9 ms |
14540 KB |
n=500 |
41 |
Correct |
9 ms |
14460 KB |
n=500 |
42 |
Correct |
9 ms |
14568 KB |
n=500 |
43 |
Correct |
8 ms |
14540 KB |
n=500 |
44 |
Correct |
8 ms |
14540 KB |
n=500 |
45 |
Correct |
9 ms |
14512 KB |
n=500 |
46 |
Correct |
9 ms |
14592 KB |
n=500 |
47 |
Correct |
9 ms |
14540 KB |
n=500 |
48 |
Correct |
10 ms |
14516 KB |
n=500 |
49 |
Correct |
8 ms |
14600 KB |
n=500 |
50 |
Correct |
8 ms |
14584 KB |
n=500 |
51 |
Correct |
10 ms |
14544 KB |
n=500 |
52 |
Correct |
9 ms |
14560 KB |
n=500 |
53 |
Correct |
12 ms |
14568 KB |
n=500 |
54 |
Correct |
9 ms |
14544 KB |
n=500 |
55 |
Correct |
9 ms |
14544 KB |
n=278 |
56 |
Correct |
8 ms |
14544 KB |
n=500 |
57 |
Correct |
8 ms |
14508 KB |
n=500 |
58 |
Correct |
9 ms |
14592 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
14412 KB |
n=5 |
2 |
Correct |
8 ms |
14412 KB |
n=100 |
3 |
Correct |
8 ms |
14412 KB |
n=100 |
4 |
Correct |
8 ms |
14444 KB |
n=100 |
5 |
Correct |
8 ms |
14412 KB |
n=100 |
6 |
Correct |
8 ms |
14412 KB |
n=100 |
7 |
Correct |
10 ms |
14412 KB |
n=100 |
8 |
Correct |
8 ms |
14444 KB |
n=100 |
9 |
Correct |
8 ms |
14412 KB |
n=100 |
10 |
Correct |
8 ms |
14412 KB |
n=100 |
11 |
Correct |
8 ms |
14412 KB |
n=100 |
12 |
Correct |
11 ms |
14404 KB |
n=100 |
13 |
Correct |
8 ms |
14412 KB |
n=100 |
14 |
Correct |
9 ms |
14448 KB |
n=100 |
15 |
Correct |
8 ms |
14448 KB |
n=100 |
16 |
Correct |
8 ms |
14412 KB |
n=100 |
17 |
Correct |
8 ms |
14412 KB |
n=100 |
18 |
Correct |
9 ms |
14448 KB |
n=100 |
19 |
Correct |
8 ms |
14412 KB |
n=100 |
20 |
Correct |
9 ms |
14448 KB |
n=100 |
21 |
Correct |
9 ms |
14416 KB |
n=100 |
22 |
Correct |
8 ms |
14412 KB |
n=100 |
23 |
Correct |
9 ms |
14412 KB |
n=100 |
24 |
Correct |
9 ms |
14412 KB |
n=100 |
25 |
Correct |
8 ms |
14412 KB |
n=100 |
26 |
Correct |
9 ms |
14412 KB |
n=12 |
27 |
Correct |
7 ms |
14412 KB |
n=100 |
28 |
Correct |
10 ms |
14532 KB |
n=500 |
29 |
Correct |
8 ms |
14560 KB |
n=500 |
30 |
Correct |
8 ms |
14540 KB |
n=500 |
31 |
Correct |
8 ms |
14540 KB |
n=500 |
32 |
Correct |
8 ms |
14540 KB |
n=500 |
33 |
Correct |
9 ms |
14572 KB |
n=500 |
34 |
Correct |
9 ms |
14504 KB |
n=500 |
35 |
Correct |
10 ms |
14540 KB |
n=500 |
36 |
Correct |
8 ms |
14540 KB |
n=500 |
37 |
Correct |
8 ms |
14540 KB |
n=500 |
38 |
Correct |
8 ms |
14540 KB |
n=500 |
39 |
Correct |
9 ms |
14568 KB |
n=500 |
40 |
Correct |
9 ms |
14540 KB |
n=500 |
41 |
Correct |
9 ms |
14460 KB |
n=500 |
42 |
Correct |
9 ms |
14568 KB |
n=500 |
43 |
Correct |
8 ms |
14540 KB |
n=500 |
44 |
Correct |
8 ms |
14540 KB |
n=500 |
45 |
Correct |
9 ms |
14512 KB |
n=500 |
46 |
Correct |
9 ms |
14592 KB |
n=500 |
47 |
Correct |
9 ms |
14540 KB |
n=500 |
48 |
Correct |
10 ms |
14516 KB |
n=500 |
49 |
Correct |
8 ms |
14600 KB |
n=500 |
50 |
Correct |
8 ms |
14584 KB |
n=500 |
51 |
Correct |
10 ms |
14544 KB |
n=500 |
52 |
Correct |
9 ms |
14560 KB |
n=500 |
53 |
Correct |
12 ms |
14568 KB |
n=500 |
54 |
Correct |
9 ms |
14544 KB |
n=500 |
55 |
Correct |
9 ms |
14544 KB |
n=278 |
56 |
Correct |
8 ms |
14544 KB |
n=500 |
57 |
Correct |
8 ms |
14508 KB |
n=500 |
58 |
Correct |
9 ms |
14592 KB |
n=500 |
59 |
Correct |
13 ms |
14928 KB |
n=2000 |
60 |
Correct |
13 ms |
15056 KB |
n=2000 |
61 |
Correct |
11 ms |
15056 KB |
n=2000 |
62 |
Correct |
12 ms |
14952 KB |
n=2000 |
63 |
Correct |
12 ms |
14928 KB |
n=2000 |
64 |
Correct |
11 ms |
15056 KB |
n=2000 |
65 |
Correct |
12 ms |
14928 KB |
n=2000 |
66 |
Correct |
12 ms |
15084 KB |
n=2000 |
67 |
Correct |
12 ms |
14928 KB |
n=2000 |
68 |
Correct |
13 ms |
14964 KB |
n=2000 |
69 |
Correct |
11 ms |
14928 KB |
n=2000 |
70 |
Correct |
11 ms |
14928 KB |
n=2000 |
71 |
Correct |
11 ms |
14928 KB |
n=2000 |
72 |
Correct |
10 ms |
14928 KB |
n=2000 |
73 |
Correct |
10 ms |
14928 KB |
n=2000 |
74 |
Correct |
12 ms |
14992 KB |
n=1844 |
75 |
Correct |
12 ms |
15020 KB |
n=2000 |
76 |
Correct |
12 ms |
14928 KB |
n=2000 |
77 |
Correct |
11 ms |
14928 KB |
n=2000 |
78 |
Correct |
15 ms |
14912 KB |
n=2000 |
79 |
Correct |
12 ms |
14992 KB |
n=2000 |
80 |
Correct |
15 ms |
15056 KB |
n=2000 |
81 |
Correct |
12 ms |
15064 KB |
n=2000 |
82 |
Correct |
11 ms |
14988 KB |
n=2000 |
83 |
Correct |
11 ms |
15056 KB |
n=2000 |
84 |
Correct |
11 ms |
14952 KB |
n=2000 |
85 |
Correct |
11 ms |
14952 KB |
n=2000 |
86 |
Correct |
13 ms |
14980 KB |
n=2000 |
87 |
Correct |
12 ms |
14928 KB |
n=2000 |
88 |
Correct |
12 ms |
15056 KB |
n=2000 |
89 |
Correct |
11 ms |
15096 KB |
n=2000 |
90 |
Correct |
11 ms |
15056 KB |
n=2000 |
91 |
Correct |
10 ms |
14956 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
14412 KB |
n=5 |
2 |
Correct |
8 ms |
14412 KB |
n=100 |
3 |
Correct |
8 ms |
14412 KB |
n=100 |
4 |
Correct |
8 ms |
14444 KB |
n=100 |
5 |
Correct |
8 ms |
14412 KB |
n=100 |
6 |
Correct |
8 ms |
14412 KB |
n=100 |
7 |
Correct |
10 ms |
14412 KB |
n=100 |
8 |
Correct |
8 ms |
14444 KB |
n=100 |
9 |
Correct |
8 ms |
14412 KB |
n=100 |
10 |
Correct |
8 ms |
14412 KB |
n=100 |
11 |
Correct |
8 ms |
14412 KB |
n=100 |
12 |
Correct |
11 ms |
14404 KB |
n=100 |
13 |
Correct |
8 ms |
14412 KB |
n=100 |
14 |
Correct |
9 ms |
14448 KB |
n=100 |
15 |
Correct |
8 ms |
14448 KB |
n=100 |
16 |
Correct |
8 ms |
14412 KB |
n=100 |
17 |
Correct |
8 ms |
14412 KB |
n=100 |
18 |
Correct |
9 ms |
14448 KB |
n=100 |
19 |
Correct |
8 ms |
14412 KB |
n=100 |
20 |
Correct |
9 ms |
14448 KB |
n=100 |
21 |
Correct |
9 ms |
14416 KB |
n=100 |
22 |
Correct |
8 ms |
14412 KB |
n=100 |
23 |
Correct |
9 ms |
14412 KB |
n=100 |
24 |
Correct |
9 ms |
14412 KB |
n=100 |
25 |
Correct |
8 ms |
14412 KB |
n=100 |
26 |
Correct |
9 ms |
14412 KB |
n=12 |
27 |
Correct |
7 ms |
14412 KB |
n=100 |
28 |
Correct |
10 ms |
14532 KB |
n=500 |
29 |
Correct |
8 ms |
14560 KB |
n=500 |
30 |
Correct |
8 ms |
14540 KB |
n=500 |
31 |
Correct |
8 ms |
14540 KB |
n=500 |
32 |
Correct |
8 ms |
14540 KB |
n=500 |
33 |
Correct |
9 ms |
14572 KB |
n=500 |
34 |
Correct |
9 ms |
14504 KB |
n=500 |
35 |
Correct |
10 ms |
14540 KB |
n=500 |
36 |
Correct |
8 ms |
14540 KB |
n=500 |
37 |
Correct |
8 ms |
14540 KB |
n=500 |
38 |
Correct |
8 ms |
14540 KB |
n=500 |
39 |
Correct |
9 ms |
14568 KB |
n=500 |
40 |
Correct |
9 ms |
14540 KB |
n=500 |
41 |
Correct |
9 ms |
14460 KB |
n=500 |
42 |
Correct |
9 ms |
14568 KB |
n=500 |
43 |
Correct |
8 ms |
14540 KB |
n=500 |
44 |
Correct |
8 ms |
14540 KB |
n=500 |
45 |
Correct |
9 ms |
14512 KB |
n=500 |
46 |
Correct |
9 ms |
14592 KB |
n=500 |
47 |
Correct |
9 ms |
14540 KB |
n=500 |
48 |
Correct |
10 ms |
14516 KB |
n=500 |
49 |
Correct |
8 ms |
14600 KB |
n=500 |
50 |
Correct |
8 ms |
14584 KB |
n=500 |
51 |
Correct |
10 ms |
14544 KB |
n=500 |
52 |
Correct |
9 ms |
14560 KB |
n=500 |
53 |
Correct |
12 ms |
14568 KB |
n=500 |
54 |
Correct |
9 ms |
14544 KB |
n=500 |
55 |
Correct |
9 ms |
14544 KB |
n=278 |
56 |
Correct |
8 ms |
14544 KB |
n=500 |
57 |
Correct |
8 ms |
14508 KB |
n=500 |
58 |
Correct |
9 ms |
14592 KB |
n=500 |
59 |
Correct |
13 ms |
14928 KB |
n=2000 |
60 |
Correct |
13 ms |
15056 KB |
n=2000 |
61 |
Correct |
11 ms |
15056 KB |
n=2000 |
62 |
Correct |
12 ms |
14952 KB |
n=2000 |
63 |
Correct |
12 ms |
14928 KB |
n=2000 |
64 |
Correct |
11 ms |
15056 KB |
n=2000 |
65 |
Correct |
12 ms |
14928 KB |
n=2000 |
66 |
Correct |
12 ms |
15084 KB |
n=2000 |
67 |
Correct |
12 ms |
14928 KB |
n=2000 |
68 |
Correct |
13 ms |
14964 KB |
n=2000 |
69 |
Correct |
11 ms |
14928 KB |
n=2000 |
70 |
Correct |
11 ms |
14928 KB |
n=2000 |
71 |
Correct |
11 ms |
14928 KB |
n=2000 |
72 |
Correct |
10 ms |
14928 KB |
n=2000 |
73 |
Correct |
10 ms |
14928 KB |
n=2000 |
74 |
Correct |
12 ms |
14992 KB |
n=1844 |
75 |
Correct |
12 ms |
15020 KB |
n=2000 |
76 |
Correct |
12 ms |
14928 KB |
n=2000 |
77 |
Correct |
11 ms |
14928 KB |
n=2000 |
78 |
Correct |
15 ms |
14912 KB |
n=2000 |
79 |
Correct |
12 ms |
14992 KB |
n=2000 |
80 |
Correct |
15 ms |
15056 KB |
n=2000 |
81 |
Correct |
12 ms |
15064 KB |
n=2000 |
82 |
Correct |
11 ms |
14988 KB |
n=2000 |
83 |
Correct |
11 ms |
15056 KB |
n=2000 |
84 |
Correct |
11 ms |
14952 KB |
n=2000 |
85 |
Correct |
11 ms |
14952 KB |
n=2000 |
86 |
Correct |
13 ms |
14980 KB |
n=2000 |
87 |
Correct |
12 ms |
14928 KB |
n=2000 |
88 |
Correct |
12 ms |
15056 KB |
n=2000 |
89 |
Correct |
11 ms |
15096 KB |
n=2000 |
90 |
Correct |
11 ms |
15056 KB |
n=2000 |
91 |
Correct |
10 ms |
14956 KB |
n=2000 |
92 |
Correct |
777 ms |
75324 KB |
n=200000 |
93 |
Correct |
988 ms |
81808 KB |
n=200000 |
94 |
Correct |
700 ms |
86240 KB |
n=200000 |
95 |
Correct |
807 ms |
75072 KB |
n=200000 |
96 |
Correct |
776 ms |
75060 KB |
n=200000 |
97 |
Correct |
1074 ms |
80628 KB |
n=200000 |
98 |
Correct |
757 ms |
75084 KB |
n=200000 |
99 |
Correct |
829 ms |
75332 KB |
n=200000 |
100 |
Correct |
806 ms |
75172 KB |
n=200000 |
101 |
Correct |
595 ms |
87852 KB |
n=200000 |
102 |
Correct |
426 ms |
76360 KB |
n=200000 |
103 |
Correct |
436 ms |
76280 KB |
n=200000 |
104 |
Correct |
431 ms |
76340 KB |
n=200000 |
105 |
Correct |
501 ms |
76744 KB |
n=200000 |
106 |
Correct |
446 ms |
76764 KB |
n=200000 |
107 |
Correct |
441 ms |
76660 KB |
n=200000 |
108 |
Correct |
787 ms |
75188 KB |
n=200000 |
109 |
Correct |
774 ms |
75336 KB |
n=200000 |
110 |
Correct |
830 ms |
75208 KB |
n=200000 |
111 |
Correct |
737 ms |
74576 KB |
n=200000 |
112 |
Correct |
652 ms |
86612 KB |
n=200000 |
113 |
Correct |
1014 ms |
80660 KB |
n=200000 |
114 |
Correct |
740 ms |
74836 KB |
n=200000 |
115 |
Correct |
1288 ms |
77728 KB |
n=200000 |
116 |
Correct |
703 ms |
75360 KB |
n=200000 |
117 |
Correct |
628 ms |
87116 KB |
n=200000 |
118 |
Correct |
1095 ms |
79048 KB |
n=200000 |
119 |
Correct |
674 ms |
75224 KB |
n=200000 |
120 |
Correct |
605 ms |
87012 KB |
n=200000 |
121 |
Correct |
620 ms |
86892 KB |
n=200000 |
122 |
Correct |
629 ms |
87280 KB |
n=200000 |
123 |
Correct |
422 ms |
76436 KB |
n=200000 |
124 |
Correct |
184 ms |
32968 KB |
n=25264 |