Submission #465986

#TimeUsernameProblemLanguageResultExecution timeMemory
465986nathanlee726Two Antennas (JOI19_antennas)C++14
100 / 100
723 ms58084 KiB
//#include<i_am_noob_orz> #include<bits/stdc++.h> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; #define ll long long #define int ll #define ull unsigned long long #define pii pair<int,int> #define X first #define Y second #define mod ((ll)1e9+7) #define pb push_back #define mp make_pair #define abs(x) ((x)>0?(x):(-(x))) #define F(n) Fi(i,n) #define Fi(i,n) Fl(i,0,n) #define Fl(i,l,n) for(int i=l;i<n;i++) #define memres(a) memset(a,0,sizeof(a)) #define all(a) a.begin(),a.end() #define sz(a) ((int)a.size()) #define ceiling(a,b) (((a)+(b)-1)/(b)) #define endl '\n' #define bit_count(x) __builtin_popcountll((x)) #define ykh mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define jimmy_is_kind false typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree; //#define LOCAL #ifdef LOCAL #define bug(...) cerr<<"#"<<__LINE__<<' '<<#__VA_ARGS__<<"- ", _do(__VA_ARGS__) template<typename T> void _do(T && x) {cerr<<x<<endl;} template<typename T, typename ...S> void _do(T && x, S&&...y) {cerr<<x<<", "; _do(y...);} #define IOS() #else #define IOS() ios_base::sync_with_stdio(0), cin.tie(0) #define endl '\n' #define bug(...) #endif int add(int a,int b){return(a+b>=mod?a+b-mod:a+b);} int sub(int a,int b){return(a<b?a+mod-b:a-b);} int po(int a,int b){ if(b==0)return 1; if(b==1)return(a%mod); int tem=po(a,b/2); if(b&1)return(((tem*tem)%mod)*a)%mod; else return(tem*tem)%mod; } int GCD(int a,int b){ int x=0; int ra,rb; while(a&&b){ if(((a&1)==0)&&((b&1)==0)){ a>>=1,b>>=1,x++; } else if((a^b)&1){ if(a&1)b>>=1; else a>>=1; } else{ ra=abs(a-b),rb=min(a,b); a=ra,b=rb; } } return max(a,b)<<x; } int gcd(int a,int b){if(b==0)return a;return gcd(b,a%b);} int h[200010],o[200010]; pii b[200010]; pair<pii,int> qr[200010]; vector<pii> ev; struct NODE{ int v,mi,ma,ti,ta; NODE():v(-1e15),mi(1e15),ma(-1e15),ti(-1e15),ta(1e15){} }seg[800010]; void pull(int p){ seg[p].mi=min(seg[p*2].mi,seg[p*2+1].mi); seg[p].ma=max(seg[p*2].ma,seg[p*2+1].ma); seg[p].v=max(seg[p*2].v,seg[p*2+1].v); } void push(int p,int l,int mi,int r){ seg[p*2].ta=min(seg[p*2].ta,seg[p].ta); seg[p*2+1].ta=min(seg[p*2+1].ta,seg[p].ta); seg[p*2].ti=max(seg[p*2].ti,seg[p].ti); seg[p*2+1].ti=max(seg[p*2+1].ti,seg[p].ti); seg[p*2].v=max(seg[p*2].v,max(seg[p*2].ma-seg[p*2].ta,seg[p*2].ti-seg[p*2].mi)); seg[p*2+1].v=max(seg[p*2+1].v,max(seg[p*2+1].ma-seg[p*2+1].ta,seg[p*2+1].ti-seg[p*2+1].mi)); seg[p].ti=-1e15,seg[p].ta=1e15; } void insert(int p,int l,int r,int x,int d){ if(l==r){ seg[p].ti=-1e15,seg[p].ta=1e15; if(d==-1){ seg[p].ma=-1e15,seg[p].mi=1e15; } else{ seg[p].ma=seg[p].mi=d; } return; } int mi=(l+r)/2; push(p,l,mi,r); if(x>mi)insert(p*2+1,mi+1,r,x,d); else insert(p*2,l,mi,x,d); pull(p); } void modify(int p,int l,int r,int ql,int qr,int v){ if(ql>r||qr<l)return; if(l>=ql&&r<=qr){ seg[p].ti=max(seg[p].ti,v); seg[p].ta=min(seg[p].ta,v); seg[p].v=max(seg[p].v,max(seg[p].ma-seg[p].ta,seg[p].ti-seg[p].mi)); return; } int mi=(l+r)/2; push(p,l,mi,r); modify(p*2,l,mi,ql,qr,v); modify(p*2+1,mi+1,r,ql,qr,v); pull(p); } int query(int p,int l,int r,int ql,int qr){ if(ql>r||qr<l)return -1e15; if(l>=ql&&r<=qr){bug(p,l,r,ql,qr,seg[p].v);return seg[p].v;} int mi=(l+r)/2; push(p,l,mi,r); return max(query(p*2,l,mi,ql,qr),query(p*2+1,mi+1,r,ql,qr)); } bool cmp(pair<pii,int> a,pair<pii,int> b){ if(a.X.Y==b.X.Y)return a.X.X<b.X.X; else return a.X.Y<b.X.Y; } bool cmp1(pii a,pii b){ if(a.X==b.X)return a.Y>b.Y; else return a.X<b.X; } signed main(){ IOS(); int n; cin>>n; F(n)cin>>h[i]>>b[i].X>>b[i].Y; int q; cin>>q; F(q)cin>>qr[i].X.X>>qr[i].X.Y,qr[i].X.X--,qr[i].X.Y--; F(q)qr[i].Y=i; sort(qr,qr+q,cmp); F(n){ ev.pb({min(n,i+b[i].X),i+1}); ev.pb({min(n,i+b[i].Y+1),-i-1}); } sort(all(ev),cmp1); int p0=0,p1=0; F(n){ while(p0<sz(ev)&&ev[p0].X==i){ if(ev[p0].Y>0){ insert(1,0,n-1,ev[p0].Y-1,h[ev[p0].Y-1]); } else{ insert(1,0,n-1,-ev[p0].Y-1,-1); } p0++; } if(i-b[i].X>=0ll)modify(1,0,n-1,max(0ll,i-b[i].Y),max(0ll,i-b[i].X),h[i]); while(p1<q&&qr[p1].X.Y==i){ o[qr[p1].Y]=query(1,0,n-1,qr[p1].X.X,qr[p1].X.Y); if(o[qr[p1].Y]<0)o[qr[p1].Y]=-1; p1++; } } F(q)cout<<o[i]<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...