Submission #1109478

#TimeUsernameProblemLanguageResultExecution timeMemory
1109478imarnBigger segments (IZhO19_segments)C++14
100 / 100
159 ms16664 KiB
#include<bits/stdc++.h> #define ll long long #define pii pair<int,int> #define pll pair<ll,ll> #define plx pair<ll,int> #define f first #define s second #define pb push_back #define all(x) x.begin(),x.end() #define vi vector<int> #define vvi vector<vi> #define pp pair<ll,int> #define ub(x,i) upper_bound(all(x),i)-x.begin() using namespace std; const int mxn=5e5+5; ll t[4*mxn]{0}; void build(int i,int l,int r){ if(l==r)return void(t[i]=1e16); int m=(l+r)>>1; build(2*i,l,m);build(2*i+1,m+1,r); t[i]=min(t[2*i],t[2*i+1]); } void upd(int i,int l,int r,int idx,ll v){ if(r<idx||l>idx)return; if(l==r)return void(t[i]=v); int m=(l+r)>>1; upd(2*i,l,m,idx,v);upd(2*i+1,m+1,r,idx,v); t[i]=min(t[2*i],t[2*i+1]); } int qr(int i,int l,int r,ll tt){ if(l==r)return l;int m=(l+r)>>1; if(t[2*i+1]<=tt)return qr(2*i+1,m+1,r,tt); return qr(2*i,l,m,tt); } int main(){ ios_base::sync_with_stdio(0);cin.tie(0); int n;cin>>n;build(1,0,n); ll a[n+1]={0};for(int i=1;i<=n;i++)cin>>a[i],a[i]+=a[i-1]; ll dp[n+1]={0};dp[0]=0;upd(1,0,n,0,0); for(int i=1;i<=n;i++){ int r=qr(1,0,n,a[i]); dp[i] = dp[r]+1; upd(1,0,n,i,2*a[i]-a[r]); }cout<<dp[n]; }

Compilation message (stderr)

segments.cpp: In function 'int qr(int, int, int, long long int)':
segments.cpp:31:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   31 |     if(l==r)return l;int m=(l+r)>>1;
      |     ^~
segments.cpp:31:22: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   31 |     if(l==r)return l;int m=(l+r)>>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...
#Verdict Execution timeMemoryGrader output
Fetching results...