結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 4 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 159 ms
9,600 KB
testcase_17 AC 136 ms
8,320 KB
testcase_18 AC 223 ms
11,520 KB
testcase_19 AC 228 ms
11,648 KB
testcase_20 AC 205 ms
9,856 KB
testcase_21 AC 224 ms
10,240 KB
testcase_22 AC 212 ms
10,240 KB
testcase_23 AC 223 ms
10,240 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("YES");}else{puts("NO");}

const int MAX_N = 300005;
ll bit[MAX_N+1];
int nn = MAX_N; // 1-index

void adds(int a, ll w){
    for(int x = a; x <= nn; x += x & -x) bit[x] += w;
}
ll sums(int a){ // bit[1,a]の和を返す.
    ll ret = 0;
    for(int x = a; x > 0; x -= x & -x) ret += bit[x];  
    return ret;
}

int main() {
    ll n, q;
    cin >> n >> q;
    ll a[n + 1] = {};
    srep(i,1,n+1)cin >> a[i];
    char c[q];
    ll x[q], y[q];
    rep(i,q)cin >> c[i] >> x[i] >> y[i];

    ll b[n+1] = {};

    drep(i,q){
        if(c[i] == 'A'){
            b[x[i]] += y[i] * sums(x[i]);
        }else{
            adds(x[i], 1);
            adds(y[i] + 1, -1);
        }
    }

    srep(i,1,n+1){
        b[i] += sums(i) * a[i];
        cout << b[i] << ' ';
    }
    cout << endl;



    return 0;
}
 
 
0