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")
#pragma GCC target ("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")*/
#include <bits/stdc++.h>
#pragma GCC optimize ("unroll-loops,Ofast,O3")
#pragma GCC target("avx,avx2,fma")
//#define file(data) freopen(data".in", "r", stdin); freopen(data".out", "w", stdout);
#define pb push_back
//#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(data) data.begin() , data.end()
#define endl '\n'
//freopen("nenokku_easy.in", "r", stdin);
//freopen("nenokku_easy.out", "w", stdout);
#define int long long
#define pii pair < int, int >
#define pll pair < long long, long long >
using namespace std;
typedef long long ll;
const int N = 1e6 + 5;
const int M = 3005;
const int mod = 1e9 + 7;
int n, a[N], pref[N];
pair < int, int > dp[N];
main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//file("pieaters");
cin >> n;
for(int i = 1; i <= n; i++) {
cin >> a[i];
pref[i] = pref[i - 1] + a[i];
}
for(int i = 1; i <= n; i++) {
dp[i].second = max(dp[i - 1].second, dp[i].second);
dp[i].first = dp[dp[i].second].first + 1;
int l = i + 1, r = n;
while(l < r) {
int md = (l + r) / 2;
if(pref[md] >= 2 * pref[i] - pref[dp[i].second]) {
r = md;
} else {
l = md + 1;
}
}
if(pref[l] >= 2 * pref[i] - pref[dp[i].second]) dp[l].second = max(dp[l].second, i);
}
cout << dp[n].first;
}
Compilation message (stderr)
segments.cpp:30:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
30 | main() {
| ^~~~
# | 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... |