結果

問題 No.1000 Point Add and Array Add
ユーザー rokahikou1rokahikou1
提出日時 2020-10-30 00:43:25
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 236 ms / 2,000 ms
コード長 2,812 bytes
コンパイル時間 1,766 ms
コンパイル使用メモリ 173,956 KB
実行使用メモリ 12,536 KB
最終ジャッジ日時 2023-09-29 04:14:49
合計ジャッジ時間 7,207 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 4 ms
4,380 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 173 ms
9,888 KB
testcase_17 AC 143 ms
8,788 KB
testcase_18 AC 235 ms
12,356 KB
testcase_19 AC 234 ms
12,324 KB
testcase_20 AC 222 ms
12,416 KB
testcase_21 AC 235 ms
12,392 KB
testcase_22 AC 229 ms
12,528 KB
testcase_23 AC 236 ms
12,536 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:97:14: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   97 |     for(auto [q, p] : query) {
      |              ^
main.cpp:98:14: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   98 |         auto [x, y] = p;
      |              ^

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
template <class T> vector<T> make_vec(size_t a, T val) {
    return vector<T>(a, val);
}
template <class... Ts> auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec(ts...))>(a, make_vec(ts...));
}
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
template <typename T> struct edge {
    int to;
    T cost;
    edge(int t, T c) : to(t), cost(c) {}
};
template <typename T> using WGraph = vector<vector<edge<T>>>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

// 参考:https://qiita.com/drken/items/1b7e6e459c24a83bb7fd
// 1-indexed BIT
// add:log(N),sum:log(N),get_k-th:log(N)
// https://codeforces.com/contest/1354/problem/D
struct BIT {
    vector<ll> dat;

    BIT(int n) {
        dat.resize(n + 1);
        for(int i = 0; i < (int)dat.size(); i++)
            dat[i] = 0;
    }

    // a is 1-indexed
    void add(int a, ll x) {
        for(int i = a; i < (int)dat.size(); i += i & -i)
            dat[i] = dat[i] + x;
    }

    // [1,a], a is 1-indexed
    ll sum(int a) {
        ll res = 0;
        for(int i = a; i > 0; i -= i & -i) {
            res = res + dat[i];
        }
        return res;
    }

    // [a,b), a and b are 1-indexed
    ll sum(int a, int b) { return sum(b - 1) - sum(a - 1); }

    // k-th number (k is 1-indexed)
    // lower_bound
    int get(ll k) {
        if(k <= 0)
            return 0;
        int res = 0;
        int N = 1;
        while(N < (int)dat.size())
            N *= 2;
        for(int i = N / 2; i > 0; i /= 2) {
            if(res + i < (int)dat.size() && dat[res + i] < k) {
                k = k - dat[res + i];
                res = res + i;
            }
        }
        return res + 1;
    }
};

int main() {
    int N, Q;
    cin >> N >> Q;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    vector<pair<int, pll>> query(Q);
    BIT bit(N + 1);
    rep(i, Q) {
        char c;
        ll x, y;
        cin >> c >> x >> y;
        if(c == 'A') {
            query[i] = {0, {x, y}};
        } else {
            query[i] = {1, {x, y}};
        }
    }
    reverse(All(query));
    vector<ll> res(N);
    for(auto [q, p] : query) {
        auto [x, y] = p;
        if(q == 0) {
            res[x - 1] += bit.sum(x) * y;
        } else {
            bit.add(x, 1);
            bit.add(y + 1, -1);
        }
    }
    for(int i = 0; i < N; i++) {
        res[i] += A[i] * bit.sum(i + 1);
    }
    for(int i = 0; i < N; i++) {
        cout << res[i] << (i == N - 1 ? "\n" : " ");
    }
}
0