結果

問題 No.1000 Point Add and Array Add
ユーザー monnumonnu
提出日時 2021-04-18 18:27:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 337 ms / 2,000 ms
コード長 1,465 bytes
コンパイル時間 1,741 ms
コンパイル使用メモリ 171,080 KB
実行使用メモリ 11,476 KB
最終ジャッジ日時 2023-09-17 07:50:55
合計ジャッジ時間 6,304 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 4 ms
4,376 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 4 ms
4,376 KB
testcase_15 AC 4 ms
4,380 KB
testcase_16 AC 223 ms
10,152 KB
testcase_17 AC 188 ms
8,076 KB
testcase_18 AC 311 ms
11,388 KB
testcase_19 AC 310 ms
11,440 KB
testcase_20 AC 267 ms
11,476 KB
testcase_21 AC 337 ms
11,476 KB
testcase_22 AC 280 ms
11,444 KB
testcase_23 AC 331 ms
11,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
using ll=long long;
using Graph=vector<vector<int>>;
#define MAX 200003
#define MOD 1000000007
#define INF 1000000000000000000

int n=1;
vector<int> tree;
void propagate(int i){
  if(i<n-1){
    tree[2*i+1]+=tree[i];
    tree[2*i+2]+=tree[i];
    tree[i]=0;
  }
}
void add(int a,int b,int i,int left,int right,int x){
  propagate(i);
  if(a<=left&&right<=b){
    tree[i]+=x;
    return;
  }
  if(b<=left||right<=a){
    return;
  }
  add(a,b,2*i+1,left,(left+right)/2,x);
  add(a,b,2*i+2,(left+right)/2,right,x);
}
int get(int i){
  int index=0;
  int left=0;
  int right=n;
  while(left+1<right){
    int x=(left+right)/2;
    propagate(index);
    if(i<x){
      right=x;
      index=2*index+1;
    }else{
      left=x;
      index=2*index+2;
    }
  }
  propagate(index);
  return tree[index];
}

int main(){
  int N,Q;
  cin>>N>>Q;
  vector<ll> A(N);
  vector<char> c(Q);
  vector<ll> x(Q),y(Q);
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  for(int i=0;i<Q;i++){
    cin>>c[i]>>x[i]>>y[i];
  }

  while(n<N){
    n<<=1;
  }
  tree.resize(2*n-1,0);
  vector<ll> B(N);
  for(int i=Q-1;i>=0;i--){
    if(c[i]=='B'){
      add(x[i]-1,y[i],0,0,n,1);
    }else{
      int cnt=get(x[i]-1);
      B[x[i]-1]+=(ll)cnt*y[i];
    }
  }

  for(int i=0;i<N;i++){
    int cnt=get(i);
    B[i]+=(ll)cnt*A[i];
  }

  for(int i=0;i<N;i++){
    cout<<B[i]<<" ";
  }
  cout<<endl;
}
0