結果

問題 No.1000 Point Add and Array Add
ユーザー milanis48663220milanis48663220
提出日時 2020-07-07 00:04:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 103 ms / 2,000 ms
コード長 1,539 bytes
コンパイル時間 794 ms
コンパイル使用メモリ 85,716 KB
実行使用メモリ 10,132 KB
最終ジャッジ日時 2023-10-25 03:31:40
合計ジャッジ時間 3,823 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,724 KB
testcase_01 AC 2 ms
7,724 KB
testcase_02 AC 3 ms
7,724 KB
testcase_03 AC 3 ms
7,724 KB
testcase_04 AC 3 ms
7,724 KB
testcase_05 AC 3 ms
7,724 KB
testcase_06 AC 2 ms
7,724 KB
testcase_07 AC 3 ms
7,728 KB
testcase_08 AC 3 ms
7,732 KB
testcase_09 AC 3 ms
7,724 KB
testcase_10 AC 3 ms
7,724 KB
testcase_11 AC 3 ms
7,724 KB
testcase_12 AC 3 ms
7,740 KB
testcase_13 AC 3 ms
7,732 KB
testcase_14 AC 3 ms
7,752 KB
testcase_15 AC 3 ms
7,776 KB
testcase_16 AC 70 ms
9,956 KB
testcase_17 AC 57 ms
9,164 KB
testcase_18 AC 96 ms
9,956 KB
testcase_19 AC 103 ms
9,956 KB
testcase_20 AC 91 ms
10,132 KB
testcase_21 AC 86 ms
10,080 KB
testcase_22 AC 98 ms
10,080 KB
testcase_23 AC 90 ms
10,080 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

//1-indexed
template <typename T>
struct bit{
    int n;
    vector<T> data;

    bit(int n_){
        n = 1;
        while(n < n_) n *= 2;
        data = vector<T>(n+1);
        for(int i = 0; i <= n; i++) data[i] = 0;
    }
    
    T sum(int i){
        T ret = 0;
        while(i > 0){
            ret += data[i];
            i -= i&-i;
        }
        return ret;
    }

    void add(int i, T x){
        while(i <= n){
            data[i] += x;
            i += i&-i;
        }
    }
};

int N, Q;
ll A[200000];
ll ans[200000];
ll imos[200005];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N >> Q;
    for(int i = 0; i < N; i++) cin >> A[i];
    bit<int> btl(N), btr(N);
    int cnt_a = 0;
    
    for(int i = 0; i < Q; i++){
        char c; int x, y; cin >> c >> x >> y;
        if(c == 'B'){
            btl.add(x, 1);
            btr.add(y, 1);
            cnt_a++;
            imos[x-1]++;
            imos[y]--;
        }else{
            ll cnt_r = btr.sum(x-1);
            ll cnt_l = (y == N ? 0 : btl.sum(N)-btl.sum(x));
            ans[x-1] -= (y)*(cnt_a-cnt_l-cnt_r);
            A[x-1] += y;
        }
    }
    for(int i = 1; i < N; i++) imos[i] += imos[i-1];
    for(int i = 0; i < N; i++){
        ans[i] += imos[i]*A[i];
        cout << ans[i] << ' ';
    }
    cout << endl;
}
0