제출 #554019

#제출 시각아이디문제언어결과실행 시간메모리
554019MilosMilutinovicTwo Antennas (JOI19_antennas)C++14
100 / 100
728 ms59268 KiB
#include <bits/stdc++.h> using namespace std; #define rep(i,a,n) for (int i=a;i<n;i++) #define per(i,a,n) for (int i=n-1;i>=a;i--) #define pb push_back #define eb emplace_back #define mp make_pair #define all(x) (x).begin(),(x).end() #define fi first #define se second #define SZ(x) ((int)(x).size()) typedef vector<int> VI; typedef long long ll; typedef pair<int,int> PII; typedef double db; mt19937 mrand(random_device{}()); const ll mod=1000000007; int rnd(int x) { return mrand() % x;} ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;} ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;} // head const int N=200050; const ll inf=(ll)1e18; int n,q,h[N],a[N],b[N],ql[N],qr[N]; ll ans[N]; vector<PII> Qs[N][2]; struct node{ ll val,mx,lzy; }nd[8*N]; void upd(int p,ll x) { nd[p].val=max(nd[p].val,nd[p].mx+x); nd[p].lzy=max(nd[p].lzy,x); } void push(int p) { if (nd[p].lzy==-inf) return; upd(p*2,nd[p].lzy); upd(p*2+1,nd[p].lzy); nd[p].lzy=-inf; } void build(int p,int l,int r) { nd[p].val=nd[p].mx=nd[p].lzy=-inf; if (l==r) return; int mid=(l+r)/2; build(p*2,l,mid); build(p*2+1,mid+1,r); } void modify(int p,int l,int r,int tl,ll x) { if (l==r) { nd[p].mx=x; return; } push(p); int mid=(l+r)/2; if (tl<=mid) modify(p*2,l,mid,tl,x); else modify(p*2+1,mid+1,r,tl,x); nd[p].mx=max(nd[p*2].mx,nd[p*2+1].mx); } void update(int p,int l,int r,int tl,int tr,ll x) { if (tl>tr||l>r||l>tr||r<tl) return; if (tl<=l&&r<=tr) { upd(p,x); push(p); return; } push(p); int mid=(l+r)/2; update(p*2,l,mid,tl,tr,x); update(p*2+1,mid+1,r,tl,tr,x); nd[p].val=max(nd[p*2].val,nd[p*2+1].val); } ll query(int p,int l,int r,int tl,int tr) { if (tl>tr||l>r||l>tr||r<tl) return -inf; if (tl<=l&&r<=tr) return nd[p].val; push(p); int mid=(l+r)/2; return max(query(p*2,l,mid,tl,tr),query(p*2+1,mid+1,r,tl,tr)); } void solve() { rep(i,1,n+1) { Qs[i][0].clear(); Qs[i][1].clear(); } rep(i,1,n+1) { Qs[min(n+1,i+a[i])][0].pb(mp(i,0)); Qs[min(n+1,i+b[i])][0].pb(mp(i,1)); } rep(i,1,q+1) Qs[qr[i]][1].pb(mp(i,ql[i])); build(1,1,n); rep(i,1,n+1) { for (auto qs:Qs[i][0]) if (qs.se==0) modify(1,1,n,qs.fi,h[qs.fi]); update(1,1,n,i-b[i],i-a[i],-h[i]); for (auto qs:Qs[i][1]) ans[qs.fi]=max(ans[qs.fi],query(1,1,n,qs.se,i)); for (auto qs:Qs[i][0]) if (qs.se==1) modify(1,1,n,qs.fi,-inf); } } int main() { scanf("%d",&n); rep(i,1,n+1) scanf("%d%d%d",&h[i],&a[i],&b[i]); scanf("%d",&q); rep(i,1,q+1) scanf("%d%d",&ql[i],&qr[i]),ans[i]=-1; solve(); rep(i,1,n+1) h[i]=-h[i]; solve(); rep(i,1,q+1) printf("%lld\n",ans[i]); return 0; }

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

antennas.cpp: In function 'int main()':
antennas.cpp:101:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  101 |  scanf("%d",&n);
      |  ~~~~~^~~~~~~~~
antennas.cpp:102:20: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  102 |  rep(i,1,n+1) scanf("%d%d%d",&h[i],&a[i],&b[i]);
      |               ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
antennas.cpp:103:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  103 |  scanf("%d",&q);
      |  ~~~~~^~~~~~~~~
antennas.cpp:104:20: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  104 |  rep(i,1,q+1) scanf("%d%d",&ql[i],&qr[i]),ans[i]=-1;
      |               ~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...