#include<bits/stdc++.h>
#pragma optimize ("g",on)
#pragma GCC optimize ("inline")
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("03")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,avx2,mmx,fma,avx,tune=native")
#pragma comment(linker, "/stack:200000000")
//01001101 01100001 01101011 01101000 01100001 01100111 01100001 01111001
using namespace std;
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ll long long
#define pb push_back
#define sz(a) a.size()
#define nl '\n'
#define popb pop_back()
#define ld double
#define ull unsigned long long
#define ff first
#define ss second
#define fix fixed << setprecision
#define pii pair<int, int>
#define E exit (0)
const int inf = 1e9, N = 1e6 + 1, mod = 998244353;
vector<pii> dir = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
int tin[N], tout[N], timer;
int up[N][18], b[400], lc[400];
vector<int> adj[N];
const int k = 300;
void dfs(int u, int p) {
tin[u] = timer++;
up[u][0] = p;
for (int i = 1; i < 18; i++) up[u][i] = up[up[u][i - 1]][i - 1];
for (auto e: adj[u]) {
if (e != p) dfs(e, u);
}
tout[u] = timer;
}
bool is(int a, int b) {
return tin[a] <= tin[b] && tout[a] >= tout[b];
}
int lca(int u, int v) {
if (is(u, v)) return u;
if (is(v, u)) return v;
for (int i = 17; i >= 0; i--) {
int x = up[u][i];
if (is(x, v)) continue;
u = x;
}
return up[u][0];
}
main() {
//freopen("cowrect.in", "r", stdin);
//freopen("cowrect.out", "w", stdout);
ios_base::sync_with_stdio(NULL);
cin.tie(NULL);
int n, m, q;
cin >> n >> m >> q;
for (int i = 1; i < n; i++) {
int u, v;
cin >> u >> v;
adj[u].pb(v);
adj[v].pb(u);
}
int a[m];
for (int i = 0; i < m; i++) {
cin >> a[i];
b[i] = i / k;
if (i % k == 0) lc[b[i]] = a[i];
lc[b[i]] = lca(lc[b[i]], a[i]);
}
dfs(1, 1);
while (q--) {
int t;
cin >> t;
if (t == 1) {
int pos, v;
cin >> pos >> v;
pos--;
a[pos] = v;
lc[b[pos]] = v;
for (int i = b[pos] * k; i < min(m, (b[pos] + 1) * k); i++) {
lc[b[pos]] = lca(lc[b[pos]], a[i]);
}
}else {
int l, r, v;
cin >> l >> r >> v;
bool ok = 0;
for (int tl = b[l]; tl <= b[r] && !ok; tl++) {
int cur = lc[tl];
for (int tr = tl; tr <= b[r] && !ok; tr++) {
if (tr == tl) {
for (int x = tl * k; x < min((tl + 1) * k, m) && !ok; x++) {
int val = a[x];
for (int y = x; y < min((tl + 1) * k, m); y++) {
val = lca(val, a[y]);
if (val == v) {
cout << x + 1 << ' ' << y + 1 << nl;
ok = 1;
break;
}
}
}
}else {
int val = lca(cur, a[min((tl + 1) * k, m) - 1]);
for (int x = min((tl + 1) * k, m) - 1; x >= tl * k && !ok; x--) {
val = lca(val, a[x]);
int z = val;
for (int y = tr * k; y < min((tr + 1) * k, m); y++) {
z = lca(z, a[y]);
if (z == v) {
cout << x + 1 << ' ' << y + 1 << nl;
ok = 1;
break;
}
}
}
}
cur = lca(cur, lc[tr]);
}
}
if (!ok) cout << -1 << ' ' << -1 << nl;
}
}
}
Compilation message
treearray.cpp:3: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
3 | #pragma optimize ("g",on)
|
treearray.cpp:9: warning: ignoring '#pragma comment ' [-Wunknown-pragmas]
9 | #pragma comment(linker, "/stack:200000000")
|
treearray.cpp:67:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
67 | main() {
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
23756 KB |
Wrong output format. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
23756 KB |
Wrong output format. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
23756 KB |
Wrong output format. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
23756 KB |
Wrong output format. |
2 |
Halted |
0 ms |
0 KB |
- |