結果

問題 No.865 24時間降水量
ユーザー parukiparuki
提出日時 2019-08-16 21:54:03
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 567 ms / 2,000 ms
コード長 2,368 bytes
コンパイル時間 1,699 ms
コンパイル使用メモリ 172,648 KB
実行使用メモリ 8,948 KB
最終ジャッジ日時 2023-10-23 22:49:31
合計ジャッジ時間 4,775 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 4 ms
4,348 KB
testcase_06 AC 5 ms
4,348 KB
testcase_07 AC 5 ms
4,348 KB
testcase_08 AC 5 ms
4,348 KB
testcase_09 AC 4 ms
4,348 KB
testcase_10 AC 25 ms
4,348 KB
testcase_11 AC 25 ms
4,348 KB
testcase_12 AC 25 ms
4,348 KB
testcase_13 AC 25 ms
4,348 KB
testcase_14 AC 26 ms
4,348 KB
testcase_15 AC 563 ms
8,948 KB
testcase_16 AC 560 ms
8,948 KB
testcase_17 AC 567 ms
8,948 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

template<class Val, class Cmp>
class DynamicRMQ {
    int n;
    Val init;
    vector<Val> dat;
    Cmp cmp;
    inline Val query(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l) return init;
        if (a <= l && r <= b) return dat[k];
        else {
            Val vl, vr;
            vl = query(a, b, k << 1, l, (l + r) >> 1);
            vr = query(a, b, (k << 1) | 1, (l + r) >> 1, r);
            return cmp(vl, vr) ? vl : vr;
        }
    }
public:
    DynamicRMQ() {}
    DynamicRMQ(int n_, Val init_) :n(1), init(init_) {
        for (; n<n_; n <<= 1);
        dat = vector<Val>(n << 1, init);
    }
    void update(int k, Val a) {
        k += n;
        dat[k] = a;
        while (k > 1) {
            k >>= 1;
            dat[k] = cmp(dat[k << 1], dat[(k << 1) | 1]) ? dat[k << 1] : dat[(k << 1) | 1];
        }
    }
    Val query(int a, int b) {
        return query(a, b, 1, 0, n);
    }
};

typedef DynamicRMQ<long long, less<long long> > RMinQ64;
typedef DynamicRMQ<long long, greater<long long> > RMaxQ64;
typedef DynamicRMQ<int, less<int> > RMinQ32;
typedef DynamicRMQ<int, greater<int> > RMaxQ32;

void solve() {
    int N;
    cin >> N;
    vll A(N);
    rep(i, N)cin >> A[i];

    RMaxQ64 rmq(N, 0);

    auto f = [&](int k) {
        ll val = 0;
        FOR(i, k, min(k + 24, N)) {
            val += A[i];
        }
        rmq.update(k, val);
    };
    rep(i, N) {
        f(i);
    }

    int Q;
    cin >> Q;
    rep(ITER, Q) {
        int T, V;
        cin >> T >> V;
        --T;
        A[T] = V;
        for (int i = max(0, T - 23); i <= T; ++i) {
            f(i);
        }
        cout << rmq.query(0, N) << endl;
    }
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}
0