結果

問題 No.1000 Point Add and Array Add
ユーザー totori_nyaatotori_nyaa
提出日時 2020-02-28 21:37:35
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 106 ms / 2,000 ms
コード長 972 bytes
コンパイル時間 1,726 ms
コンパイル使用メモリ 163,952 KB
実行使用メモリ 11,648 KB
最終ジャッジ日時 2024-04-21 18:06:33
合計ジャッジ時間 4,596 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 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 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 77 ms
9,600 KB
testcase_17 AC 60 ms
8,320 KB
testcase_18 AC 103 ms
11,648 KB
testcase_19 AC 105 ms
11,520 KB
testcase_20 AC 93 ms
9,984 KB
testcase_21 AC 106 ms
10,240 KB
testcase_22 AC 105 ms
10,368 KB
testcase_23 AC 104 ms
10,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

ll N;
ll bit[2010000];

//aの位置にwを追加
void add(ll a,ll w){
    a++;
    for(int x=a;x<=N+1;x+=(x&(-x)) ){
        bit[x] += w;
    }
}

//v[0] + ... + v[a-1]
ll sum(ll a){
    ll ret=0;
    for(int x=a;x>0;x-=(x&(-x)) ){
        ret+=bit[x];
    }
    return ret;
}


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
    
    int n,q;
    cin>>n>>q;
    N = n;
    ll a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    ll ans[n]={};
    ll x[q],y[q];
    char c[q];
    for(int i=0;i<q;i++){
        cin>>c[i]>>x[i]>>y[i];
    }
    for(int i=q-1;i>=0;i--){
        if(c[i] == 'A'){
            ans[x[i]-1] += y[i] * sum(x[i]);
        }
        else{
            add(x[i]-1,1);
            add(y[i],-1);
        }
    }
    for(int i=0;i<n;i++){
        ans[i] += a[i] * sum(i+1);
        cout << ans[i] << " ";
    }
    cout << endl;
    
}
0