이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << "[" << H << "]";
debug_out(T...);
}
#ifdef dddxxz
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
#define SZ(s) ((int)s.size())
#define all(x) (x).begin(), (x).end()
#define revall(x) (x).rbegin(), (x).rend()
clock_t startTime;
double getCurrentTime() {
return (double) (clock() - startTime) / CLOCKS_PER_SEC;
}
#define MP make_pair
typedef long long ll;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
const double eps = 0.00001;
const int MOD = 1e9 + 7;
const int INF = 1000000101;
const long long LLINF = 1223372000000000555;
const int N = 2e5 + 3e2;
const int M = 222;
vector<int> g[N];
int tin[N], tout[N], up[N][20], timer = 0;
void dfs(int v, int p){
tin[v] = ++timer;
up[v][0] = p;
for (int i = 1; i < 20; i++){
up[v][i] = up[up[v][i - 1]][i - 1];
}
for (int u : g[v]){
if (u != p) dfs(u, v);
}
tout[v] = ++timer;
}
bool upper(int a, int b){
return tin[a] <= tin[b] && tout[a] >= tout[b];
}
int lca(int a, int b){
if (upper(a, b)) return a;
if (upper(b, a)) return b;
for (int i = 19; i >= 0; i--){
if (!upper(up[a][i], b)) a = up[a][i];
}
return up[a][0];
}
int a[N];
set<int> positions[N];
inline void add(int i){
int x = lca(a[i], a[i + 1]);
positions[x].insert(i);
}
inline void del(int i){
int x = lca(a[i], a[i + 1]);
positions[x].erase(i);
}
set<int> pos[N];
void solve(int TC) {
int n, m, q;
cin >> n >> m >> q;
for (int i = 1; i < n; i++){
int u, v;
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
dfs(1, 1);
for (int i = 1; i <= m; i++){
cin >> a[i];
pos[a[i]].insert(i);
}
for (int i = 1; i < m; i++) add(i);
while (q--){
int t;
cin >> t;
if (t == 1){
int i, v;
cin >> i >> v;
if (i > 1) del(i - 1);
if (i < m) del(i);
pos[a[i]].erase(i);
pos[v].insert(i);
a[i] = v;
if (i > 1) add(i - 1);
if (i < m) add(i);
} else {
int l, r, v;
cin >> l >> r >> v;
auto it = positions[v].lower_bound(l);
auto it2 = pos[v].lower_bound(l);
if (it != positions[v].end() && *it < r){
int x = *it;
cout << x << ' ' << x + 1 << endl;
} else if (it2 != pos[v].end() && *it2 <= r){
int x = *it2;
cout << x << ' ' << x << endl;
} else cout << -1 << ' ' << -1 << endl;
}
}
}
int main() {
startTime = clock();
cin.tie(nullptr); cout.tie(nullptr);
ios_base::sync_with_stdio(false);
bool llololcal = false;
#ifdef dddxxz
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
llololcal = true;
#endif
int TC = 1;
//cin >> TC;
for (int test = 1; test <= TC; test++) {
//debug(test);
//cout << "Case #" << test << ": ";
solve(test);
}
if (llololcal) cerr << endl << "Time: " << int(getCurrentTime() * 1000) << " ms" << endl;
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... |