結果

問題 No.865 24時間降水量
ユーザー mencottonmencotton
提出日時 2019-08-16 21:52:28
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 505 ms / 2,000 ms
コード長 1,162 bytes
コンパイル時間 746 ms
コンパイル使用メモリ 73,004 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-23 22:40:59
合計ジャッジ時間 3,492 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 4 ms
4,348 KB
testcase_07 AC 4 ms
4,348 KB
testcase_08 AC 4 ms
4,348 KB
testcase_09 AC 5 ms
4,348 KB
testcase_10 AC 23 ms
4,348 KB
testcase_11 AC 22 ms
4,348 KB
testcase_12 AC 23 ms
4,348 KB
testcase_13 AC 22 ms
4,348 KB
testcase_14 AC 22 ms
4,348 KB
testcase_15 AC 505 ms
4,348 KB
testcase_16 AC 501 ms
4,348 KB
testcase_17 AC 503 ms
4,348 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 <iostream>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;

template<typename T>
struct BinaryIndexedTree {
    vector<T> data;

    BinaryIndexedTree(int sz) {
        data.assign(++sz, 0);
    }

    T sum(int k) {
        T ret = 0;
        for (++k; k > 0; k -= k & -k) ret += data[k];
        return (ret);
    }

    void add(int k, T x) {
        for (++k; k < data.size(); k += k & -k) data[k] += x;
    }
};

int main() {
    int n;
    cin >> n;
    BinaryIndexedTree<int> bit(n + 1);
    for (int i = 0; i < n; i++) {
        int tmp;
        cin >> tmp;
        bit.add(i + 1, tmp);
    }
    int ret = 0;
    for (int i = 24; i <= n; i++)ret = max(ret, bit.sum(i) - bit.sum(i - 24));

    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int t, v;
        cin >> t >> v;
        int plus = v - (bit.sum(t) - bit.sum(t - 1));
        bit.add(t, plus);
        for (int finish = t; finish < t + 24 && finish <= n; finish++) {
            if (finish < 24)continue;
            ret = max(ret, bit.sum(finish) - bit.sum(finish - 24));
        }

        cout << ret << endl;
    }
    return 0;
}
0