#include "bits/stdc++.h"
using namespace std;
const int MAXN = 1e6 + 10;
const int MOD = 1e9 + 7;
#define int long long
mt19937_64 rng((int)std::chrono::steady_clock::now().time_since_epoch().count());
int rnd(int x, int y) {
int u = uniform_int_distribution<int>(x, y)(rng); return u;
}
long long bm(long long b, long long p) {
if(p==0) return 1;
long long r = bm(b, p/2);
if(p&1) return (((r*r) % MOD) * b) % MOD;
return (r*r) % MOD;
}
vector<int> adj[MAXN];
pair<int, int> st[19][MAXN];
int l[MAXN], r[MAXN];
vector<int> e;
int dep[MAXN];
void dfs(int node, int prv) {
e.push_back(node);
dep[node] = (prv == -1 ? 0 : dep[prv] + 1);
for(int x: adj[node]) {
if(x != prv) {
dfs(x, node);
e.push_back(node);
}
}
}
int lca_idx(int x, int y) {
int m1 = min(l[x], l[y]), m2 = max(r[x], r[y]);
int k = 32 - __builtin_clz(m2 - m1 + 1) - 1;
return min(st[k][m1], st[k][m2 - (1<<k) + 1]).second;
}
void solve(int tc) {
int n, m, q;
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);
}
dfs(1, -1);
for(int i=0; i<e.size(); i++) st[0][i] = {dep[e[i]], e[i]};
for(int i=0; i<e.size(); i++) r[e[i]] = i;
for(int i=e.size() - 1; i>=0; i--) l[e[i]] = i;
for(int i=1; i<19; i++) {
for(int j=0; j<e.size(); j++) {
if(j + (1<<i) - 1 < e.size()) {
st[i][j] = min(st[i-1][j],st[i-1][j+(1<<(i-1))]);
}
}
}
int a[m+1];
for(int i=1; i<=m; i++) cin >> a[i];
set<int> s[n+1];
for(int i=1; i<=m; i++) s[a[i]].insert(i);
for(int i=1; i<=n; i++) s[i].insert(1e7);
for(int i=1; i<=q; i++) {
int t;
cin >> t;
if(t == 1) {
int pos, v;
cin >> pos >> v;
s[a[pos]].erase(pos);
a[pos] = v;
s[a[pos]].insert(pos);
}
else {
int l, r, v;
cin >> l >> r >> v;
int x = -1, y = -1;
auto it = s[v].lower_bound(l);
if((*it) <= r) x = (*it), y = (*it);
for(int j=l; j<r; j++) {
if(lca_idx(a[j], a[j+1]) == v) {
x = j, y = j + 1;
}
}
cout << x << ' ' << y << "\n";
}
}
}
int32_t main(){
ios::sync_with_stdio(0); cin.tie(0);
int t = 1; //cin >> t;
for(int i=1; i<=t; i++) solve(i);
}
/*
5 4 4
1 2
3 1
3 4
5 3
4 5 2 3
2 1 3 1
1 3 5
2 3 4 5
2 1 3 1
*/
Compilation message
treearray.cpp: In function 'void solve(long long int)':
treearray.cpp:52:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | for(int i=0; i<e.size(); i++) st[0][i] = {dep[e[i]], e[i]};
| ~^~~~~~~~~
treearray.cpp:53:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | for(int i=0; i<e.size(); i++) r[e[i]] = i;
| ~^~~~~~~~~
treearray.cpp:57:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | for(int j=0; j<e.size(); j++) {
| ~^~~~~~~~~
treearray.cpp:58:25: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
58 | if(j + (1<<i) - 1 < e.size()) {
| ~~~~~~~~~~~~~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
n=5 |
2 |
Correct |
13 ms |
23848 KB |
n=100 |
3 |
Correct |
13 ms |
23884 KB |
n=100 |
4 |
Correct |
15 ms |
23860 KB |
n=100 |
5 |
Correct |
13 ms |
23892 KB |
n=100 |
6 |
Correct |
13 ms |
23836 KB |
n=100 |
7 |
Correct |
12 ms |
23892 KB |
n=100 |
8 |
Correct |
13 ms |
23892 KB |
n=100 |
9 |
Correct |
12 ms |
23876 KB |
n=100 |
10 |
Correct |
12 ms |
23928 KB |
n=100 |
11 |
Correct |
13 ms |
23820 KB |
n=100 |
12 |
Correct |
12 ms |
23892 KB |
n=100 |
13 |
Correct |
12 ms |
23892 KB |
n=100 |
14 |
Correct |
13 ms |
23808 KB |
n=100 |
15 |
Correct |
13 ms |
23936 KB |
n=100 |
16 |
Correct |
13 ms |
23932 KB |
n=100 |
17 |
Correct |
13 ms |
23892 KB |
n=100 |
18 |
Correct |
12 ms |
23872 KB |
n=100 |
19 |
Correct |
13 ms |
23892 KB |
n=100 |
20 |
Correct |
13 ms |
23820 KB |
n=100 |
21 |
Correct |
13 ms |
23852 KB |
n=100 |
22 |
Correct |
13 ms |
23892 KB |
n=100 |
23 |
Correct |
13 ms |
23820 KB |
n=100 |
24 |
Correct |
13 ms |
23808 KB |
n=100 |
25 |
Correct |
13 ms |
23840 KB |
n=100 |
26 |
Correct |
13 ms |
23756 KB |
n=12 |
27 |
Correct |
13 ms |
23892 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
n=5 |
2 |
Correct |
13 ms |
23848 KB |
n=100 |
3 |
Correct |
13 ms |
23884 KB |
n=100 |
4 |
Correct |
15 ms |
23860 KB |
n=100 |
5 |
Correct |
13 ms |
23892 KB |
n=100 |
6 |
Correct |
13 ms |
23836 KB |
n=100 |
7 |
Correct |
12 ms |
23892 KB |
n=100 |
8 |
Correct |
13 ms |
23892 KB |
n=100 |
9 |
Correct |
12 ms |
23876 KB |
n=100 |
10 |
Correct |
12 ms |
23928 KB |
n=100 |
11 |
Correct |
13 ms |
23820 KB |
n=100 |
12 |
Correct |
12 ms |
23892 KB |
n=100 |
13 |
Correct |
12 ms |
23892 KB |
n=100 |
14 |
Correct |
13 ms |
23808 KB |
n=100 |
15 |
Correct |
13 ms |
23936 KB |
n=100 |
16 |
Correct |
13 ms |
23932 KB |
n=100 |
17 |
Correct |
13 ms |
23892 KB |
n=100 |
18 |
Correct |
12 ms |
23872 KB |
n=100 |
19 |
Correct |
13 ms |
23892 KB |
n=100 |
20 |
Correct |
13 ms |
23820 KB |
n=100 |
21 |
Correct |
13 ms |
23852 KB |
n=100 |
22 |
Correct |
13 ms |
23892 KB |
n=100 |
23 |
Correct |
13 ms |
23820 KB |
n=100 |
24 |
Correct |
13 ms |
23808 KB |
n=100 |
25 |
Correct |
13 ms |
23840 KB |
n=100 |
26 |
Correct |
13 ms |
23756 KB |
n=12 |
27 |
Correct |
13 ms |
23892 KB |
n=100 |
28 |
Correct |
14 ms |
24148 KB |
n=500 |
29 |
Correct |
14 ms |
24052 KB |
n=500 |
30 |
Correct |
13 ms |
24092 KB |
n=500 |
31 |
Correct |
13 ms |
24160 KB |
n=500 |
32 |
Correct |
14 ms |
24148 KB |
n=500 |
33 |
Correct |
13 ms |
24148 KB |
n=500 |
34 |
Correct |
13 ms |
24148 KB |
n=500 |
35 |
Correct |
13 ms |
24148 KB |
n=500 |
36 |
Correct |
15 ms |
24148 KB |
n=500 |
37 |
Correct |
15 ms |
24148 KB |
n=500 |
38 |
Correct |
16 ms |
24148 KB |
n=500 |
39 |
Correct |
13 ms |
24148 KB |
n=500 |
40 |
Correct |
16 ms |
24160 KB |
n=500 |
41 |
Correct |
13 ms |
24148 KB |
n=500 |
42 |
Correct |
14 ms |
24168 KB |
n=500 |
43 |
Correct |
15 ms |
24160 KB |
n=500 |
44 |
Correct |
14 ms |
24164 KB |
n=500 |
45 |
Correct |
13 ms |
24160 KB |
n=500 |
46 |
Correct |
13 ms |
24148 KB |
n=500 |
47 |
Correct |
13 ms |
24148 KB |
n=500 |
48 |
Correct |
13 ms |
24148 KB |
n=500 |
49 |
Correct |
13 ms |
24148 KB |
n=500 |
50 |
Correct |
13 ms |
24148 KB |
n=500 |
51 |
Correct |
14 ms |
24112 KB |
n=500 |
52 |
Correct |
14 ms |
24148 KB |
n=500 |
53 |
Correct |
13 ms |
24148 KB |
n=500 |
54 |
Correct |
14 ms |
24044 KB |
n=500 |
55 |
Correct |
13 ms |
23944 KB |
n=278 |
56 |
Correct |
14 ms |
24264 KB |
n=500 |
57 |
Correct |
14 ms |
24128 KB |
n=500 |
58 |
Correct |
14 ms |
24148 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
n=5 |
2 |
Correct |
13 ms |
23848 KB |
n=100 |
3 |
Correct |
13 ms |
23884 KB |
n=100 |
4 |
Correct |
15 ms |
23860 KB |
n=100 |
5 |
Correct |
13 ms |
23892 KB |
n=100 |
6 |
Correct |
13 ms |
23836 KB |
n=100 |
7 |
Correct |
12 ms |
23892 KB |
n=100 |
8 |
Correct |
13 ms |
23892 KB |
n=100 |
9 |
Correct |
12 ms |
23876 KB |
n=100 |
10 |
Correct |
12 ms |
23928 KB |
n=100 |
11 |
Correct |
13 ms |
23820 KB |
n=100 |
12 |
Correct |
12 ms |
23892 KB |
n=100 |
13 |
Correct |
12 ms |
23892 KB |
n=100 |
14 |
Correct |
13 ms |
23808 KB |
n=100 |
15 |
Correct |
13 ms |
23936 KB |
n=100 |
16 |
Correct |
13 ms |
23932 KB |
n=100 |
17 |
Correct |
13 ms |
23892 KB |
n=100 |
18 |
Correct |
12 ms |
23872 KB |
n=100 |
19 |
Correct |
13 ms |
23892 KB |
n=100 |
20 |
Correct |
13 ms |
23820 KB |
n=100 |
21 |
Correct |
13 ms |
23852 KB |
n=100 |
22 |
Correct |
13 ms |
23892 KB |
n=100 |
23 |
Correct |
13 ms |
23820 KB |
n=100 |
24 |
Correct |
13 ms |
23808 KB |
n=100 |
25 |
Correct |
13 ms |
23840 KB |
n=100 |
26 |
Correct |
13 ms |
23756 KB |
n=12 |
27 |
Correct |
13 ms |
23892 KB |
n=100 |
28 |
Correct |
14 ms |
24148 KB |
n=500 |
29 |
Correct |
14 ms |
24052 KB |
n=500 |
30 |
Correct |
13 ms |
24092 KB |
n=500 |
31 |
Correct |
13 ms |
24160 KB |
n=500 |
32 |
Correct |
14 ms |
24148 KB |
n=500 |
33 |
Correct |
13 ms |
24148 KB |
n=500 |
34 |
Correct |
13 ms |
24148 KB |
n=500 |
35 |
Correct |
13 ms |
24148 KB |
n=500 |
36 |
Correct |
15 ms |
24148 KB |
n=500 |
37 |
Correct |
15 ms |
24148 KB |
n=500 |
38 |
Correct |
16 ms |
24148 KB |
n=500 |
39 |
Correct |
13 ms |
24148 KB |
n=500 |
40 |
Correct |
16 ms |
24160 KB |
n=500 |
41 |
Correct |
13 ms |
24148 KB |
n=500 |
42 |
Correct |
14 ms |
24168 KB |
n=500 |
43 |
Correct |
15 ms |
24160 KB |
n=500 |
44 |
Correct |
14 ms |
24164 KB |
n=500 |
45 |
Correct |
13 ms |
24160 KB |
n=500 |
46 |
Correct |
13 ms |
24148 KB |
n=500 |
47 |
Correct |
13 ms |
24148 KB |
n=500 |
48 |
Correct |
13 ms |
24148 KB |
n=500 |
49 |
Correct |
13 ms |
24148 KB |
n=500 |
50 |
Correct |
13 ms |
24148 KB |
n=500 |
51 |
Correct |
14 ms |
24112 KB |
n=500 |
52 |
Correct |
14 ms |
24148 KB |
n=500 |
53 |
Correct |
13 ms |
24148 KB |
n=500 |
54 |
Correct |
14 ms |
24044 KB |
n=500 |
55 |
Correct |
13 ms |
23944 KB |
n=278 |
56 |
Correct |
14 ms |
24264 KB |
n=500 |
57 |
Correct |
14 ms |
24128 KB |
n=500 |
58 |
Correct |
14 ms |
24148 KB |
n=500 |
59 |
Correct |
20 ms |
25044 KB |
n=2000 |
60 |
Correct |
20 ms |
25068 KB |
n=2000 |
61 |
Correct |
22 ms |
25044 KB |
n=2000 |
62 |
Correct |
23 ms |
25044 KB |
n=2000 |
63 |
Correct |
22 ms |
25080 KB |
n=2000 |
64 |
Correct |
25 ms |
25064 KB |
n=2000 |
65 |
Correct |
21 ms |
25044 KB |
n=2000 |
66 |
Correct |
23 ms |
25044 KB |
n=2000 |
67 |
Correct |
24 ms |
25060 KB |
n=2000 |
68 |
Correct |
23 ms |
25044 KB |
n=2000 |
69 |
Correct |
61 ms |
25064 KB |
n=2000 |
70 |
Correct |
62 ms |
25056 KB |
n=2000 |
71 |
Correct |
60 ms |
25068 KB |
n=2000 |
72 |
Correct |
25 ms |
25044 KB |
n=2000 |
73 |
Correct |
26 ms |
25108 KB |
n=2000 |
74 |
Correct |
20 ms |
24916 KB |
n=1844 |
75 |
Correct |
26 ms |
25064 KB |
n=2000 |
76 |
Correct |
37 ms |
25048 KB |
n=2000 |
77 |
Correct |
47 ms |
25044 KB |
n=2000 |
78 |
Correct |
38 ms |
25044 KB |
n=2000 |
79 |
Correct |
20 ms |
25076 KB |
n=2000 |
80 |
Correct |
24 ms |
25044 KB |
n=2000 |
81 |
Correct |
26 ms |
25044 KB |
n=2000 |
82 |
Correct |
21 ms |
25044 KB |
n=2000 |
83 |
Correct |
22 ms |
25044 KB |
n=2000 |
84 |
Correct |
22 ms |
25040 KB |
n=2000 |
85 |
Correct |
23 ms |
25064 KB |
n=2000 |
86 |
Correct |
24 ms |
24980 KB |
n=2000 |
87 |
Correct |
21 ms |
25044 KB |
n=2000 |
88 |
Correct |
29 ms |
25044 KB |
n=2000 |
89 |
Correct |
29 ms |
25068 KB |
n=2000 |
90 |
Correct |
27 ms |
25044 KB |
n=2000 |
91 |
Correct |
35 ms |
25052 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
n=5 |
2 |
Correct |
13 ms |
23848 KB |
n=100 |
3 |
Correct |
13 ms |
23884 KB |
n=100 |
4 |
Correct |
15 ms |
23860 KB |
n=100 |
5 |
Correct |
13 ms |
23892 KB |
n=100 |
6 |
Correct |
13 ms |
23836 KB |
n=100 |
7 |
Correct |
12 ms |
23892 KB |
n=100 |
8 |
Correct |
13 ms |
23892 KB |
n=100 |
9 |
Correct |
12 ms |
23876 KB |
n=100 |
10 |
Correct |
12 ms |
23928 KB |
n=100 |
11 |
Correct |
13 ms |
23820 KB |
n=100 |
12 |
Correct |
12 ms |
23892 KB |
n=100 |
13 |
Correct |
12 ms |
23892 KB |
n=100 |
14 |
Correct |
13 ms |
23808 KB |
n=100 |
15 |
Correct |
13 ms |
23936 KB |
n=100 |
16 |
Correct |
13 ms |
23932 KB |
n=100 |
17 |
Correct |
13 ms |
23892 KB |
n=100 |
18 |
Correct |
12 ms |
23872 KB |
n=100 |
19 |
Correct |
13 ms |
23892 KB |
n=100 |
20 |
Correct |
13 ms |
23820 KB |
n=100 |
21 |
Correct |
13 ms |
23852 KB |
n=100 |
22 |
Correct |
13 ms |
23892 KB |
n=100 |
23 |
Correct |
13 ms |
23820 KB |
n=100 |
24 |
Correct |
13 ms |
23808 KB |
n=100 |
25 |
Correct |
13 ms |
23840 KB |
n=100 |
26 |
Correct |
13 ms |
23756 KB |
n=12 |
27 |
Correct |
13 ms |
23892 KB |
n=100 |
28 |
Correct |
14 ms |
24148 KB |
n=500 |
29 |
Correct |
14 ms |
24052 KB |
n=500 |
30 |
Correct |
13 ms |
24092 KB |
n=500 |
31 |
Correct |
13 ms |
24160 KB |
n=500 |
32 |
Correct |
14 ms |
24148 KB |
n=500 |
33 |
Correct |
13 ms |
24148 KB |
n=500 |
34 |
Correct |
13 ms |
24148 KB |
n=500 |
35 |
Correct |
13 ms |
24148 KB |
n=500 |
36 |
Correct |
15 ms |
24148 KB |
n=500 |
37 |
Correct |
15 ms |
24148 KB |
n=500 |
38 |
Correct |
16 ms |
24148 KB |
n=500 |
39 |
Correct |
13 ms |
24148 KB |
n=500 |
40 |
Correct |
16 ms |
24160 KB |
n=500 |
41 |
Correct |
13 ms |
24148 KB |
n=500 |
42 |
Correct |
14 ms |
24168 KB |
n=500 |
43 |
Correct |
15 ms |
24160 KB |
n=500 |
44 |
Correct |
14 ms |
24164 KB |
n=500 |
45 |
Correct |
13 ms |
24160 KB |
n=500 |
46 |
Correct |
13 ms |
24148 KB |
n=500 |
47 |
Correct |
13 ms |
24148 KB |
n=500 |
48 |
Correct |
13 ms |
24148 KB |
n=500 |
49 |
Correct |
13 ms |
24148 KB |
n=500 |
50 |
Correct |
13 ms |
24148 KB |
n=500 |
51 |
Correct |
14 ms |
24112 KB |
n=500 |
52 |
Correct |
14 ms |
24148 KB |
n=500 |
53 |
Correct |
13 ms |
24148 KB |
n=500 |
54 |
Correct |
14 ms |
24044 KB |
n=500 |
55 |
Correct |
13 ms |
23944 KB |
n=278 |
56 |
Correct |
14 ms |
24264 KB |
n=500 |
57 |
Correct |
14 ms |
24128 KB |
n=500 |
58 |
Correct |
14 ms |
24148 KB |
n=500 |
59 |
Correct |
20 ms |
25044 KB |
n=2000 |
60 |
Correct |
20 ms |
25068 KB |
n=2000 |
61 |
Correct |
22 ms |
25044 KB |
n=2000 |
62 |
Correct |
23 ms |
25044 KB |
n=2000 |
63 |
Correct |
22 ms |
25080 KB |
n=2000 |
64 |
Correct |
25 ms |
25064 KB |
n=2000 |
65 |
Correct |
21 ms |
25044 KB |
n=2000 |
66 |
Correct |
23 ms |
25044 KB |
n=2000 |
67 |
Correct |
24 ms |
25060 KB |
n=2000 |
68 |
Correct |
23 ms |
25044 KB |
n=2000 |
69 |
Correct |
61 ms |
25064 KB |
n=2000 |
70 |
Correct |
62 ms |
25056 KB |
n=2000 |
71 |
Correct |
60 ms |
25068 KB |
n=2000 |
72 |
Correct |
25 ms |
25044 KB |
n=2000 |
73 |
Correct |
26 ms |
25108 KB |
n=2000 |
74 |
Correct |
20 ms |
24916 KB |
n=1844 |
75 |
Correct |
26 ms |
25064 KB |
n=2000 |
76 |
Correct |
37 ms |
25048 KB |
n=2000 |
77 |
Correct |
47 ms |
25044 KB |
n=2000 |
78 |
Correct |
38 ms |
25044 KB |
n=2000 |
79 |
Correct |
20 ms |
25076 KB |
n=2000 |
80 |
Correct |
24 ms |
25044 KB |
n=2000 |
81 |
Correct |
26 ms |
25044 KB |
n=2000 |
82 |
Correct |
21 ms |
25044 KB |
n=2000 |
83 |
Correct |
22 ms |
25044 KB |
n=2000 |
84 |
Correct |
22 ms |
25040 KB |
n=2000 |
85 |
Correct |
23 ms |
25064 KB |
n=2000 |
86 |
Correct |
24 ms |
24980 KB |
n=2000 |
87 |
Correct |
21 ms |
25044 KB |
n=2000 |
88 |
Correct |
29 ms |
25044 KB |
n=2000 |
89 |
Correct |
29 ms |
25068 KB |
n=2000 |
90 |
Correct |
27 ms |
25044 KB |
n=2000 |
91 |
Correct |
35 ms |
25052 KB |
n=2000 |
92 |
Execution timed out |
4069 ms |
180428 KB |
Time limit exceeded |
93 |
Halted |
0 ms |
0 KB |
- |