# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
344644 | Nurlykhan | Bigger segments (IZhO19_segments) | C++17 | 2 ms | 620 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>
#define ll long long
using namespace std;
const int N = (int)5e5 + 10;
const int mod = (int)1e9 + 7;
int n;
int a[N];
ll pref[N];
ll get_sum(int l, int r) {
return pref[r] - pref[l - 1];
}
pair<int, int> dp[N];
unordered_map<int, pair<int, int> > t;
pair<int, int> get(ll x) {
assert(x >= 0);
pair<int, int> ans = make_pair(0, 0);
while (x >= 0) {
if (t.count(x))
ans = max(ans, t[x]);
x &= x + 1;
x--;
}
return ans;
}
void upd(ll x, pair<int, int> y) {
assert(x >= 0);
while (x < (ll)1e15) {
t[x] = max(t[x], y);
x |= x + 1;
}
}
int main() {
// freopen("in.txt", "r", stdin);
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
pref[i] = pref[i - 1] + a[i];
}
for (int i = 1; i <= n; i++) {
dp[i] = make_pair(1, 1);
dp[i] = max(dp[i], get(pref[i]));
upd(2 * pref[i] - pref[dp[i].second - 1], make_pair(dp[i].first + 1, i + 1));
}
cout << dp[n].first;
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... |