This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cstring>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template<typename T, typename V>
void __print(const pair<T, V> &x) {
cerr << '{';
__print(x.first);
cerr << ',';
__print(x.second);
cerr << '}';
}
template<typename T>
void __print(const T &x) {
int f = 0;
cerr << '{';
for (auto &i: x) cerr << (f++ ? "," : ""), __print(i);
cerr << "}";
}
void _print() { cerr << "]\n"; }
template<typename T, typename... V>
void _print(T t, V... v) {
__print(t);
if (sizeof...(v)) cerr << ", ";
_print(v...);
}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define ff first
#define sc second
#define pb push_back
#define ll long long
#define pll pair<ll, ll>
#define pii pair <int, int>
#define ull unsigned long long
// #define int long long
// #define int unsigned long long
const ll inf = 1e9 + 7;
const ll weirdMod = 998244353;
vector<int> adj[200005];
set<int> pos[200005], lpos[200005];
int x, y, par[200005][18], in[200005], out[200005], tim;
void dfs(int v, int p) {
in[v] = ++tim;
par[v][0] = p;
for (int i = 1; i < 18; i++)
par[v][i] = par[par[v][i - 1]][i - 1];
for (int u : adj[v]) if (u != p) dfs(u, v);
out[v] = ++tim;
}
bool anc(int a, int b) {
return (in[a] <= in[b] && out[a] >= out[b]);
}
int lca(int x, int y) {
if (anc(x, y)) return x;
if (anc(y, x)) return y;
for (int i = 17; i >= 0; i--) {
if (par[x][i] == 0) continue;
if (!anc(par[x][i], y)) x = par[x][i];
} return par[x][0];
}
void solve() {
int n, m, q;
cin >> n >> m >> q;
for (int i = 1; i < n; i++) {
cin >> x >> y;
adj[x].pb(y); adj[y].pb(x);
} int arr[m + 1];
for (int i = 1; i <= m; i++) {
cin >> arr[i]; pos[arr[i]].insert(i);
} dfs(1, 0);
for (int i = 2; i <= m; i++)
lpos[lca(arr[i], arr[i - 1])].insert(i);
int tst, l, r, v;
for (int i = 1; i <= q; i++) {
cin >> tst;
if (tst & 1) {
cin >> l >> v;
pos[arr[l]].erase(l);
if (l > 1) lpos[lca(arr[l], arr[l - 1])].erase(l);
if (l < m) lpos[lca(arr[l], arr[l + 1])].erase(l + 1);
arr[l] = v;
pos[arr[l]].insert(l);
if (l > 1) lpos[lca(arr[l], arr[l - 1])].insert(l);
if (l < m) lpos[lca(arr[l], arr[l + 1])].insert(l + 1);
} else {
cin >> l >> r >> v;
auto it = pos[v].lower_bound(l);
if (it != pos[v].end() && *it <= r) {
cout << *it << ' ' << *it << '\n'; continue;
} it = lpos[v].lower_bound(l + 1);
if (it != lpos[v].end() && *it <= r) {
cout << *it - 1 << ' ' << *it << '\n'; continue;
} cout << "-1 -1\n";
}
}
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
int t = 1;
// cin >> t;
while (t--) {
solve();
cout << '\n';
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |