結果

問題 No.1000 Point Add and Array Add
ユーザー kappybarkappybar
提出日時 2020-03-31 11:50:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 241 ms / 2,000 ms
コード長 1,727 bytes
コンパイル時間 1,796 ms
コンパイル使用メモリ 172,936 KB
実行使用メモリ 20,440 KB
最終ジャッジ日時 2023-09-06 13:01:17
合計ジャッジ時間 7,016 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,388 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 2 ms
4,388 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 4 ms
4,380 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 177 ms
11,960 KB
testcase_17 AC 146 ms
10,784 KB
testcase_18 AC 235 ms
14,636 KB
testcase_19 AC 233 ms
14,624 KB
testcase_20 AC 241 ms
20,440 KB
testcase_21 AC 229 ms
9,380 KB
testcase_22 AC 241 ms
19,884 KB
testcase_23 AC 213 ms
10,480 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;

/*1-indexedに注意!!!*/
struct BIT{
        private:
        int n;
        vector<ll> bit;
        
        public:
        BIT(int m){
                n = m;
                bit.resize(n+1);
        }
        
        ll sum(int i){
                ll res = 0;
                while(i > 0){
                        res += bit.at(i);
                        i -= i&-i;
                }
                return res;
        }
        
        void add(int i,ll val){
                while(i <= n){
                        bit.at(i) += val;
                        i += i&-i;
                }
        }
};

int main() {
        int n,q;
        cin >> n >> q;
        vector<ll> a(n+1);
        rep(i,n) cin >> a[i+1];
        vector<vector<ll>> query;
        BIT bit(n+1);
        while(q--){
                char c;
                ll x,y;
                cin >> c >> x >> y;
                if(c =='A'){
                        query.push_back({x,bit.sum(x),y});
                }else{
                        bit.add(x,1);
                        bit.add(y+1,-1);
                }
        }

        vector<ll> cnt(n+1);
        for(int i=1;i<=n;i++){
                cnt[i] = bit.sum(i);
        }
        vector<ll> ans(n+1);

        for(int i=1;i<=n;i++){
                ans[i] += a[i] * cnt[i];
        }

        for(auto v:query){
                ans[v[0]] += (cnt[v[0]] - v[1])*v[2];
        }

        for(int i=1;i<=n;i++){
                cout << ans[i] << " " ;
        }

        cout << endl;


        return 0;  
}
0