4977 | 2023-04-08 12:03:05 | zsombor | Mágikus intervallum | cpp17 | Wrong answer 15/100 | 192ms | 12184 KiB |
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
int n, ansl, dif = -1;
vector <ll> a(15e4 + 2, 0);
vector <ll> p(15e4 + 2, 0);
vector <ll> v(15e4 + 2, 0);
ll sum(int l, int r) {
return p[r] - p[l - 1];
}
void solve(int l, int r) {
if (r < l) return;
int m = (l + r) / 2, L, R, M;
ll mx;
v[l] = sum(l, m - 1);
for (int i = l + 1; i <= m; i++) v[i] = min(v[i - 1], sum(i, m - 1));
v[m + 1] = -1e15;
mx = -1e15;
for (int i = m; i <= r; i++) {
mx = max(mx, a[i]);
L = l - 1; R = m + 1;
while (R - L > 1) {
M = (L + R) / 2;
(v[M] + sum(m, i) <= 2 * mx ? R = M : L = M);
}
if (R == m + 1) continue;
if (i - R > dif) { dif = i - R; ansl = R; }
}
v[r] = sum(m + 1, r);
for (int i = r - 1; i >= m; i--) v[i] = min(v[i + 1], sum(m + 1, r));
v[m - 1] = -1e15;
mx = -1e15;
for (int i = m; i >= l; i--) {
mx = max(mx, a[i]);
L = m - 1; R = r + 1;
while (R - L > 1) {
M = (L + R) / 2;
(v[M] + sum(i, m) <= 2 * mx ? L = M : R = M);
}
if (L == m - 1) continue;
if (L - i > dif) { dif = L - i; ansl = i; }
}
solve(l, m - 1);
solve(m + 1, r);
}
int main()
{
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
p[i] = p[i - 1] + a[i];
}
solve(1, n);
cout << ansl << " " << ansl + dif;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 4ms | 8948 KiB | ||||
2 | Accepted | 152ms | 9136 KiB | ||||
subtask2 | 0/5 | ||||||
3 | Accepted | 4ms | 9220 KiB | ||||
4 | Wrong answer | 4ms | 9448 KiB | ||||
5 | Wrong answer | 4ms | 9660 KiB | ||||
6 | Wrong answer | 4ms | 9956 KiB | ||||
7 | Accepted | 6ms | 10248 KiB | ||||
8 | Wrong answer | 4ms | 10124 KiB | ||||
subtask3 | 0/10 | ||||||
9 | Wrong answer | 6ms | 10336 KiB | ||||
10 | Wrong answer | 4ms | 10592 KiB | ||||
11 | Accepted | 4ms | 10468 KiB | ||||
12 | Accepted | 4ms | 10464 KiB | ||||
13 | Accepted | 4ms | 10468 KiB | ||||
14 | Wrong answer | 4ms | 10468 KiB | ||||
subtask4 | 0/10 | ||||||
15 | Accepted | 4ms | 10720 KiB | ||||
16 | Accepted | 4ms | 10936 KiB | ||||
17 | Wrong answer | 4ms | 10888 KiB | ||||
18 | Wrong answer | 14ms | 10892 KiB | ||||
19 | Wrong answer | 178ms | 11144 KiB | ||||
20 | Accepted | 146ms | 11360 KiB | ||||
21 | Wrong answer | 148ms | 11572 KiB | ||||
subtask5 | 15/15 | ||||||
22 | Accepted | 4ms | 11528 KiB | ||||
23 | Accepted | 141ms | 11784 KiB | ||||
24 | Accepted | 159ms | 11816 KiB | ||||
subtask6 | 0/60 | ||||||
25 | Accepted | 164ms | 11772 KiB | ||||
26 | Accepted | 180ms | 11744 KiB | ||||
27 | Accepted | 180ms | 11744 KiB | ||||
28 | Accepted | 172ms | 11788 KiB | ||||
29 | Accepted | 167ms | 11780 KiB | ||||
30 | Accepted | 168ms | 11784 KiB | ||||
31 | Accepted | 192ms | 11936 KiB | ||||
32 | Accepted | 192ms | 11996 KiB | ||||
33 | Accepted | 150ms | 11840 KiB | ||||
34 | Accepted | 149ms | 11984 KiB | ||||
35 | Wrong answer | 149ms | 12184 KiB | ||||
36 | Wrong answer | 177ms | 11980 KiB | ||||
37 | Accepted | 142ms | 11980 KiB | ||||
38 | Wrong answer | 146ms | 11872 KiB | ||||
39 | Wrong answer | 4ms | 11872 KiB |