結果

問題 No.1000 Point Add and Array Add
ユーザー snow39snow39
提出日時 2020-02-28 21:37:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 291 ms / 2,000 ms
コード長 2,215 bytes
コンパイル時間 1,123 ms
コンパイル使用メモリ 100,208 KB
実行使用メモリ 17,840 KB
最終ジャッジ日時 2023-08-03 19:48:15
合計ジャッジ時間 5,496 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 4 ms
4,380 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 190 ms
16,132 KB
testcase_17 AC 161 ms
11,320 KB
testcase_18 AC 275 ms
17,840 KB
testcase_19 AC 275 ms
17,724 KB
testcase_20 AC 179 ms
17,636 KB
testcase_21 AC 291 ms
17,748 KB
testcase_22 AC 228 ms
17,624 KB
testcase_23 AC 291 ms
17,812 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

class LazySegmentTree{
private:
  int n;
  vector<ll> node,lazy;

public:
  LazySegmentTree(vector<ll> v){
      n=1;
      while(n<v.size()) n*=2;
      node.resize(2*n-1,0);
      lazy.resize(2*n-1,0);
      
      for(int i=0;i<v.size();i++) node[i+n-1]=v[i];
      for(int i=n-2;i>=0;i--) node[i]=node[2*i+1]+node[2*i+2];
  }

  void eval(int k,int l,int r){
      if(lazy[k]!=0){
          node[k]+=lazy[k];
          if(r-l>1){
              lazy[2*k+1]+=lazy[k]/2;
              lazy[2*k+2]+=lazy[k]/2;
          }
          lazy[k]=0;
      }
  }

  void add(int a,int b,ll x,int k=0,int l=0,int r=-1){
      if(r<0) r=n;
      eval(k,l,r);
      if(b<=l||r<=a) return;
      if(a<=l&&r<=b){
          lazy[k]+=(r-l)*x;
          eval(k,l,r);
      }else{
          add(a,b,x,2*k+1,l,(r+l)/2);
          add(a,b,x,2*k+2,(r+l)/2,r);
          node[k]=node[2*k+1]+node[2*k+2];
      }
  }

  ll getSum(int a,int b,int k=0,int l=0,int r=-1){
      if(r<0) r=n;
      eval(k,l,r);
      if(b<=l||r<=a) return 0;
      if(a<=l&&r<=b) return node[k];

      ll vl,vr;
      vl=getSum(a,b,2*k+1,l,(l+r)/2);
      vr=getSum(a,b,2*k+2,(l+r)/2,r);
      return vl+vr;
  }
};

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

  int N,Q;
  cin>>N>>Q;
  vector<ll> A(N);
  rep(i,N) cin>>A[i];
  vector<char> C(Q);
  vector<ll> X(Q),Y(Q);
  rep(i,Q) cin>>C[i]>>X[i]>>Y[i];

  LazySegmentTree seg(vector<ll> (N,0));
  vector<ll> B(N,0);
  for(int q=Q-1;q>=0;q--){
    X[q]--;
    if(C[q]=='A'){
      ll val=seg.getSum(X[q],X[q]+1);
      B[X[q]]+=Y[q]*val;
    }else{
      Y[q]--;
      seg.add(X[q],Y[q]+1,1);
    }
  }
  for(int i=0;i<N;i++){
    ll val=seg.getSum(i,i+1);
    B[i]+=A[i]*val;
  }

  for(auto n:B) cout<<n<<" ";
  cout<<endl;

  return 0;
}
0