結果

問題 No.1000 Point Add and Array Add
コンテスト
ユーザー C
提出日時 2026-10-01 23:44:46
言語 C++23(gcc16)
(gcc 16.1.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 123 ms / 2,000 ms
+ 3µs
コード長 1,477 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 7,681 ms
コンパイル使用メモリ 396,448 KB
実行使用メモリ 20,064 KB
最終ジャッジ日時 2026-10-01 23:45:05
合計ジャッジ時間 12,817 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#include <atcoder/all>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
using namespace std;
using namespace atcoder;
using namespace __gnu_pbds;
using ll=long long;
using ld=long double;
using vll=vector<ll>;
using vvll=vector<vll>;
using pll=pair<ll,ll>;

// using mint=modint;

// template<class K,class V>
// using ordered_map=tree<K,V,less<K>,rb_tree_tag,tree_order_statistics_node_update>;

struct S{
    ll sum=0,len=1;
};

S op(S a,S b){
    return {a.sum+b.sum,a.len+b.len};
}

S e(){
    return {0,0};
}

using F=ll;

S mapping(F f,S x){
    return {x.sum+f*x.len,x.len};
}

F composition(F f,F g){
    return f+g;
}

F id(){
    return 0;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

    ll N,Q;
    cin>>N>>Q;
    vll a(N),b(N,0);
    rep(i,0,N){
        cin>>a[i];
    }

    vector<S>init(N);
    lazy_segtree<S,op,e,F,mapping,composition,id> seg(init);

    while(Q--){
        string c;
        ll x,y;
        cin>>c>>x>>y;
        --x;
        if(c=="A"){
            ll cnt=seg.get(x).sum;
            b[x]+=a[x]*cnt;
            seg.set(x,{0,1});
            a[x]+=y;
        }else{
            seg.apply(x,y,1);
        }
    }
    rep(x,0,N){
        ll cnt=seg.get(x).sum;
        b[x]+=a[x]*cnt;
    }
    rep(i,0,N){
        if(i)cout<<' ';
        cout<<b[i];
    }
    cout<<endl;

}
0