Submission #889673

#TimeUsernameProblemLanguageResultExecution timeMemory
889673AiperiiiTourism (JOI23_tourism)C++14
7 / 100
178 ms13100 KiB
#include <bits/stdc++.h> #define int long long #define all(x) x.begin(),x.end() #define ff first #define ss second #define pb push_back using namespace std; const int N=1e5+5; int mn[N*4],mx[N*4],c[N]; void build(int v,int tl,int tr){ if(tl==tr){ mn[v]=c[tl]; mx[v]=c[tl]; } else{ int tm=(tl+tr)/2; build(v*2,tl,tm); build(v*2+1,tm+1,tr); mn[v]=min(mn[v*2],mn[v*2+1]); mx[v]=max(mx[v*2],mx[v*2+1]); } } int get_mn(int v,int tl,int tr,int l,int r){ if(r<tl or l>tr)return INT_MAX; if(l<=tl && tr<=r)return mn[v]; int tm=(tl+tr)/2; return min(get_mn(v*2,tl,tm,l,r),get_mn(v*2+1,tm+1,tr,l,r)); } int get_mx(int v,int tl,int tr,int l,int r){ if(r<tl or l>tr)return INT_MIN; if(l<=tl && tr<=r)return mx[v]; int tm=(tl+tr)/2; return max(get_mx(v*2,tl,tm,l,r),get_mx(v*2+1,tm+1,tr,l,r)); } signed main(){ ios_base::sync_with_stdio(); cin.tie(0); int n,m,qq; cin>>n>>m>>qq; vector <int> g[n+1]; for(int i=0;i<n-1;i++){ int u,v; cin>>u>>v; g[u].pb(v); g[v].pb(u); } for(int i=1;i<=m;i++){ cin>>c[i]; } build(1,1,m); while(qq--){ int l,r; cin>>l>>r; cout<<get_mx(1,1,m,l,r)-get_mn(1,1,m,l,r)+1<<"\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...