# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
959406 | Pring | Bigger segments (IZhO19_segments) | C++17 | 0 ms | 0 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.
#pragma GCC optimize("O3","unroll-loops")
#pragma GCC target("avx2","popcnt","sse4","abm")
#include <bits/stdc++.h>
using namespace std;
#ifdef MIKU
string dbmc = "\033[1;38;2;57;197;187m", dbrs = "\033[0m";
#define debug(x...) cout << dbmc << "[" << #x << "]: ", dout(x)
void dout() { cout << dbrs << endl; }
template <typename T, typename ...U>
void dout(T t, U ...u) { cout << t << (sizeof...(u) ? ", " : ""); dout(u...); }
#else
#define debug(...) 39
#endif
// #define int long long
#define fs first
#define sc second
#define mp make_pair
#define FOR(i, j, k) for (int i = j, Z = k; i < Z; i++)
using ll = long long;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
const int MXN = 500005;
int n, a[MXN];
int dp[MXN];
ll pre[MXN];
vector<pli> dq;
int ptr;
inline int R(){
int ans = 0; char c = readchar(); bool minus = false;
while((c < '0' or c > '9') and c != '-' and c != EOF) c = readchar();
if(c == '-') minus = true, c = readchar();
while(c >= '0' and c <= '9') ans = ans * 10 + (c ^ '0'), c = readchar();
return minus ? -ans : ans;
}
void DP(int id) {
while (ptr < dq.size() && dq[ptr].fs <= pre[id]) ptr++;
int l = dq[ptr - 1].sc;
dp[id] = dp[l] + 1;
pli now = mp(2 * pre[id] - pre[l], id);
debug(now.fs, now.sc);
while (dq.size() && dq.back().fs >= now.fs) dq.pop_back();
dq.push_back(now);
}
void miku() {
// cin >> n;
n = R();
FOR(i, 1, n + 1) a[i] = R();
FOR(i, 1, n + 1) pre[i] = pre[i - 1] + a[i];
dq.push_back(mp(0LL, 0));
FOR(i, 1, n + 1) DP(i);
cout << dp[n] << '\n';
}
int32_t main() {
cin.tie(0) -> sync_with_stdio(false);
cin.exceptions(cin.failbit);
miku();
return 0;
}