Submission #776734

#TimeUsernameProblemLanguageResultExecution timeMemory
776734bachhoangxuanTwo Antennas (JOI19_antennas)C++17
100 / 100
324 ms44484 KiB
// Judges with GCC >= 12 only needs Ofast // #pragma GCC optimize("O3,no-stack-protector,fast-math,unroll-loops,tree-vectorize") // MLE optimization // #pragma GCC optimize("conserve-stack") // Old judges // #pragma GCC target("sse4.2,popcnt,lzcnt,abm,mmx,fma,bmi,bmi2") // New judges. Test with assert(__builtin_cpu_supports("avx2")); // #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native") // Atcoder // #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma") /* #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; - insert(x),erase(x) - find_by_order(k): return iterator to the k-th smallest element - order_of_key(x): the number of elements that are strictly smaller */ #include<bits/stdc++.h> using namespace std; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); uniform_real_distribution<> pp(0.0,1.0); //#define int long long #define ld long double #define pii pair<int,int> #define piii pair<pii,int> #define mpp make_pair #define fi first #define se second const int inf=1e9+1; const int mod=1e9+7; const int maxn=200005; const int bl=650; const int maxs=655; const int maxm=200005; const int maxq=500005; const int maxl=20; const int maxa=250000; const int root=3; /* int power(int a,int n){ int res=1; while(n){ if(n&1) res=res*a%mod; a=a*a%mod;n>>=1; } return res; } const int iroot=power(3,mod-2); */ const int base=101; int n,h[maxn],a[maxn],b[maxn],ans[maxn]; vector<pii> query[maxn],add[maxn]; struct node{ int Max=0,Min=inf,res=-1,lMax=0,lMin=inf; node(){} friend node operator+(node a,node b){ node res; res.Max=max(a.Max,b.Max); res.Min=min(a.Min,b.Min); res.res=max(a.res,b.res); return res; } }; namespace Segtree{ node tree[4*maxn]; void getnew(int id,int Max,int Min){ if(tree[id].Max==0) return; tree[id].lMax=max(tree[id].lMax,Max); tree[id].lMin=min(tree[id].lMin,Min); tree[id].res=max(tree[id].res,max(tree[id].Max-tree[id].lMin,tree[id].lMax-tree[id].Min)); } void pushdown(int id){ if(tree[id].lMax==0) return; getnew(id<<1,tree[id].lMax,tree[id].lMin); getnew(id<<1|1,tree[id].lMax,tree[id].lMin); tree[id].lMax=0;tree[id].lMin=inf; } void update_pos(int l,int r,int id,int p,int val){ if(l==r){ if(val) tree[id].Max=tree[id].Min=h[p]; else tree[id].Max=0,tree[id].Min=inf; return; } pushdown(id); int mid=(l+r)>>1; if(p<=mid) update_pos(l,mid,id<<1,p,val); else update_pos(mid+1,r,id<<1|1,p,val); tree[id]=tree[id<<1]+tree[id<<1|1]; } void update(int l,int r,int id,int tl,int tr,int val){ if(tr<l || r<tl) return; if(tl<=l && r<=tr){ getnew(id,val,val); return; } pushdown(id); int mid=(l+r)>>1; update(l,mid,id<<1,tl,tr,val);update(mid+1,r,id<<1|1,tl,tr,val); tree[id]=tree[id<<1]+tree[id<<1|1]; } int query(int l,int r,int id,int tl,int tr){ if(tr<l || r<tl) return -1; if(tl<=l && r<=tr) return tree[id].res; pushdown(id); int mid=(l+r)>>1; return max(query(l,mid,id<<1,tl,tr),query(mid+1,r,id<<1|1,tl,tr)); } } void solve(){ cin >> n; for(int i=1;i<=n;i++){ cin >> h[i] >> a[i] >> b[i]; int l=i+a[i],r=i+b[i]; if(l<=n) add[l].push_back({i,1}); if(r<n) add[r+1].push_back({i,0}); } int q;cin >> q; for(int i=1;i<=q;i++){ int l,r;cin >> l >> r; query[r].push_back({l,i}); } for(int i=1;i<=n;i++){ for(auto &[p,val]:add[i]) Segtree::update_pos(1,n,1,p,val); int lt=max(1,i-b[i]),rt=i-a[i]; //cout << lt << ' ' << rt << ' ' << i << '\n'; if(lt<=rt) Segtree::update(1,n,1,lt,rt,h[i]); for(auto &[l,id]:query[i]) ans[id]=Segtree::query(1,n,1,l,i); } for(int i=1;i<=q;i++) cout << ans[i] << '\n'; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); int test=1;//cin >> test; while(test--) solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...