#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = a; i<= b; ++i)
#define FORD(i, a, b) for (int i = a; i>=b; --i)
#define REP(i, a) for (int i = 0; i<a; ++i)
#define DEBUG(x) { cerr << #x << " = " << x << endl; }
#define Arr(A, l, r) { cerr << #A << " = "; FOR(_, l, r) cerr << A[_] << ' '; cerr << endl; }
#define N 1001000
#define pp pair<int, int>
#define next __next
#define prev __prev
#define __builtin_popcount __builtin_popcountll
#define bit(S, i) (((S) >> i) & 1)
#define IO ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
using namespace std;
int n, m, q, a[N], h[N];
int LCA[N][20], LOG;
vector<int> e[N];
set<int> One[N], Two[N];
void dfs(int u, int p) {
for (int v : e[u]) if (v != p) {
h[v] = h[u] + 1;
LCA[v][0] = u;
FOR(j, 1, LOG) LCA[v][j] = LCA[LCA[v][j - 1]][j - 1];
dfs(v, u);
}
}
int lca(int u, int v) {
if (h[u] < h[v]) swap(u, v);
int delta = h[u] - h[v];
FORD(i, LOG, 0) if (bit(delta, i)) u = LCA[u][i];
if (u == v) return u;
FORD(i, LOG, 0) if (LCA[u][i] != LCA[v][i]) {
u = LCA[u][i]; v = LCA[v][i];
}
return LCA[u][0];
}
int main() {
#ifdef NERO
freopen("test.inp","r",stdin);
freopen("test.out","w",stdout);
#endif //NERO
IO;
cin >> n >> m >> q;
LOG = log2(n);
FOR(i, 2, n) {
int u, v;
cin >> u >> v;
e[u].push_back(v);
e[v].push_back(u);
}
dfs(1, -1);
FOR(i, 1, m) {
cin >> a[i];
One[a[i]].insert(i);
if (i != 1) {
Two[lca(a[i], a[i - 1])].insert(i);
}
}
while (q--) {
int type, v, l, r;
cin >> type;
if (type == 1) {
cin >> l >> v;
One[a[l]].erase(l);
if (l > 1) Two[lca(a[l - 1], a[l])].erase(l);
a[l] = v;
One[a[l]].insert(l);
if (l != 1) Two[lca(a[l], a[l - 1])].insert(l);
}
else {
cin >> l >> r >> v;
auto InOne = *lower_bound(One[v].begin(), One[v].end(), l);
if (!One[v].empty() && l <= InOne && InOne <= r) {
cout << InOne << ' ' << InOne << '\n';
continue;
}
auto InTwo = *lower_bound(Two[v].begin(), Two[v].end(), l + 1);
if (!Two[v].empty() && l < InTwo && InTwo <= r) {
cout << InTwo - 1 << ' ' << InTwo << '\n';
continue;
}
cout << "-1 -1\n";
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
95 ms |
117880 KB |
n=5 |
2 |
Correct |
95 ms |
117984 KB |
n=100 |
3 |
Incorrect |
97 ms |
117984 KB |
Wrong range. |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
95 ms |
117880 KB |
n=5 |
2 |
Correct |
95 ms |
117984 KB |
n=100 |
3 |
Incorrect |
97 ms |
117984 KB |
Wrong range. |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
95 ms |
117880 KB |
n=5 |
2 |
Correct |
95 ms |
117984 KB |
n=100 |
3 |
Incorrect |
97 ms |
117984 KB |
Wrong range. |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
95 ms |
117880 KB |
n=5 |
2 |
Correct |
95 ms |
117984 KB |
n=100 |
3 |
Incorrect |
97 ms |
117984 KB |
Wrong range. |
4 |
Halted |
0 ms |
0 KB |
- |