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;
#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 = 5e2+5;
int n, m, q, a[N], par[N], used[N], s;
vector<int>edges[N], tree;
vector<pii>seg;
int lca(int f, int s){
if(used[f]) return f;
used[f] = 1;
if(used[s]) return s;
used[s] = 1;
return lca(par[f], par[s]);
}
void build(int lx, int rx, int x){
if(lx == rx){
tree[x] = a[lx];
return;
}
int m = (lx + rx)/2;
build(lx, m, x*2);
build(m+1, rx, x*2+1);
seg[x] = {lx, rx};
tree[x] = lca(tree[x*2], tree[x*2+1]);
memset(used, 0, sizeof(used));
}
void sett(int i, int v, int lx, int rx, int x){
if(lx == rx){
tree[x] = v;
return;
}
int m = (lx + rx)/2;
if(i <= m) sett(i, v, lx, m, x*2);
else sett(i, v, m+1 ,rx, x*2+1);
tree[x] = lca(tree[x*2], tree[x*2+1]);
memset(used, 0, sizeof(used));
}
int find(int l, int r, int lx, int rx, int x){
if(lx > r || rx < l) return -1;
if(lx >= l && rx <= r) return tree[x];
int m = (lx + rx)/2;
int res1 = find(l, r, lx, m, x*2);
int res2 = find(l, r, m+1, rx, x*2+1);
if(res1 == -1) return res2;
if(res2 == -1) return res1;
int res = lca(res1, res2);
memset(used, 0, sizeof(used));
return res;
}
void dfs(int u, int p){
par[u] = p;
for(auto x:edges[u]){
if(x == p) continue;
dfs(x, 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);
}
for(int i=1;i<=m;i++) cin>>a[i];
dfs(1, 0);
s = n*2;
tree.assign(2*s, 0);
seg.assign(2*s, {0, 0});
build(1, s, 1);
//print();
while(q--){
int t;
cin>>t;
if(t == 1){
int pos, val;
cin>>pos>>val;
sett(pos, val, 1, s, 1);
}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 res = find(l, rr, 1, s, 1);
//cout<<l<<" "<<rr<<" "<<res<<endl;
if(res == 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 |
---|
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... |