//-------------dilanyan------------\\
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
//------------------KarginDefines--------------------\\
#define ll long long
#define pb push_back
#define all(u) (u).begin(), (u).end()
#define pqueue priority_queue
#define upper upper_bound
#define lower lower_bound
#define umap unordered_map
#define uset unordered_set
#define Kargin ios_base::sync_with_stdio(false);cin.tie(NULL);
#define Usaco freopen(".in", "r", stdin); freopen(".out", "w", stdout);
//-------------------KarginConstants------------------\\
const ll mod = 1000000007;
const ll inf = 1e9 + 15;
//-------------------KarginCode------------------------\\
const int N = 200005;
int a[N];
vector<int> g[N];
int tin[N], tout[N], tim = 0;
int up[N][20];
void dfs(int u, int p) {
tin[u] = tim++;
up[u][0] = p;
for (int v : g[u]) {
if (v != p) dfs(v, u);
}
tout[u] = tim;
}
bool anc(int u, int v) {
return tin[u] <= tin[v] && tout[u] >= tout[v];
}
int lca(int x, int y) {
if (anc(x, y)) return x;
if (anc(y, x)) return y;
for (int i = 19;i >= 0;i--) {
if (!anc(up[x][i], y)) x = up[x][i];
}
return up[x][0];
}
multiset<int> st[N];
void KarginSolve() {
int n, m, q;
cin >> n >> m >> q;
for (int i = 0;i < n - 1;i++) {
int u, v;
cin >> u >> v;
g[u].pb(v), g[v].pb(u);
}
for (int i = 1;i <= m;i++) cin >> a[i];
dfs(1, 1);
for (int j = 1;j < 20;j++) {
for (int i = 1;i <= n;i++) {
up[i][j] = up[up[i][j - 1]][j - 1];
}
}
for (int i = 1;i < m;i++) {
st[lca(a[i], a[i + 1])].insert(i);
st[a[i]].insert(i);
}
st[a[m]].insert(m);
while (q--) {
int t; cin >> t;
if (t == 1) {
int pos, v;
cin >> pos >> v;
st[a[pos]].erase(st[a[pos]].find(pos));
st[v].insert(pos);
if (pos != 1) {
st[lca(a[pos - 1], a[pos])].erase(st[lca(a[pos - 1], a[pos])].find(pos - 1));
st[lca(a[pos - 1], v)].insert(pos - 1);
}
if (pos != n) {
st[lca(a[pos], a[pos + 1])].erase(st[lca(a[pos], a[pos + 1])].find(pos));
st[lca(v, a[pos + 1])].insert(pos);
}
a[pos] = v;
}
else {
int l, r, v;
cin >> l >> r >> v;
auto it = st[v].lower(l);
if (it == st[v].end()) {
cout << "-1 -1\n";
}
else if (*it <= r) {
if (a[*it] == v) cout << *it << ' ' << *it << '\n';
else cout << *it << ' ' << *it + 1 << '\n';
}
else cout << "-1 -1\n";
}
}
}
int main() {
Kargin;
int test = 1;
//cin >> test;
while (test--) {
KarginSolve();
}
return 0;
}
Compilation message
treearray.cpp:1:1: warning: multi-line comment [-Wcomment]
1 | //-------------dilanyan------------\\
| ^
treearray.cpp:8:1: warning: multi-line comment [-Wcomment]
8 | //------------------KarginDefines--------------------\\
| ^
treearray.cpp:22:1: warning: multi-line comment [-Wcomment]
22 | //-------------------KarginConstants------------------\\
| ^
treearray.cpp:27:1: warning: multi-line comment [-Wcomment]
27 | //-------------------KarginCode------------------------\\
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
17244 KB |
n=5 |
2 |
Correct |
4 ms |
17244 KB |
n=100 |
3 |
Correct |
4 ms |
17496 KB |
n=100 |
4 |
Correct |
4 ms |
17240 KB |
n=100 |
5 |
Correct |
3 ms |
17244 KB |
n=100 |
6 |
Correct |
3 ms |
17244 KB |
n=100 |
7 |
Correct |
3 ms |
17412 KB |
n=100 |
8 |
Correct |
3 ms |
17244 KB |
n=100 |
9 |
Correct |
3 ms |
17244 KB |
n=100 |
10 |
Correct |
3 ms |
17244 KB |
n=100 |
11 |
Correct |
3 ms |
17244 KB |
n=100 |
12 |
Incorrect |
4 ms |
17240 KB |
Wrong output format. |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
17244 KB |
n=5 |
2 |
Correct |
4 ms |
17244 KB |
n=100 |
3 |
Correct |
4 ms |
17496 KB |
n=100 |
4 |
Correct |
4 ms |
17240 KB |
n=100 |
5 |
Correct |
3 ms |
17244 KB |
n=100 |
6 |
Correct |
3 ms |
17244 KB |
n=100 |
7 |
Correct |
3 ms |
17412 KB |
n=100 |
8 |
Correct |
3 ms |
17244 KB |
n=100 |
9 |
Correct |
3 ms |
17244 KB |
n=100 |
10 |
Correct |
3 ms |
17244 KB |
n=100 |
11 |
Correct |
3 ms |
17244 KB |
n=100 |
12 |
Incorrect |
4 ms |
17240 KB |
Wrong output format. |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
17244 KB |
n=5 |
2 |
Correct |
4 ms |
17244 KB |
n=100 |
3 |
Correct |
4 ms |
17496 KB |
n=100 |
4 |
Correct |
4 ms |
17240 KB |
n=100 |
5 |
Correct |
3 ms |
17244 KB |
n=100 |
6 |
Correct |
3 ms |
17244 KB |
n=100 |
7 |
Correct |
3 ms |
17412 KB |
n=100 |
8 |
Correct |
3 ms |
17244 KB |
n=100 |
9 |
Correct |
3 ms |
17244 KB |
n=100 |
10 |
Correct |
3 ms |
17244 KB |
n=100 |
11 |
Correct |
3 ms |
17244 KB |
n=100 |
12 |
Incorrect |
4 ms |
17240 KB |
Wrong output format. |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
17244 KB |
n=5 |
2 |
Correct |
4 ms |
17244 KB |
n=100 |
3 |
Correct |
4 ms |
17496 KB |
n=100 |
4 |
Correct |
4 ms |
17240 KB |
n=100 |
5 |
Correct |
3 ms |
17244 KB |
n=100 |
6 |
Correct |
3 ms |
17244 KB |
n=100 |
7 |
Correct |
3 ms |
17412 KB |
n=100 |
8 |
Correct |
3 ms |
17244 KB |
n=100 |
9 |
Correct |
3 ms |
17244 KB |
n=100 |
10 |
Correct |
3 ms |
17244 KB |
n=100 |
11 |
Correct |
3 ms |
17244 KB |
n=100 |
12 |
Incorrect |
4 ms |
17240 KB |
Wrong output format. |
13 |
Halted |
0 ms |
0 KB |
- |