Submission #259875

#TimeUsernameProblemLanguageResultExecution timeMemory
259875Osama_AlkhodairyBigger segments (IZhO19_segments)C++17
0 / 100
1 ms384 KiB
#include <bits/stdc++.h> using namespace std; #define finish(x) return cout << x << endl, 0 #define ll long long const int N = 500001; int n, sum[N]; vector <int> a; int get_sum(int l, int r){ if(r < l) return 0; return sum[r] - (l == 0 ? 0 : sum[l - 1]); } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; a.resize(n); for(auto &i : a) cin >> i; if(n == 1) finish(1); for(int i = 0 ; i < n ; i++){ if(i > 0) sum[i] = sum[i - 1]; sum[i] += a[i]; } vector <pair <int, int> > ans; ans.push_back(make_pair(0, 0)); ans.push_back(make_pair(1, 1)); for(int i = 2 ; i < n ; i++){ auto &g = ans[ans.size() - 2]; auto &h = ans[ans.size() - 1]; if(get_sum(g.first, g.second) > get_sum(h.first, h.second)){ ans.back().second++; } else{ while(get_sum(g.first, g.second + 1) <= get_sum(h.first + 1, h.second)){ g.second++; h.first++; } ans.push_back(make_pair(i, i)); } } auto &g = ans[ans.size() - 2]; auto &h = ans[ans.size() - 1]; if(get_sum(g.first, g.second) > get_sum(h.first, h.second)) ans.pop_back(); cout << ans.size() << endl; }
#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...