#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
const int lg = 18;
const int mx = 200'000;
vvi anc(1+mx, vi(1+lg, 1));
vi edge[1+mx];
vi depth(1+mx, 0);
void dfs(int u)
{
for(int v: edge[u])
{
if(anc[u][0] == v) continue;
depth[v] = 1 + depth[u];
anc[v][0] = u;
dfs(v);
}
}
int lca(int u, int v)
{
if(depth[u] > depth[v]) swap(u, v);
for(int e = 0; e <= lg; e++)
if((depth[v] - depth[u]) & (1 << e))
v = anc[v][e];
if(u == v) return u;
for(int e = lg; e >= 0; e--)
{
if(anc[u][e] != anc[v][e])
{
u = anc[u][e];
v = anc[v][e];
}
}
return anc[u][0];
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m, q;
cin >> n >> m >> q;
for(int e = 1; e <= n-1; e++)
{
int u, v;
cin >> u >> v;
edge[u].push_back(v);
edge[v].push_back(u);
}
dfs(1);
for(int e = 1; e <= lg; e++)
for(int u = 1; u <= n; u++)
anc[u][e] = anc[ anc[u][e-1] ][e-1];
vi a(1+m);
for(int i = 1; i <= m; i++) cin >> a[i];
vi L(m);
for(int i = 1; i < m; i++) L[i] = lca(a[i], a[i+1]);
set<int> occ[1+n];
for(int i = 1; i < m; i++)
occ[L[i]].insert(i);
for(int x = 1; x <= q; x++)
{
int t;
cin >> t;
if(t == 1)
{
int p, v;
cin >> p >> v;
if(p > 1)
occ[L[p-1]].erase(p-1);
if(p < m)
occ[L[p]].erase(p);
a[p] = v;
if(p > 1)
L[p-1] = lca(a[p-1], a[p]);
if(p < m)
L[p] = lca(a[p], a[p+1]);
if(p > 1)
occ[L[p-1]].insert(p-1);
if(p < m)
occ[L[p]].insert(p);
}
else
{
int l, r, v;
cin >> l >> r >> v;
auto z = occ[v].lower_bound(l);
if(z == occ[v].end() || *z >= r) cout << "-1 -1\n";
else cout << *z << ' ' << (*z)+1 << '\n';
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
18 ms |
29260 KB |
Jury has the answer but participant has not |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
18 ms |
29260 KB |
Jury has the answer but participant has not |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
18 ms |
29260 KB |
Jury has the answer but participant has not |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
18 ms |
29260 KB |
Jury has the answer but participant has not |
2 |
Halted |
0 ms |
0 KB |
- |