제출 #124730

#제출 시각아이디문제언어결과실행 시간메모리
124730MvCTwo Antennas (JOI19_antennas)C++11
100 / 100
771 ms48512 KiB
#pragma GCC target("avx2") #pragma GCC optimization("O3") #pragma GCC optimization("unroll-loops") #include<bits/stdc++.h> //#include "rail.h" #define rc(x) return cout<<x<<endl,0 #define pb push_back #define mkp make_pair #define in insert #define er erase #define fd find #define fr first #define sc second typedef long long ll; typedef long double ld; const ll INF=0x3f3f3f3f3f3f3f3f; const ll llinf=(1LL<<62); const int inf=(1<<30); const int nmax=2e5+50; const int mod=1e9+7; using namespace std; int n,i,j,rs[nmax],h[nmax],a[nmax],b[nmax],q,x,l[nmax],r[nmax],dmn[4*nmax],dmx[4*nmax],lzmn[4*nmax],lzmx[4*nmax]; vector<int>ad[nmax],re[nmax],qr[nmax]; pair<int,int>st[4*nmax]; void push(int nod,int l,int r) { dmn[nod]=max(dmn[nod],lzmx[nod]-st[nod].sc); dmx[nod]=max(dmx[nod],st[nod].fr-lzmn[nod]); if(l!=r) { lzmn[2*nod]=min(lzmn[2*nod],lzmn[nod]); lzmn[2*nod+1]=min(lzmn[2*nod+1],lzmn[nod]); lzmx[2*nod]=max(lzmx[2*nod],lzmx[nod]); lzmx[2*nod+1]=max(lzmx[2*nod+1],lzmx[nod]); } lzmn[nod]=inf,lzmx[nod]=-inf; } void upd(int nod,int l,int r,int tl,int tr,int v) { push(nod,l,r); if(tl<=l && r<=tr) { lzmn[nod]=v; lzmx[nod]=v; push(nod,l,r); return; } int mid=(l+r)/2; if(tl<=mid)upd(nod*2,l,mid,tl,tr,v); if(mid<tr)upd(nod*2+1,mid+1,r,tl,tr,v); push(nod*2,l,mid); push(nod*2+1,mid+1,r); dmn[nod]=max(dmn[2*nod],dmn[2*nod+1]); dmx[nod]=max(dmx[2*nod],dmx[2*nod+1]); } pair<int,int> merge(pair<int,int>x,pair<int,int>y) { return mkp(max(x.fr,y.fr),min(x.sc,y.sc)); } void up(int x,int l,int r,int p,int v) { if(l>r)return; push(x,l,r); if(l==r) { if(v==-1)st[x]=mkp(-inf,inf); else st[x]=mkp(v,v); return; } int mid=(l+r)/2; if(p<=mid)up(2*x,l,mid,p,v); else up(2*x+1,mid+1,r,p,v); push(x*2,l,mid); push(x*2+1,mid+1,r); st[x]=merge(st[2*x],st[2*x+1]); dmn[x]=max(dmn[2*x],dmn[2*x+1]); dmx[x]=max(dmx[2*x],dmx[2*x+1]); } int qry(int nod,int l,int r,int tl,int tr) { push(nod,l,r); if(tl<=l && r<=tr)return max(dmn[nod],dmx[nod]); int mid=(l+r)/2,vl=-inf; if(tl<=mid)vl=max(vl,qry(nod*2,l,mid,tl,tr)); if(mid<tr)vl=max(vl,qry(nod*2+1,mid+1,r,tl,tr)); return vl; } int main() { //freopen("sol.in","r",stdin); //freopen("sol.out","w",stdout); //mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0); cin>>n; for(i=1;i<=n;i++) { cin>>h[i]>>a[i]>>b[i]; ad[min(n+1,i+a[i])].pb(i); re[min(n+1,i+b[i]+1)].pb(i); } cin>>q; for(i=1;i<=q;i++) { cin>>l[i]>>r[i]; qr[r[i]].pb(i); } for(i=1;i<=4*n;i++) { st[i]=mkp(-inf,inf); lzmn[i]=inf; lzmx[i]=-inf; dmn[i]=dmx[i]=-inf; } for(i=1;i<=n;i++) { for(j=0;j<ad[i].size();j++) { up(1,1,n,ad[i][j],h[ad[i][j]]); } for(j=0;j<re[i].size();j++) { up(1,1,n,re[i][j],-1); } if(i-a[i]>=1) { upd(1,1,n,max(i-b[i],1),max(i-a[i],1),h[i]); } for(j=0;j<qr[i].size();j++) { rs[qr[i][j]]=qry(1,1,n,l[qr[i][j]],i); } } for(i=1;i<=q;i++)cout<<max(-1,rs[i])<<'\n'; return 0; }

컴파일 시 표준 에러 (stderr) 메시지

antennas.cpp:2:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization("O3")
 
antennas.cpp:3:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization("unroll-loops")
 
antennas.cpp: In function 'int main()':
antennas.cpp:116:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(j=0;j<ad[i].size();j++)
           ~^~~~~~~~~~~~~
antennas.cpp:120:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(j=0;j<re[i].size();j++)
           ~^~~~~~~~~~~~~
antennas.cpp:128:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(j=0;j<qr[i].size();j++)
           ~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...