結果

問題 No.865 24時間降水量
ユーザー TAISA_TAISA_
提出日時 2019-08-16 21:55:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 474 ms / 2,000 ms
コード長 3,241 bytes
コンパイル時間 1,520 ms
コンパイル使用メモリ 172,524 KB
実行使用メモリ 6,916 KB
最終ジャッジ日時 2023-10-23 22:58:24
合計ジャッジ時間 4,289 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 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 3 ms
4,348 KB
testcase_06 AC 3 ms
4,348 KB
testcase_07 AC 4 ms
4,348 KB
testcase_08 AC 4 ms
4,348 KB
testcase_09 AC 4 ms
4,348 KB
testcase_10 AC 20 ms
4,348 KB
testcase_11 AC 20 ms
4,348 KB
testcase_12 AC 20 ms
4,348 KB
testcase_13 AC 20 ms
4,348 KB
testcase_14 AC 21 ms
4,348 KB
testcase_15 AC 474 ms
6,916 KB
testcase_16 AC 474 ms
6,916 KB
testcase_17 AC 473 ms
6,916 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>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T> bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> ostream &operator<<(ostream &os, vector<T> v) {
    for (int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
    for (auto &e : t) {
        fill_v(e, v);
    }
};

template <class U> struct RangeMax {
    using T = U;
    static T op(const T &a, const T &b) { return max(a, b); }
    static constexpr T id() { return -INF; }
};
template <class Monoid> struct Segtree {
    using T = typename Monoid::T;
    int n;
    vector<T> dat;
    Segtree(int n_) {
        n = 1;
        while (n < n_)
            n <<= 1;
        dat.resize(2 * n, Monoid::id());
    }
    T get(int k) {
        assert(k < n);
        return dat[k + n];
    }
    void set(int k, const T &x) {
        assert(k < n);
        k += n;
        dat[k] = x;
        for (k >>= 1; k > 0; k >>= 1) {
            dat[k] = Monoid::op(dat[k << 1], dat[k << 1 | 1]);
        }
    }
    void add(int k, const T &x) {
        assert(k < n);
        k += n;
        dat[k] += x;
        for (k >>= 1; k > 0; k >>= 1) {
            dat[k] = Monoid::op(dat[k << 1], dat[k << 1 | 1]);
        }
    }
    T query(int a, int b) { //[a,b]->[a,b)
        if (a < 0)
            a = 0;
        if (a > b)
            return Monoid::id();
        if (b > n)
            b = n;
        T vl = Monoid::id(), vr = Monoid::id();
        int l = a + n, r = b + n + 1;
        for (; l < r; l >>= 1, r >>= 1) {
            if (l & 1)
                vl = Monoid::op(vl, dat[l++]);
            if (r & 1)
                vr = Monoid::op(dat[--r], vr);
        }
        return Monoid::op(vl, vr);
    }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n + 1), sum(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        sum[i] = sum[i - 1] + a[i];
    }
    Segtree<RangeMax<int>> seg(n + 10);
    for (int i = 24; i <= n; i++) {
        seg.set(i, sum[i] - sum[i - 24]);
    }
    int q;
    cin >> q;
    while (q--) {
        int t, v;
        cin >> t >> v;
        int to = v - a[t];
        a[t] = v;
        for (int i = max(t, 24); i < min(n + 1, t + 24); i++) {
            seg.add(i, to);
        }
        cout << seg.query(0, n + 1) << endl;
    }
}
0