はまやんはまやんはまやん

hamayanhamayan's blog

24時間降水量 [yukicoder 865]

https://yukicoder.me/problems/no/865

解説

https://yukicoder.me/submissions/370121

クエリ計算を行っていくが、降水量が減ることはないため、
変化する分を計算すればいい。
ある個所が変更されたときに影響を受けるのは24区間である。
なので、その24区間の総和の最大値をつかって、答えを更新すればいい。

int N, A[201010], Q;
BIT<int> bit(201010);
//---------------------------------------------------------------------------------------------------
int ans = -1;
void update(int L) {
    if (0 <= L and L + 24 <= N) {
        int tot = bit.get(L, L + 24);
        chmax(ans, tot);
    }
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;
    rep(i, 0, N) cin >> A[i];
    rep(i, 0, N) bit.update(i, A[i]);

    rep(L, 0, N) update(L);

    cin >> Q;
    rep(q, 0, Q) {
        int T, V; cin >> T >> V;
        T--;
        bit.update(T, V);
        rep(L, T - 23, T + 1) update(L);
        printf("%d\n", ans);
    }
}