結果

問題 No.1000 Point Add and Array Add
ユーザー face4face4
提出日時 2020-05-30 11:28:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 104 ms / 2,000 ms
コード長 1,341 bytes
コンパイル時間 666 ms
コンパイル使用メモリ 70,252 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2024-04-24 22:23:01
合計ジャッジ時間 3,385 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,248 KB
testcase_03 AC 2 ms
5,248 KB
testcase_04 AC 2 ms
5,248 KB
testcase_05 AC 2 ms
5,248 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 3 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,832 KB
testcase_17 AC 62 ms
7,680 KB
testcase_18 AC 102 ms
10,496 KB
testcase_19 AC 103 ms
10,624 KB
testcase_20 AC 90 ms
10,496 KB
testcase_21 AC 102 ms
10,624 KB
testcase_22 AC 95 ms
10,624 KB
testcase_23 AC 104 ms
10,496 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<cstring>
#include<vector>
using namespace std;

typedef long long ll;

struct BIT{
    vector<int> v;
    int n;

    BIT(int _n):
        v(vector<int>(_n+1, 0)), n(_n) {}

    int sum(int i){
        int s = 0;
        while(i > 0){
            s += v[i];
            i -= lsb(i);
        }
        return s;
    }
    
    int sum(int l, int r){
        return sum(r) - sum(l-1);
    }

    void add(int i, int x){
        while(i <= n){
            v[i] += x;
            i += lsb(i);
        }
    }

private:
    // least significant bit
    int lsb(int i){
        return i & -i;
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, q;
    cin >> n >> q;
    ll a[n], b[n];
    for(int i = 0; i < n; i++)  cin >> a[i];
    memset(b, 0, sizeof(b));
    char op[q];
    ll x[q], y[q];
    for(int i = 0; i < q; i++){
        cin >> op[i] >> x[i] >> y[i];
        x[i]--;
        if(op[i] == 'B'){
            y[i]--;
        }
    }
    BIT bit(n+1);
    for(int i = q-1; i >= 0; i--){
        if(op[i] == 'A'){
            b[x[i]] += y[i]*bit.sum(x[i]+1);
        }else if(op[i] == 'B'){
            bit.add(x[i]+1, 1);
            bit.add(y[i]+2,-1);
        }
    }
    for(int i = 0; i < n; i++){
        cout << a[i]*bit.sum(i+1)+b[i] << " \n"[i==n-1];
    }
    return 0;
}
0