# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
201337 | guangxuan | Bigger segments (IZhO19_segments) | C++14 | 1574 ms | 142052 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int a[500009];
long long rs[500009];
pair<int,long long> dp[500009];
unordered_map<long long,pair<int,long long> >fw;
pair<int,long long> query(long long x){
pair<int,long long> ans = {-1,-1};
for(x++;x;x-=x&(-x)){
if(fw.find(x)==fw.end())continue;
ans = max(ans,fw[x]);
}
return ans;
}
void up(long long x,pair<int,long long> v ){
for(x++;x<1e15;x+=x&(-x)){
if(fw.find(x)==fw.end())fw[x] = v;
else fw[x] = max(fw[x],v);
}
}
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];
}
up(0,{0,0});
for(int i=1;i<=n;i++){
pair<int,long long> res = query(rs[i]);
dp[i] = {res.first,res.second - rs[i]};
dp[i].first++;
up(rs[i] - dp[i].second,{dp[i].first,rs[i]});
//cout << dp[i].first << ' ' << dp[i].second << '\n';
// cout << res.first << ' ' << res.second.first << ' ' << res.second.second << '\n';
}
printf("%d", dp[n].first);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |