제출 #747448

#제출 시각아이디문제언어결과실행 시간메모리
747448baluteshihMizuyokan 2 (JOI23_mizuyokan2)C++14
28 / 100
4083 ms1692 KiB
#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];

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];
        };

        pii one = pll(a - 1, -1);
        pii two = pll(a, 0);
        for (int j = a + 1; j <= b; ++j) {
            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 - 1 > one.X) one.X = j, one.Y += 2;
                    if (k - 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});
                    break;
                }
            }
        }
        cout << ans << "\n";
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...