Submission #201379

#TimeUsernameProblemLanguageResultExecution timeMemory
201379guangxuanBigger segments (IZhO19_segments)C++14
73 / 100
692 ms262144 KiB
#include <bits/stdc++.h> using namespace std; int a[500009]; long long rs[500009]; struct node{ pair<int,int> v; node *l,*r; node():v({-1,0}),l(NULL),r(NULL){} void up(long long s,long long e,long long x,pair<int,int> uv){ long long m = (s+e)/2; if(s==e){ v = max(v,uv);return; } if(x>m){ if(r==NULL)r = new node(); r->up(m+1,e,x,uv); } else{ if(l==NULL)l = new node(); l->up(s,m,x,uv); } v = {-1,0}; if(r)v = max(v,r->v); if(l)v = max(v,l->v); } pair<int,int> qu(long long s,long long e,long long x,long long y){ long long m = (s+e)/2; if(s==x&&e==y)return v; if(x>m){ if(r)return r->qu(m+1,e,x,y); else return {-1,0}; } if(y<=m){ if(l)return l->qu(s,m,x,y); else return {-1,0}; } pair<int,int> qv = {-1,0}; if(r)qv = max(qv,r->qu(m+1,e,m+1,y)); if(l)qv = max(qv,l->qu(s,m,x,m)); return qv; } }*root; int main(){ int n; scanf("%d",&n); for(int i=0;i<n;i++){ scanf("%d",&a[i]); rs[i+1]=rs[i]+a[i]; } root = new node(); root->up(0,(long long)5e14,0,{0,0}); pair<int,long long> dp; for(int i=1;i<=n;i++){ pair<int,int> res = root->qu(0,(long long)5e14,0,rs[i]); dp = {res.first,rs[res.second] - rs[i]}; dp.first++; root->up(0,(long long)5e14,rs[i] - dp.second,{dp.first,i}); //cout << dp[i].first << ' ' << dp[i].second << '\n'; // cout << res.first << ' ' << res.second.first << ' ' << res.second.second << '\n'; } printf("%d", dp.first); }

Compilation message (stderr)

segments.cpp: In function 'int main()':
segments.cpp:49:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
  ~~~~~^~~~~~~~~
segments.cpp:51:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&a[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...