# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
344692 | Nurlykhan | Bigger segments (IZhO19_segments) | C++17 | 195 ms | 19540 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;
const ll inf = (ll) 1e16 + 10;
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];
pair<int, int> t[N];
int sz = 1;
vector<ll> ids;
int get_id(ll x) {
//cout << x << " -> id=" << lower_bound(ids.begin(), ids.end(), x) - ids.begin() - 1 << endl;;
return lower_bound(ids.begin(), ids.end(), x) - ids.begin() - 1;
}
pair<int, int> get(ll x) {
assert(x >= 0);
pair<int, int> ans = make_pair(0, 0);
while (x >= 0) {
ans = max(ans, t[x]);
x &= x + 1;
x--;
}
return ans;
}
void upd(ll x, pair<int, int> y) {
assert(x >= 0);
while (x <= ids.size()) {
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];
ids.push_back(pref[i]);
}
ids.push_back(-inf);
ids.push_back(inf);
sort(ids.begin(), ids.end());
//for (auto it : ids) cout << it << ' '; cout << endl;
for (int i = 1; i <= n; i++) {
dp[i] = make_pair(1, 1);
dp[i] = max(dp[i], get(get_id(pref[i])));
upd(get_id(2 * pref[i] - pref[dp[i].second - 1]), make_pair(dp[i].first + 1, i + 1));
}
//cout << "\n";
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... |