#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define ff(i,a,b) for(int i = a; i <= b; i++)
#define fb(i,b,a) for(int i = b; i >= a; i--)
#define trav(a,x) for (auto& a : x)
#define sz(a) (int)(a).size()
#define pb push_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// os.order_of_key(k) the number of elements in the os less than k
// *os.find_by_order(k) print the k-th smallest number in os(0-based)
const int mod = 1000000007;
const int inf = 1e9 + 5;
const int mxN = 100005;
int n, m, q;
int niz[mxN];
vector<int> g[mxN];
set<int> s[mxN];
set<int> gde[mxN];
int d[mxN];
int deda[mxN][20];
void dfs(int v, int p){
deda[v][0] = p;
ff(i,1,19)deda[v][i] = deda[deda[v][i - 1]][i - 1];
for(auto u : g[v]){
if(u != p){
d[u] = d[v] + 1;
dfs(u, v);
}
}
}
int LCA(int x, int y){
if(d[x] < d[y])swap(x, y);
fb(i,19,0)if((d[x] - d[y]) & (1 << i))x = deda[x][i];
fb(i,19,0)if(deda[x][i] != deda[y][i])x = deda[x][i], y = deda[y][i];
return (x == y ? x : deda[x][0]);
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m >> q;
ff(i,1,n - 1){
int u, v;
cin >> u >> v;
g[u].pb(v);
g[v].pb(u);
}
ff(i,1,m)cin >> niz[i];
dfs(1, 0);
ff(i,2,m){
int lca = LCA(niz[i - 1], niz[i]);
s[lca].insert(i);
}
ff(i,1,m)gde[niz[i]].insert(i);
while(q--){
int t;
cin >> t;
if(t == 1){
int pos, val;
cin >> pos >> val;
gde[niz[pos]].erase(pos);
if(pos != 1){
int lca = LCA(niz[pos - 1], niz[pos]);
s[lca].erase(pos);
}
if(pos != n){
int lca = LCA(niz[pos], niz[pos + 1]);
s[lca].erase(pos + 1);
}
niz[pos] = val; gde[niz[pos]].insert(pos);
if(pos != 1){
int lca = LCA(niz[pos - 1], niz[pos]);
s[lca].insert(pos);
}
if(pos != n){
int lca = LCA(niz[pos], niz[pos + 1]);
s[lca].insert(pos + 1);
}
}
if(t == 2){
int l, r, v;
cin >> l >> r >> v;
bool ok = 0;
auto a = s[v].ub(l);
if(a != s[v].end() && *a <= r){
cout << *a - 1 << " " << *a << '\n';
continue;
}
auto b = gde[v].lb(l);
if(b != gde[v].end() && *b <= r){
cout << *b << " " << *b << '\n';
continue;
}
cout << -1 << " " << -1 << '\n';
}
}
return 0;
}
/*
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
// probati bojenje sahovski
*/
Compilation message
treearray.cpp: In function 'int main()':
treearray.cpp:128:9: warning: unused variable 'ok' [-Wunused-variable]
128 | bool ok = 0;
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
11988 KB |
n=5 |
2 |
Correct |
7 ms |
12024 KB |
n=100 |
3 |
Correct |
6 ms |
12012 KB |
n=100 |
4 |
Correct |
7 ms |
11988 KB |
n=100 |
5 |
Correct |
6 ms |
12080 KB |
n=100 |
6 |
Correct |
6 ms |
11988 KB |
n=100 |
7 |
Correct |
7 ms |
11988 KB |
n=100 |
8 |
Correct |
6 ms |
12084 KB |
n=100 |
9 |
Correct |
7 ms |
12084 KB |
n=100 |
10 |
Correct |
6 ms |
11988 KB |
n=100 |
11 |
Correct |
7 ms |
11988 KB |
n=100 |
12 |
Correct |
6 ms |
11988 KB |
n=100 |
13 |
Correct |
7 ms |
11988 KB |
n=100 |
14 |
Correct |
6 ms |
11988 KB |
n=100 |
15 |
Correct |
7 ms |
12072 KB |
n=100 |
16 |
Correct |
7 ms |
11988 KB |
n=100 |
17 |
Correct |
7 ms |
12104 KB |
n=100 |
18 |
Correct |
7 ms |
11988 KB |
n=100 |
19 |
Correct |
7 ms |
11988 KB |
n=100 |
20 |
Correct |
6 ms |
11988 KB |
n=100 |
21 |
Correct |
7 ms |
11988 KB |
n=100 |
22 |
Correct |
6 ms |
11988 KB |
n=100 |
23 |
Correct |
7 ms |
11996 KB |
n=100 |
24 |
Correct |
7 ms |
12076 KB |
n=100 |
25 |
Correct |
6 ms |
12084 KB |
n=100 |
26 |
Correct |
6 ms |
11988 KB |
n=12 |
27 |
Correct |
7 ms |
11988 KB |
n=100 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
11988 KB |
n=5 |
2 |
Correct |
7 ms |
12024 KB |
n=100 |
3 |
Correct |
6 ms |
12012 KB |
n=100 |
4 |
Correct |
7 ms |
11988 KB |
n=100 |
5 |
Correct |
6 ms |
12080 KB |
n=100 |
6 |
Correct |
6 ms |
11988 KB |
n=100 |
7 |
Correct |
7 ms |
11988 KB |
n=100 |
8 |
Correct |
6 ms |
12084 KB |
n=100 |
9 |
Correct |
7 ms |
12084 KB |
n=100 |
10 |
Correct |
6 ms |
11988 KB |
n=100 |
11 |
Correct |
7 ms |
11988 KB |
n=100 |
12 |
Correct |
6 ms |
11988 KB |
n=100 |
13 |
Correct |
7 ms |
11988 KB |
n=100 |
14 |
Correct |
6 ms |
11988 KB |
n=100 |
15 |
Correct |
7 ms |
12072 KB |
n=100 |
16 |
Correct |
7 ms |
11988 KB |
n=100 |
17 |
Correct |
7 ms |
12104 KB |
n=100 |
18 |
Correct |
7 ms |
11988 KB |
n=100 |
19 |
Correct |
7 ms |
11988 KB |
n=100 |
20 |
Correct |
6 ms |
11988 KB |
n=100 |
21 |
Correct |
7 ms |
11988 KB |
n=100 |
22 |
Correct |
6 ms |
11988 KB |
n=100 |
23 |
Correct |
7 ms |
11996 KB |
n=100 |
24 |
Correct |
7 ms |
12076 KB |
n=100 |
25 |
Correct |
6 ms |
12084 KB |
n=100 |
26 |
Correct |
6 ms |
11988 KB |
n=12 |
27 |
Correct |
7 ms |
11988 KB |
n=100 |
28 |
Correct |
7 ms |
12116 KB |
n=500 |
29 |
Correct |
7 ms |
12116 KB |
n=500 |
30 |
Correct |
8 ms |
12116 KB |
n=500 |
31 |
Correct |
7 ms |
12116 KB |
n=500 |
32 |
Correct |
7 ms |
12116 KB |
n=500 |
33 |
Correct |
7 ms |
12116 KB |
n=500 |
34 |
Correct |
7 ms |
12092 KB |
n=500 |
35 |
Correct |
7 ms |
12116 KB |
n=500 |
36 |
Correct |
7 ms |
12116 KB |
n=500 |
37 |
Correct |
7 ms |
12172 KB |
n=500 |
38 |
Correct |
7 ms |
12116 KB |
n=500 |
39 |
Correct |
7 ms |
12092 KB |
n=500 |
40 |
Correct |
7 ms |
12116 KB |
n=500 |
41 |
Correct |
7 ms |
12092 KB |
n=500 |
42 |
Correct |
7 ms |
12088 KB |
n=500 |
43 |
Correct |
7 ms |
12092 KB |
n=500 |
44 |
Correct |
7 ms |
12116 KB |
n=500 |
45 |
Correct |
7 ms |
12116 KB |
n=500 |
46 |
Correct |
7 ms |
12160 KB |
n=500 |
47 |
Correct |
8 ms |
12220 KB |
n=500 |
48 |
Correct |
7 ms |
12116 KB |
n=500 |
49 |
Correct |
7 ms |
12116 KB |
n=500 |
50 |
Correct |
7 ms |
12088 KB |
n=500 |
51 |
Correct |
7 ms |
12116 KB |
n=500 |
52 |
Correct |
7 ms |
12116 KB |
n=500 |
53 |
Correct |
7 ms |
12116 KB |
n=500 |
54 |
Correct |
7 ms |
12116 KB |
n=500 |
55 |
Correct |
7 ms |
12104 KB |
n=278 |
56 |
Correct |
8 ms |
12116 KB |
n=500 |
57 |
Correct |
7 ms |
12220 KB |
n=500 |
58 |
Correct |
7 ms |
12116 KB |
n=500 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
11988 KB |
n=5 |
2 |
Correct |
7 ms |
12024 KB |
n=100 |
3 |
Correct |
6 ms |
12012 KB |
n=100 |
4 |
Correct |
7 ms |
11988 KB |
n=100 |
5 |
Correct |
6 ms |
12080 KB |
n=100 |
6 |
Correct |
6 ms |
11988 KB |
n=100 |
7 |
Correct |
7 ms |
11988 KB |
n=100 |
8 |
Correct |
6 ms |
12084 KB |
n=100 |
9 |
Correct |
7 ms |
12084 KB |
n=100 |
10 |
Correct |
6 ms |
11988 KB |
n=100 |
11 |
Correct |
7 ms |
11988 KB |
n=100 |
12 |
Correct |
6 ms |
11988 KB |
n=100 |
13 |
Correct |
7 ms |
11988 KB |
n=100 |
14 |
Correct |
6 ms |
11988 KB |
n=100 |
15 |
Correct |
7 ms |
12072 KB |
n=100 |
16 |
Correct |
7 ms |
11988 KB |
n=100 |
17 |
Correct |
7 ms |
12104 KB |
n=100 |
18 |
Correct |
7 ms |
11988 KB |
n=100 |
19 |
Correct |
7 ms |
11988 KB |
n=100 |
20 |
Correct |
6 ms |
11988 KB |
n=100 |
21 |
Correct |
7 ms |
11988 KB |
n=100 |
22 |
Correct |
6 ms |
11988 KB |
n=100 |
23 |
Correct |
7 ms |
11996 KB |
n=100 |
24 |
Correct |
7 ms |
12076 KB |
n=100 |
25 |
Correct |
6 ms |
12084 KB |
n=100 |
26 |
Correct |
6 ms |
11988 KB |
n=12 |
27 |
Correct |
7 ms |
11988 KB |
n=100 |
28 |
Correct |
7 ms |
12116 KB |
n=500 |
29 |
Correct |
7 ms |
12116 KB |
n=500 |
30 |
Correct |
8 ms |
12116 KB |
n=500 |
31 |
Correct |
7 ms |
12116 KB |
n=500 |
32 |
Correct |
7 ms |
12116 KB |
n=500 |
33 |
Correct |
7 ms |
12116 KB |
n=500 |
34 |
Correct |
7 ms |
12092 KB |
n=500 |
35 |
Correct |
7 ms |
12116 KB |
n=500 |
36 |
Correct |
7 ms |
12116 KB |
n=500 |
37 |
Correct |
7 ms |
12172 KB |
n=500 |
38 |
Correct |
7 ms |
12116 KB |
n=500 |
39 |
Correct |
7 ms |
12092 KB |
n=500 |
40 |
Correct |
7 ms |
12116 KB |
n=500 |
41 |
Correct |
7 ms |
12092 KB |
n=500 |
42 |
Correct |
7 ms |
12088 KB |
n=500 |
43 |
Correct |
7 ms |
12092 KB |
n=500 |
44 |
Correct |
7 ms |
12116 KB |
n=500 |
45 |
Correct |
7 ms |
12116 KB |
n=500 |
46 |
Correct |
7 ms |
12160 KB |
n=500 |
47 |
Correct |
8 ms |
12220 KB |
n=500 |
48 |
Correct |
7 ms |
12116 KB |
n=500 |
49 |
Correct |
7 ms |
12116 KB |
n=500 |
50 |
Correct |
7 ms |
12088 KB |
n=500 |
51 |
Correct |
7 ms |
12116 KB |
n=500 |
52 |
Correct |
7 ms |
12116 KB |
n=500 |
53 |
Correct |
7 ms |
12116 KB |
n=500 |
54 |
Correct |
7 ms |
12116 KB |
n=500 |
55 |
Correct |
7 ms |
12104 KB |
n=278 |
56 |
Correct |
8 ms |
12116 KB |
n=500 |
57 |
Correct |
7 ms |
12220 KB |
n=500 |
58 |
Correct |
7 ms |
12116 KB |
n=500 |
59 |
Correct |
10 ms |
12484 KB |
n=2000 |
60 |
Correct |
10 ms |
12628 KB |
n=2000 |
61 |
Correct |
10 ms |
12608 KB |
n=2000 |
62 |
Correct |
10 ms |
12612 KB |
n=2000 |
63 |
Correct |
10 ms |
12480 KB |
n=2000 |
64 |
Correct |
10 ms |
12616 KB |
n=2000 |
65 |
Correct |
10 ms |
12584 KB |
n=2000 |
66 |
Correct |
10 ms |
12612 KB |
n=2000 |
67 |
Correct |
10 ms |
12500 KB |
n=2000 |
68 |
Correct |
13 ms |
12628 KB |
n=2000 |
69 |
Correct |
9 ms |
12500 KB |
n=2000 |
70 |
Correct |
8 ms |
12480 KB |
n=2000 |
71 |
Correct |
9 ms |
12552 KB |
n=2000 |
72 |
Correct |
9 ms |
12500 KB |
n=2000 |
73 |
Correct |
9 ms |
12500 KB |
n=2000 |
74 |
Correct |
10 ms |
12512 KB |
n=1844 |
75 |
Correct |
10 ms |
12492 KB |
n=2000 |
76 |
Correct |
10 ms |
12500 KB |
n=2000 |
77 |
Correct |
10 ms |
12552 KB |
n=2000 |
78 |
Correct |
11 ms |
12500 KB |
n=2000 |
79 |
Correct |
12 ms |
12568 KB |
n=2000 |
80 |
Correct |
10 ms |
12628 KB |
n=2000 |
81 |
Correct |
11 ms |
12592 KB |
n=2000 |
82 |
Correct |
10 ms |
12568 KB |
n=2000 |
83 |
Correct |
10 ms |
12608 KB |
n=2000 |
84 |
Correct |
11 ms |
12560 KB |
n=2000 |
85 |
Correct |
11 ms |
12604 KB |
n=2000 |
86 |
Correct |
10 ms |
12628 KB |
n=2000 |
87 |
Correct |
9 ms |
12500 KB |
n=2000 |
88 |
Correct |
10 ms |
12612 KB |
n=2000 |
89 |
Correct |
10 ms |
12692 KB |
n=2000 |
90 |
Correct |
11 ms |
12628 KB |
n=2000 |
91 |
Correct |
9 ms |
12500 KB |
n=2000 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
11988 KB |
n=5 |
2 |
Correct |
7 ms |
12024 KB |
n=100 |
3 |
Correct |
6 ms |
12012 KB |
n=100 |
4 |
Correct |
7 ms |
11988 KB |
n=100 |
5 |
Correct |
6 ms |
12080 KB |
n=100 |
6 |
Correct |
6 ms |
11988 KB |
n=100 |
7 |
Correct |
7 ms |
11988 KB |
n=100 |
8 |
Correct |
6 ms |
12084 KB |
n=100 |
9 |
Correct |
7 ms |
12084 KB |
n=100 |
10 |
Correct |
6 ms |
11988 KB |
n=100 |
11 |
Correct |
7 ms |
11988 KB |
n=100 |
12 |
Correct |
6 ms |
11988 KB |
n=100 |
13 |
Correct |
7 ms |
11988 KB |
n=100 |
14 |
Correct |
6 ms |
11988 KB |
n=100 |
15 |
Correct |
7 ms |
12072 KB |
n=100 |
16 |
Correct |
7 ms |
11988 KB |
n=100 |
17 |
Correct |
7 ms |
12104 KB |
n=100 |
18 |
Correct |
7 ms |
11988 KB |
n=100 |
19 |
Correct |
7 ms |
11988 KB |
n=100 |
20 |
Correct |
6 ms |
11988 KB |
n=100 |
21 |
Correct |
7 ms |
11988 KB |
n=100 |
22 |
Correct |
6 ms |
11988 KB |
n=100 |
23 |
Correct |
7 ms |
11996 KB |
n=100 |
24 |
Correct |
7 ms |
12076 KB |
n=100 |
25 |
Correct |
6 ms |
12084 KB |
n=100 |
26 |
Correct |
6 ms |
11988 KB |
n=12 |
27 |
Correct |
7 ms |
11988 KB |
n=100 |
28 |
Correct |
7 ms |
12116 KB |
n=500 |
29 |
Correct |
7 ms |
12116 KB |
n=500 |
30 |
Correct |
8 ms |
12116 KB |
n=500 |
31 |
Correct |
7 ms |
12116 KB |
n=500 |
32 |
Correct |
7 ms |
12116 KB |
n=500 |
33 |
Correct |
7 ms |
12116 KB |
n=500 |
34 |
Correct |
7 ms |
12092 KB |
n=500 |
35 |
Correct |
7 ms |
12116 KB |
n=500 |
36 |
Correct |
7 ms |
12116 KB |
n=500 |
37 |
Correct |
7 ms |
12172 KB |
n=500 |
38 |
Correct |
7 ms |
12116 KB |
n=500 |
39 |
Correct |
7 ms |
12092 KB |
n=500 |
40 |
Correct |
7 ms |
12116 KB |
n=500 |
41 |
Correct |
7 ms |
12092 KB |
n=500 |
42 |
Correct |
7 ms |
12088 KB |
n=500 |
43 |
Correct |
7 ms |
12092 KB |
n=500 |
44 |
Correct |
7 ms |
12116 KB |
n=500 |
45 |
Correct |
7 ms |
12116 KB |
n=500 |
46 |
Correct |
7 ms |
12160 KB |
n=500 |
47 |
Correct |
8 ms |
12220 KB |
n=500 |
48 |
Correct |
7 ms |
12116 KB |
n=500 |
49 |
Correct |
7 ms |
12116 KB |
n=500 |
50 |
Correct |
7 ms |
12088 KB |
n=500 |
51 |
Correct |
7 ms |
12116 KB |
n=500 |
52 |
Correct |
7 ms |
12116 KB |
n=500 |
53 |
Correct |
7 ms |
12116 KB |
n=500 |
54 |
Correct |
7 ms |
12116 KB |
n=500 |
55 |
Correct |
7 ms |
12104 KB |
n=278 |
56 |
Correct |
8 ms |
12116 KB |
n=500 |
57 |
Correct |
7 ms |
12220 KB |
n=500 |
58 |
Correct |
7 ms |
12116 KB |
n=500 |
59 |
Correct |
10 ms |
12484 KB |
n=2000 |
60 |
Correct |
10 ms |
12628 KB |
n=2000 |
61 |
Correct |
10 ms |
12608 KB |
n=2000 |
62 |
Correct |
10 ms |
12612 KB |
n=2000 |
63 |
Correct |
10 ms |
12480 KB |
n=2000 |
64 |
Correct |
10 ms |
12616 KB |
n=2000 |
65 |
Correct |
10 ms |
12584 KB |
n=2000 |
66 |
Correct |
10 ms |
12612 KB |
n=2000 |
67 |
Correct |
10 ms |
12500 KB |
n=2000 |
68 |
Correct |
13 ms |
12628 KB |
n=2000 |
69 |
Correct |
9 ms |
12500 KB |
n=2000 |
70 |
Correct |
8 ms |
12480 KB |
n=2000 |
71 |
Correct |
9 ms |
12552 KB |
n=2000 |
72 |
Correct |
9 ms |
12500 KB |
n=2000 |
73 |
Correct |
9 ms |
12500 KB |
n=2000 |
74 |
Correct |
10 ms |
12512 KB |
n=1844 |
75 |
Correct |
10 ms |
12492 KB |
n=2000 |
76 |
Correct |
10 ms |
12500 KB |
n=2000 |
77 |
Correct |
10 ms |
12552 KB |
n=2000 |
78 |
Correct |
11 ms |
12500 KB |
n=2000 |
79 |
Correct |
12 ms |
12568 KB |
n=2000 |
80 |
Correct |
10 ms |
12628 KB |
n=2000 |
81 |
Correct |
11 ms |
12592 KB |
n=2000 |
82 |
Correct |
10 ms |
12568 KB |
n=2000 |
83 |
Correct |
10 ms |
12608 KB |
n=2000 |
84 |
Correct |
11 ms |
12560 KB |
n=2000 |
85 |
Correct |
11 ms |
12604 KB |
n=2000 |
86 |
Correct |
10 ms |
12628 KB |
n=2000 |
87 |
Correct |
9 ms |
12500 KB |
n=2000 |
88 |
Correct |
10 ms |
12612 KB |
n=2000 |
89 |
Correct |
10 ms |
12692 KB |
n=2000 |
90 |
Correct |
11 ms |
12628 KB |
n=2000 |
91 |
Correct |
9 ms |
12500 KB |
n=2000 |
92 |
Runtime error |
16 ms |
24300 KB |
Execution killed with signal 11 |
93 |
Halted |
0 ms |
0 KB |
- |