#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define ll long long
#define ld long double
#define pii pair<int, int>
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(),x.rend()
#define prc(n) fixed << setprecision(n)
#define fastios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pi acos(-1);
const int inf = 1e9+7;
const int N = 2000;
int n, m, q, a[N], par[N], used[N], s, dis[N], fir[N];
vector<int>edges[N];
vector<pii>tree;
vector<int>order;
// ff = min
// ss = which
void build(int lx, int rx, int x){
if(lx == rx){
if(lx > sz(order)) return;
tree[x].ff = dis[order[lx-1]];
tree[x].ss = order[lx-1];;
return;
}
int m = (lx + rx)/2;
build(lx, m, x*2);
build(m+1, rx, x*2+1);
if(tree[x*2].ff <= tree[x*2+1].ff) tree[x] = tree[x*2];
else tree[x] = tree[x*2+1];
}
pii find(int l, int r, int lx, int rx, int x){
if(lx > r || rx < l) return {inf, inf};
if(lx >= l && rx <= r) return tree[x];
int m = (lx + rx)/2;
pii res1 = find(l, r, lx, m, x*2);
pii res2 = find(l, r, m+1, rx, x*2+1);
return (res1.ff < res2.ff ? res1 : res2);
}
void print(){
for(int i=1;i<2*s;i++) cout<<tree[i].ff<<" ";
cout<<"\n";
for(int i=1;i<2*s;i++) cout<<tree[i].ss<<" ";
cout<<"\n";
cout<<"\n";
}
void dfs(int u, int p, int d){
order.pb(u);
dis[u] = d;
if(fir[u] == -1) fir[u] = sz(order);
for(auto x:edges[u]){
if(x == p) continue;
dfs(x, u, d+1);
order.pb(u);
}
}
void solve(){
cin>>n>>m>>q;
for(int i=1;i<n;i++){
int a, b;
cin>>a>>b;
edges[a].pb(b);
edges[b].pb(a);
}
memset(fir, -1, sizeof(fir));
dfs(1, 0, 0);
s = 2;
while(s < sz(order)) s*=2;
tree.assign(2*s, {inf, inf});
build(1, s, 1);
for(int i=1;i<=m;i++) cin>>a[i];
while(q--){
int t;
cin>>t;
if(t == 1){
int pos, val;
cin>>pos>>val;
a[pos] = val;
}
else{
int l, r, val, rr;
cin>>l>>r>>val;
int la = -1, ra = -1;
for(;l<= r; l++){
for(rr = l; rr <= r; rr++){
int lx = min(fir[a[l]], fir[a[rr]]), rx = max(fir[a[l]], fir[a[rr]]);
pii res = find(lx, rx, 1, s, 1);
//cout<<lx<<" "<<rx<<" "<<l<<" "<<rr<<" "<<res.ss<<endl;
if(res.ss == val){
if(rr - l +1 >= ra - la +1) la = l, ra = rr;
}
}
}
cout<<la<<" "<<ra<<"\n";
}
}
return;
}
int main(){
fastios
int t = 1;
//cin>>t;
while(t--) solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
n=5 |
2 |
Incorrect |
11 ms |
364 KB |
Wrong range. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
n=5 |
2 |
Incorrect |
11 ms |
364 KB |
Wrong range. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
n=5 |
2 |
Incorrect |
11 ms |
364 KB |
Wrong range. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
n=5 |
2 |
Incorrect |
11 ms |
364 KB |
Wrong range. |
3 |
Halted |
0 ms |
0 KB |
- |