結果

問題 No.1000 Point Add and Array Add
ユーザー milanis48663220milanis48663220
提出日時 2020-07-06 23:54:09
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,818 bytes
コンパイル時間 1,147 ms
コンパイル使用メモリ 86,000 KB
実行使用メモリ 16,548 KB
最終ジャッジ日時 2023-10-25 02:11:53
合計ジャッジ時間 3,890 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
13,908 KB
testcase_01 AC 4 ms
13,908 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 3 ms
13,908 KB
testcase_06 WA -
testcase_07 AC 3 ms
13,912 KB
testcase_08 AC 3 ms
13,916 KB
testcase_09 AC 4 ms
13,908 KB
testcase_10 AC 3 ms
13,908 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 83 ms
16,536 KB
testcase_21 AC 86 ms
13,808 KB
testcase_22 WA -
testcase_23 WA -
権限があれば一括ダウンロードができます

ソースコード

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];
char c_[200000];
ll x_[200000], y_[200000];
ll b_sum[200000];
ll b_tmp[200000];

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++){
        cin >> c_[i] >> x_[i] >> y_[i];
        if(c_[i] == 'A'){
            b_sum[x_[i]-1] += y_[i];
        }
    }
    for(int i = 0; i < Q; i++){
        char c = c_[i]; int x = x_[i], y = y_[i];
        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] -= (b_sum[x-1]-b_tmp[x-1])*(cnt_a-cnt_l-cnt_r);
            A[x-1] += y;
            b_tmp[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