Submission #384600

#TimeUsernameProblemLanguageResultExecution timeMemory
384600dorijanlendvajBigger segments (IZhO19_segments)C++14
100 / 100
274 ms26988 KiB
#include <bits/stdc++.h> #define x first #define y second #define pii pair<int,int> using namespace std; using ll=long long; #define pll pair<ll,ll> #define vi vector<int> #define vl vector<ll> #define pb push_back #define eb emplace_back #define all(a) begin(a),end(a) const int N=500010,MOD=1e9+7,M=1<<19; const char en='\n'; const ll LLINF=1ll<<60; int t,n,h[N]; ll pr[N]; pll seg[M*2+10]; void upd(int i,pll x) { seg[i+=M]=x; for (i/=2;i;i/=2) seg[i]=max(seg[i*2],seg[i*2+1]); } pll ge(int l,int r,int lo=0,int hi=M,int i=1) { if (lo>=l && hi<=r) return seg[i]; if (lo>=r || hi<=l) return {0,0}; int mid=(lo+hi)/2; return max(ge(l,r,lo,mid,i*2),ge(l,r,mid,hi,i*2+1)); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin>>n; for (int i=0;i<n;++i) { cin>>h[i]; pr[i+1]=pr[i]+h[i]; } for (int i=1;i<=n;++i) { pll re=ge(0,i); if (i==n) { cout<<re.x+1<<en; exit(0); } //cout<<re.x<<' '<<re.y<<en; ll su=pr[i]-re.y; int po=lower_bound(pr+1,pr+n+1,pr[i]+su)-pr-1; upd(po,{re.x+1,pr[i]}); } }
#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...