답안 #747502

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
747502 2023-05-24T08:34:23 Z baluteshih Mizuyokan 2 (JOI23_mizuyokan2) C++14
0 / 100
77 ms 5072 KB
#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]) lft[j] = max(lft[j], a + 1);
            cur += arr[j];
        }

        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];
        cout << ans << "\n";
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 0 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 0 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 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 Incorrect 77 ms 4776 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Incorrect 72 ms 5072 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 0 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -