# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
382441 | BartolM | Bigger segments (IZhO19_segments) | C++17 | 121 ms | 18952 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;
#define X first
#define Y second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <int, pii> pip;
typedef pair <pii, int> ppi;
typedef pair <ll, ll> pll;
const int INF=0x3f3f3f3f;
const ll MAX=(ll)INF*INF;
const int N=5e5+5;
int n;
ll pref[N], p[N], dp[N];
int lef[N];
void solve() {
pref[n+1]=MAX;
lef[0]=0; dp[0]=0;
for (int i=1; i<=n; ++i) {
lef[i]=max(lef[i], lef[i-1]);
dp[i]=dp[lef[i]]+1;
ll br=2*pref[i]-pref[lef[i]];
int nx=lower_bound(pref, pref+n+2, br)-pref;
lef[nx]=i;
}
printf("%lld\n", dp[n]);
}
void load() {
scanf("%d", &n);
for (int i=1; i<=n; ++i) {
scanf("%lld", &p[i]);
pref[i]=pref[i-1]+p[i];
}
}
int main() {
load();
solve();
return 0;
}
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... |