結果

問題 No.865 24時間降水量
ユーザー koi_kotyakoi_kotya
提出日時 2019-08-17 00:08:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 632 ms / 2,000 ms
コード長 2,275 bytes
コンパイル時間 1,923 ms
コンパイル使用メモリ 178,376 KB
実行使用メモリ 13,704 KB
最終ジャッジ日時 2023-10-24 12:31:11
合計ジャッジ時間 4,976 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 5 ms
4,348 KB
testcase_06 AC 4 ms
4,348 KB
testcase_07 AC 4 ms
4,348 KB
testcase_08 AC 5 ms
4,348 KB
testcase_09 AC 5 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 24 ms
4,348 KB
testcase_14 AC 25 ms
4,348 KB
testcase_15 AC 632 ms
13,704 KB
testcase_16 AC 623 ms
13,704 KB
testcase_17 AC 625 ms
13,704 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 #

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> P;

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

struct LazySegmentTree {
private:
    int n;
    vector<ll> node,lazy;
public:
    LazySegmentTree(vector<ll> v) {
        int sz = v.size();
        n = 1;
        while (n < sz) n *= 2;
        node.resize(2*n-1);
        lazy.resize(2*n-1,0);
        for (int i = 0;i < sz;++i) node[i+n-1] = v[i];
        for (int i = n-2;i >= 0;--i) node[i] = min(node[i*2+1],node[i*2+2]);
    }

    void eval(int k,int l,int r) {
        if (lazy[k] != 0) {
            node[k] += lazy[k]/(r-l);
            if (r-l > 1) {
                lazy[2*k+1] += lazy[k]/2;
                lazy[2*k+2] += lazy[k]/2;
            }
            lazy[k] = 0;
        }
    }

    void add(int a,int b,ll x,int k = 0,int l = 0,int r = -1) {
        if (r < 0) r = n;
        eval(k,l,r);
        if (b <= l || r <= a) return;
        if (a <= l && r <= b) {
            lazy[k] += (r-l)*x;
            eval(k,l,r);
        } else {
            add(a,b,x,2*k+1,l,(l+r)/2);
            add(a,b,x,2*k+2,(l+r)/2,r);
            node[k] = max(node[2*k+1],node[2*k+2]);
        }
    }

    ll getmax(int a,int b,int k = 0,int l = 0,int r = -1) {
        if (r < 0) r = n;
        if (b <= l || r <= a) return -INT64_MAX;
        eval(k,l,r);
        if (a <= l && r <= b) return node[k];
        ll vl = getmax(a,b,k*2+1,l,(l+r)/2);
        ll vr = getmax(a,b,2*k+2,(l+r)/2,r);
        return max(vl,vr);
    }
};

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    LazySegmentTree seg(vector<ll>(n+10,0));
    for (int i = 0;i < n;++i) cin >> a[i];
    for (int i = 0;i < n;++i) {
        seg.add(max(0,i-23),i+1,a[i]);
    }
    int q;
    cin >> q;
    for (int i = 0;i < q;++i) {
        int t,v;
        cin >> t >> v;
        seg.add(max(0,t-24),t,v-a[t-1]);
        cout << seg.getmax(0,n) << "\n";
        a[t-1] = v;
    }
    return 0;
}
0