이 제출은 이전 버전의 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
int arr[250005], dp[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];
int q;
cin >> q;
for (int i = 1; i <= q; ++i) {
int x, y, a, b;
cin >> x >> y >> a >> b;
arr[x] = y;
int ans = 1;
auto val = [&](int p) {
if (p <= a || p > b) return 0;
return arr[p];
};
dp[a] = 0;
for (int j = a + 1; j <= b; ++j) {
dp[j] = dp[j - 1];
ll cur = 0;
for (int k = j; k > a && k > j - 70; --k) {
cur += arr[k];
if (cur > max(val(k - 1), val(j + 1))) {
if (k == a + 1) dp[j] = max(dp[j], 1);
else if (k == a + 2) dp[j] = max(dp[j], 2);
else dp[j] = max(dp[j], dp[k - 2] + 2);
if (j == b) ans = max(ans, dp[j]);
else ans = max(ans, dp[j] + 1);
break;
}
}
}
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... |