#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb(e) push_back(e)
#define sv(a) sort(a.begin(),a.end())
#define sa(a,n) sort(a,a+n)
#define mp(a,b) make_pair(a,b)
#define vf first
#define vs second
#define ar array
#define all(x) x.begin(),x.end()
const int inf = 0x3f3f3f3f;
const int mod = 1000000007;
const double PI=3.14159265358979323846264338327950288419716939937510582097494459230;
bool remender(ll a , ll b){return a%b;}
/* in each query , the chosen x and y would be x == y or x + 1 == y */
/*
5 4 4
1 2
3 1
3 4
5 3
4 5 2 3
2 1 3 1
1 3 5
2 3 4 5
2 1 3 1
*/
const int N = 200004;
vector<int> adj[N];
const int L = 25;
int timer , up[N][L] , tin[N] , tout[N];
void dfs(int node , int par = 1){
//cout << node << ' ' << par << endl;
tin[node] = ++timer;
//cout << node << ' ';
up[node][0] = par;
for(int i = 1; i < L; i++)up[node][i] = up[up[node][i-1]][i-1];
for(int i : adj[node]){
if(i!=par)dfs(i , node);
}
tout[node] = ++timer;
}
bool islca(int x , int y){
return (tin[x] < tin[y] && tout[x] > tout[y]);
}
int findlca(int x , int y){
if(islca(x,y))return x;
if(islca(y,x))return y;
for(int i = L - 1; i >= 0; i--){
if(!islca(up[x][i] , y))x = up[x][i];
}
return up[x][0];
}
void solve(){
int n;
cin >> n;
int m;
cin >> m;
int q;
cin >> q;
for(int i = 0; i < n-1; i++){
int a , b;
cin >> a >> b;
adj[a].pb(b);
adj[b].pb(a);
}
timer = 0;
dfs(1);
int arr[m];
for(int i = 0; i < m; i++)cin >> arr[i];
set<int> cnt[n + 1];
set<int> itself[n + 1];
for(int i = 0; i < m - 1; i++){
cnt[findlca(arr[i] , arr[i + 1])].insert(i);
//cout << findlca(arr[i] , arr[i + 1]) << ' ';
}
for(int i = 0; i < m; i++){
itself[arr[i]].insert(i);
}
while(q--){
int op;
cin >> op;
if(op == 1){
int pos , v;
cin >> pos >> v;
pos--;
itself[arr[pos]].erase(pos);
if(pos + 1 < m)
cnt[findlca(arr[pos] , arr[pos + 1])].erase(pos);
if(pos - 1 >= 0)
cnt[findlca(arr[pos - 1] , arr[pos])].erase(pos-1);
arr[pos] = v;
itself[v].insert(pos);
if(pos + 1 < m){
cnt[findlca(v , arr[pos + 1])].insert(pos);
}
if(pos - 1 >= 0){
cnt[findlca(v, arr[pos - 1])].insert(pos - 1);
}
}
else {
int l , r , v;
cin >> l >> r >> v;
l--;
r--;
int ans1 , ans2;
ans1 = ans2 = -2;
auto it = itself[v].lower_bound(l);
if(it!=itself[v].end()){
int p = *it;
if(p <= r){
ans1 = ans2 = p;
}
}
if(l < r){
it = cnt[v].lower_bound(l);
if(it!=cnt[v].end()){
int pos = *it;
if(pos < r){
ans1 = pos;
ans2 = pos + 1;
}
}
}
if(ans1 >= l && ans2 <= r)
cout << ans1 + 1 << ' ' << ans2 + 1 << '\n';
else if(ans1 == -2 && ans2 == -2)cout << ans1 + 1 << ' ' << ans2 + 1 << '\n';
else {
while(1){
;
}
}
}
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//freopen("dec.in", "r", stdin);
//freopen("dec.out", "w", stdout);
//int t;cin >> t;while(t--)
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
n=5 |
2 |
Incorrect |
3 ms |
4940 KB |
Wrong range. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
n=5 |
2 |
Incorrect |
3 ms |
4940 KB |
Wrong range. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
n=5 |
2 |
Incorrect |
3 ms |
4940 KB |
Wrong range. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
n=5 |
2 |
Incorrect |
3 ms |
4940 KB |
Wrong range. |
3 |
Halted |
0 ms |
0 KB |
- |