結果

問題 No.865 24時間降水量
ユーザー face4face4
提出日時 2019-08-16 21:47:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,270 ms / 2,000 ms
コード長 1,478 bytes
コンパイル時間 899 ms
コンパイル使用メモリ 74,596 KB
実行使用メモリ 7,024 KB
最終ジャッジ日時 2023-10-23 22:21:27
合計ジャッジ時間 5,995 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 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 7 ms
4,348 KB
testcase_06 AC 7 ms
4,348 KB
testcase_07 AC 6 ms
4,348 KB
testcase_08 AC 6 ms
4,348 KB
testcase_09 AC 6 ms
4,348 KB
testcase_10 AC 48 ms
4,348 KB
testcase_11 AC 48 ms
4,348 KB
testcase_12 AC 47 ms
4,348 KB
testcase_13 AC 47 ms
4,348 KB
testcase_14 AC 47 ms
4,348 KB
testcase_15 AC 1,270 ms
7,024 KB
testcase_16 AC 1,268 ms
7,024 KB
testcase_17 AC 1,267 ms
7,024 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
using namespace std;
const int INF = 1<<30;

struct STsum{
private:
    int n;
    vector<int> dat;
public:
    STsum(vector<int> ini){
        int siz = ini.size();
        n = 1;
        while(n < siz)   n *= 2;
        dat.resize(2*n-1, -INF);
        for(int i = 0; i < siz; i++)    dat[n - 1 + i] = ini[i];
        for(int i = n-2; i >= 0; i--)   dat[i] = dat[2*i+1]+dat[2*i+2];
    }

    void update(int x, int val){
        x += (n-1);
        dat[x] += val;
        while(x > 0){
            x = (x-1)/2;
            dat[x] = dat[2*x+1]+dat[2*x+2];
        }
    }
    
    // focus on k-th node, who controls [l, r)
    int query(int a, int b, int k = 0, int l = 0, int r = -1){
        if(r < 0)   r = n;
        if(r <= a || b <= l)    return 0;
        if(a <= l && r <= b)    return dat[k];

        int lx = query(a, b, 2*k+1, l, (l+r)/2);
        int rx = query(a, b, 2*k+2, (l+r)/2, r);
        return lx+rx;
    }
};

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++)  cin >> a[i];
    STsum seg(a);
    int ans = 0;
    for(int i = 0; i <= n-24; i++)   ans = max(ans, seg.query(i, i+24));
    int q;
    cin >> q;
    while(q-- > 0){
        int t, v;
        cin >> t >> v;
        t--;
        seg.update(t, v-a[t]);
        a[t] = v;
        for(int i = max(0, t-23); i <= min(n-24, t); i++)   ans = max(ans, seg.query(i, i+24));
        cout << ans << endl;
    }
    return 0;
}
0