#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int q;
cin >> q;
while (q--) {
int x, y, l, r;
cin >> x >> y >> l >> r;
--x; --r;
a[x] = y;
vector<long long> pref(n);
for (int i = 0; i < n; i++) {
pref[i] = (i == 0 ? 0LL : pref[i - 1]) + a[i];
}
auto Get = [&](int l, int r) {
return pref[r] - (l == 0 ? 0LL : pref[l - 1]);
};
auto Solve = [&](int i) {
int res = 1 + (i > l ? 1 : 0);
while (i < r) {
int nxt = -1;
for (int j = i + 2; j <= r; j++) {
if (a[j] < Get(i + 1, j - 1) && a[i] < Get(i + 1, j - 1) && (j == r || a[j] < Get(j + 1, r))) {
nxt = j;
break;
}
}
if (nxt != -1) {
i = nxt;
res += 2;
} else {
break;
}
}
if (i != r) {
assert(a[i] < Get(i + 1, r));
res += 1;
}
return res;
};
int ans = 1;
if (l == r || a[l] < Get(l + 1, r)) {
ans = max(ans, Solve(l));
}
for (int i = l + 1; i <= r; i++) {
if (Get(l, i - 1) > a[i] && (i == r || a[i] < Get(i + 1, r))) {
ans = max(ans, Solve(i));
}
}
cout << ans << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Execution timed out |
4080 ms |
5512 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Execution timed out |
4046 ms |
5404 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |