#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define X first
#define Y second
#define SZ(a) ((int)a.size())
#define ALL(v) v.begin(), v.end()
#define pb push_back
const int L = 70;
int arr[250005], lft[250005], tmp[250005];
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int n;
cin >> n;
for (int i = 1; i <= n; ++i)
cin >> arr[i];
auto update = [&](int i) {
lft[i] = 0;
ll cur = 0;
for (int j = i; j > 0 && j > i - L; --j) {
cur += arr[j];
if (cur > max(arr[i - 1], arr[i + 1])) {
lft[i] = j;
break;
}
}
};
for (int i = 1; i <= n; ++i)
update(i);
int q;
cin >> q;
for (int i = 1; i <= q; ++i) {
int x, y, a, b;
cin >> x >> y >> a >> b;
arr[x] = y;
for (int j = max(1, x - 1); j <= n && j <= x + L; ++j)
update(j);
int ans = 1;
ll cur = 0;
for (int j = a + 1; j < b && j <= a + L; ++j) {
tmp[j] = lft[j];
if (cur > arr[j + 1]) lft[j] = max(lft[j], a + 1);
cur += arr[j];
}
tmp[b] = lft[b], lft[b] = 0, cur = 0;
for (int j = b; j > a && j > b - L; --j) {
cur += arr[j];
if (j == a + 1 || cur > arr[j - 1]) {
lft[b] = j;
break;
}
}
pii one = pll(a - 1, -1);
pii two = pll(a, 0);
for (int j = a + 1; j <= b; ++j) {
if (lft[j] - 1 > one.X) one.X = j, one.Y += 2;
if (lft[j] - 1 > two.X) two.X = j, two.Y += 2;
if (j == b) ans = max({ans, one.Y, two.Y});
else ans = max({ans, one.Y + 1, two.Y + 1});
}
for (int j = a + 1; j <= b && j <= a + L; ++j)
lft[j] = tmp[j];
lft[b] = tmp[b];
cout << ans << "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
72 ms |
2580 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Incorrect |
79 ms |
3200 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |