This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//Make CSP great again
//Vengeance
#include <bits/stdc++.h>
#define TASK "TESTCODE"
#define Log2(x) 31 - __builtin_clz(x)
using namespace std;
const int N = 5e5;
long long pre, cur, a[N + 1];
int n, res;
set<tuple<long long, int, int> > Set;
void read()
{
cin >> n;
Set.insert(make_tuple(0, 0, 0));
for (int i = 1; i <= n; ++ i)
{
cin >> a[i];
a[i] += a[i - 1];
auto it = Set.upper_bound(make_tuple(a[i], N + 1, N + 1));
--it;
res = get<1> (*it) + 1;
cur = a[i] * 2 - a[get<2> (*it)];
while(true)
{
it = Set.lower_bound(make_tuple(cur, N + 1, N + 1));
if (it == Set.end() || get<2> (*it) > res)
{
break;
}
Set.erase(it);
}
Set.insert(make_tuple(cur, res, i));
}
}
void solve()
{
cout << res;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
if (fopen(TASK".INP", "r"))
{
freopen(TASK".INP", "r", stdin);
//freopen(TASK".OUT", "w", stdout);
}
int t = 1;
bool typetest = false;
if (typetest)
{
cin >> t;
}
for (int __ = 1; __ <= t; ++ __)
{
//cout << "Case " << __ << ": ";
read();
solve();
}
}
Compilation message (stderr)
segments.cpp: In function 'int main()':
segments.cpp:45:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
45 | freopen(TASK".INP", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |