結果

問題 No.1000 Point Add and Array Add
ユーザー ngtkanangtkana
提出日時 2020-02-28 22:12:53
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 318 ms / 2,000 ms
コード長 1,301 bytes
コンパイル時間 1,902 ms
コンパイル使用メモリ 167,040 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-04-21 19:03:51
合計ジャッジ時間 6,063 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 4 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 5 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 231 ms
9,984 KB
testcase_17 AC 169 ms
6,912 KB
testcase_18 AC 291 ms
10,624 KB
testcase_19 AC 286 ms
10,496 KB
testcase_20 AC 318 ms
10,496 KB
testcase_21 AC 256 ms
10,496 KB
testcase_22 AC 309 ms
10,496 KB
testcase_23 AC 257 ms
10,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
int main(){
    int n,q;std::cin>>n>>q;
    std::vector<long long>a(n);
    for(int i=0;i<n;i++)std::cin>>a.at(i);
    std::vector<long long>b(n);
    int N=1;while(N<n+1)N*=2;
    std::vector<long long>seg(2*N);
    for(int i=0;i<q;i++){
        char c;std::cin>>c;
        if(c=='A'){
            int i;std::cin>>i;
            i--;
            long long y=0;
            for(int l=N,r=i+1+N;l<r;l/=2,r/=2){
                if(l%2==1)y+=seg.at(l++);
                if(r%2==1)y+=seg.at(--r);
            }
            b.at(i)+=a.at(i)*y;
            seg.at(i+N)-=y;
            seg.at(i+1+N)+=y;
            for(int j=(i+N)/2;j>0;j/=2)seg.at(j)=seg.at(2*j)+seg.at(2*j+1);
            for(int j=(i+1+N)/2;j>0;j/=2)seg.at(j)=seg.at(2*j)+seg.at(2*j+1);
            int x;std::cin>>x;
            a.at(i)+=x;
        }
        if(c=='B'){
            int l,r;std::cin>>l>>r;
            l--;
            seg.at(l+N)++;
            seg.at(r+N)--;
            for(int j=(l+N)/2;j>0;j/=2)seg.at(j)=seg.at(2*j)+seg.at(2*j+1);
            for(int j=(r+N)/2;j>0;j/=2)seg.at(j)=seg.at(2*j)+seg.at(2*j+1);
        }
    }
    long long coeff=0;
    for(int i=0;i<n;i++){
        coeff+=seg.at(i+N);
        std::cout<<(i?" ":"")<<a.at(i)*coeff+b.at(i);
    }
    std::cout<<std::endl;
}
0