結果

問題 No.1000 Point Add and Array Add
ユーザー rniyarniya
提出日時 2020-03-03 01:27:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 104 ms / 2,000 ms
コード長 1,500 bytes
コンパイル時間 1,667 ms
コンパイル使用メモリ 169,072 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2024-04-21 23:01:02
合計ジャッジ時間 4,441 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 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 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 75 ms
8,576 KB
testcase_17 AC 61 ms
7,424 KB
testcase_18 AC 102 ms
10,368 KB
testcase_19 AC 104 ms
10,496 KB
testcase_20 AC 91 ms
10,496 KB
testcase_21 AC 104 ms
10,368 KB
testcase_22 AC 99 ms
10,496 KB
testcase_23 AC 103 ms
10,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

template<typename T>
struct BinaryIndexedTree{
    vector<T> dat;
    BinaryIndexedTree(int n):dat(n+1,0){}
    void add(int i,T x){
        if (i==0) return;
        for (;i<=dat.size();i+=(i&-i)) dat[i]+=x;
    }
    T sum(int i){
        T res=0;
        for (;i>0;i-=(i&-i)) res+=dat[i];
        return res;
    }
    T query(int l,int r){ //[l,r)
        return sum(r-1)-sum(l-1);
    }
    int lower_bound(T x){
        if (x<=0) return 0;
        int lb=0,r=1;
        while(r<dat.size()) r<<=1;
        for (;r>0;r>>=1){
            if (lb+r<dat.size()&&dat[lb+r]<x){
                x-=dat[lb+r]; lb+=r;
            }
        }
        return lb+1;
    }
    void add0(int i,T x){
        add(i+1,x);
    }
    T sum0(int i){
        return sum(i+1);
    }
    T query0(int l,int r){
        return sum(r)-sum(l);
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,Q; cin >> N >> Q;
    vector<ll> A(N),B(N,0);
    for (int i=0;i<N;++i) cin >> A[i];
    vector<char> c(Q);
    vector<ll> x(Q),y(Q);
    for (int i=0;i<Q;++i) cin >> c[i] >> x[i] >> y[i];
    BinaryIndexedTree<int> BIT(N+1);
    for (int i=Q-1;i>=0;--i){
        if (c[i]=='A'){
            B[x[i]-1]+=y[i]*BIT.sum(x[i]);
        } else {
            BIT.add(x[i],1);
            BIT.add(y[i]+1,-1);
        }
    }
    for (int i=0;i<N;++i){
        B[i]+=A[i]*BIT.sum(i+1);
        cout << B[i] << (i!=N-1?' ':'\n');
    }
}
0