이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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[j - 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";
}
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |