結果

問題 No.1000 Point Add and Array Add
ユーザー hirono999hirono999
提出日時 2020-02-28 23:03:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,756 bytes
コンパイル時間 2,092 ms
コンパイル使用メモリ 166,796 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-04-21 20:17:00
合計ジャッジ時間 6,556 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
11,008 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 5 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 10 ms
5,376 KB
testcase_15 AC 8 ms
5,376 KB
testcase_16 TLE -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define to_s to_string
#define len(v) (int)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
ll MOD = 1e9 + 7;
ll devc(ll x, ll y) { return 1 + (x - 1) / y; }

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()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);

    ll N, Q;
    cin >> N >> Q;
    BinaryIndexedTree<ll> A(N),B(N);

    rep(i, N){
        ll a;
        cin >> a;
        A.add(i, a);
    }

    rep(i, Q){
        char c;
        ll x, y;
        cin >> c >> x >> y;
        --x;
        if(c == 'A') A.add(x, y);
        else{
            --y;
            for (ll j = x; j <= y; ++j){
                ll t;
                if(j >= 1) t = A.sum(j) - A.sum(j-1);
                else t = A.sum(j);
                B.add(j, t);
            }
        }
    }

    rep(i,N){
        if(i == 0) cout << B.sum(0) << " ";
        else{
            ll x = B.sum(i) - B.sum(i-1);
            cout << x << " ";
        }
    }


    return 0;
}
0