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 <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ALL(v) (v).begin(), (v).end()
#define MASK(i) (1LL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
// mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng(1);
ll rngesus(ll l, ll r){return ((ull) rng()) % (r - l + 1) + l;}
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll LASTBIT(ll mask){return mask & (-mask);}
ll pop_cnt(ll mask){return __builtin_popcountll(mask);}
ll ctz(ll mask){return __builtin_ctzll(mask);}
ll clz(ll mask){return __builtin_clzll(mask);}
ll logOf(ll mask){return 63 - clz(mask);}
template <class T1, class T2>
bool minimize(T1 &a, T2 b){
if (a > b){a = b; return true;}
return false;
}
template <class T1, class T2>
bool maximize(T1 &a, T2 b){
if (a < b){a = b; return true;}
return false;
}
template <class T>
void printArr(T a, string separator = " ", string finish = "\n", ostream& out = cout){
for(auto i: a) out << i << separator;
out << finish;
}
template <class T>
void remove_dup(vector<T> &a){
sort(ALL(a));
a.resize(unique(ALL(a)) - a.begin());
}
const int N = 2e5 + 69, LOG_N = 18;
int n, m, q;
vector<int> graph[N];
int h[N], parent[N][LOG_N];
void dfs(int u, int p){
h[u] = h[p] + 1;
for(int j = 1; MASK(j) < h[u]; ++j)
parent[u][j] = parent[parent[u][j-1]][j-1];
for(int v: graph[u]) if (v != p){
parent[v][0] = u;
dfs(v, u);
}
}
int LCA(int u, int v){
if (h[u] < h[v]) swap(u, v);
int diff = h[u] - h[v];
for(int j = 0; j < LOG_N; ++j) if (GETBIT(diff, j))
u = parent[u][j];
if (u == v) return u;
for(int j = LOG_N - 1; j>=0; --j) if (parent[u][j] != parent[v][j]){
u = parent[u][j];
v = parent[v][j];
}
return parent[u][0];
}
set<int> S[N];
set<int> val[N];
int a[N];
int main(void){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m >> q;
for(int i = 1; i<n; ++i){
int u, v; cin >> u >> v;
graph[u].push_back(v);
graph[v].push_back(u);
}
dfs(1, 0);
for(int i = 1; i<=m; ++i) cin >> a[i];
for(int i = 1; i<m; ++i) S[LCA(a[i], a[i+1])].insert(i);
for(int i = 1; i<=m; ++i) val[a[i]].insert(i);
while(q--){
int type; cin >> type;
if (type == 1){
int i, v; cin >> i >> v;
if (i > 1){
S[LCA(a[i-1], a[i])].erase(i-1);
S[LCA(a[i-1], v)].insert(i-1);
}
if (i < m){
S[LCA(a[i], a[i+1])].erase(i);
S[LCA(v, a[i+1])].insert(i);
}
val[a[i]].erase(i);
a[i] = v;
val[a[i]].insert(i);
}
else{
int l, r, v; cin >> l >> r >> v;
auto it = S[v].lower_bound(l);
if (it == S[v].end() || *it >= r) {
it = val[v].lower_bound(l);
if (it == val[v].end() || *it > r) cout << "-1 -1\n";
else cout << *it << " " << *it << "\n";
}
else{
int u = *it;
cout << u << " " << u+1 << "\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... |