Submission #1035442

#TimeUsernameProblemLanguageResultExecution timeMemory
1035442imarnTriple Jump (JOI19_jumps)C++14
100 / 100
652 ms67764 KiB
#include<bits/stdc++.h> #define ll long long #define pb push_back #define pii pair<int,int> #define f first #define s second #define all(x) x.begin(),x.end() #define ub(a,b) upper_bound(a.begin(),a.end(),b)-a.begin(); #define lb(a,b) lower_bound(a.begin(),a.end(),b)-a.begin(); #define vi vector<int> #define vll vector<ll> #define pll pair<ll,ll> #define sz(x) x.size() using namespace std; const int mxn=5e5+5; int a[mxn]{0}; struct node{ int mx1,mx2,mx; node operator+(node b){ return {max(mx1,b.mx1),max(mx2,b.mx2),max({mx,b.mx,mx2+b.mx1})}; } }t[4*mxn]; void build(int i,int l,int r){ if(l==r)return void(t[i]={a[l],0,a[l]}); int m=(l+r)>>1;build(2*i,l,m);build(2*i+1,m+1,r); t[i]=t[2*i]+t[2*i+1]; } void update(int i,int l,int r,int idx,int v){ if(r<idx||l>idx)return; if(l==r){ t[i].mx2=max(t[i].mx2,v); t[i].mx=t[i].mx1+t[i].mx2; return; }int m=(l+r)>>1; update(2*i,l,m,idx,v);update(2*i+1,m+1,r,idx,v); t[i]=t[2*i]+t[2*i+1]; } node query(int i,int l,int r,int tl,int tr){ if(r<tl||l>tr)return {0,0,0}; if(r<=tr&&l>=tl)return t[i]; int m=(l+r)>>1; return query(2*i,l,m,tl,tr)+query(2*i+1,m+1,r,tl,tr); } int main(){ ios_base::sync_with_stdio(0);cin.tie(0); int n;cin>>n;for(int i=1;i<=n;i++)cin>>a[i]; stack<int>st;vector<pii>gd; for(int i=1;i<=n;i++){ while(!st.empty()&&a[st.top()]<=a[i])gd.pb({st.top(),i}),st.pop(); if(!st.empty())gd.pb({st.top(),i});st.push(i); }sort(gd.rbegin(),gd.rend()); vector<pii>qr[n+1];int q;cin>>q;int ans[q+1]; for(int i=1;i<=q;i++){ int l,r;cin>>l>>r; qr[l].pb({r,i}); }int idx=0;build(1,1,n); for(int l=n;l>=1;l--){ while(idx<gd.size()&&gd[idx].f>=l){ if(2*gd[idx].s-gd[idx].f>n){idx++;continue;} update(1,1,n,2*gd[idx].s-gd[idx].f,a[gd[idx].f]+a[gd[idx].s]); idx++; } for(auto it : qr[l]){ ans[it.s]=query(1,1,n,l,it.f).mx; } }for(int i=1;i<=q;i++)cout<<ans[i]<<'\n'; }

Compilation message (stderr)

jumps.cpp: In function 'int main()':
jumps.cpp:50:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   50 |         if(!st.empty())gd.pb({st.top(),i});st.push(i);
      |         ^~
jumps.cpp:50:44: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   50 |         if(!st.empty())gd.pb({st.top(),i});st.push(i);
      |                                            ^~
jumps.cpp:58:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |         while(idx<gd.size()&&gd[idx].f>=l){
      |               ~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...