結果

問題 No.1000 Point Add and Array Add
ユーザー kkktymkkktym
提出日時 2020-02-28 22:42:17
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 425 ms / 2,000 ms
コード長 2,452 bytes
コンパイル時間 1,237 ms
コンパイル使用メモリ 79,056 KB
実行使用メモリ 18,816 KB
最終ジャッジ日時 2024-04-21 19:52:12
合計ジャッジ時間 6,420 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 4 ms
5,376 KB
testcase_14 AC 6 ms
5,376 KB
testcase_15 AC 5 ms
5,376 KB
testcase_16 AC 298 ms
18,176 KB
testcase_17 AC 255 ms
11,008 KB
testcase_18 AC 422 ms
18,816 KB
testcase_19 AC 425 ms
18,688 KB
testcase_20 AC 329 ms
18,688 KB
testcase_21 AC 407 ms
18,688 KB
testcase_22 AC 373 ms
18,816 KB
testcase_23 AC 411 ms
18,816 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
typedef long long ll;
template <typename X>
class DST
{
private:
  int n;
  vector<X> dat,delay,arr;
  const X init = 0;

  void eval(int k,int l,int r)
  {
    if(delay[k] != 0){
      if(k>=n-1) dat[k] += delay[k]*arr[k];
      else if(k<n-1){
	delay[2*k+1] += delay[k]/2;
	delay[2*k+2] += delay[k]/2;
      }
      delay[k] = 0;
    }
  }
  

  
public:  
  DST(int _n,vector<X> _arr)
  {
    n = 1;
    while(n < _n) n *= 2;
    dat.assign(2*n-1,init);
    delay.assign(2*n-1,init);
    arr.resize(2*n-1,init);
    rep(i,_arr.size()){
      arr[n-1+i]=_arr[i];
    }
  }

  void update(int a,int b,X x,int k,int l,int r)
  {
    eval(k,l,r);
    
    if(r<=a||b<=l) return ;
    
    if(a<=l&&r<=b){
      delay[k] += (r-l)*x;
      eval(k,l,r);
    }
    else{
      update(a,b,x,2*k+1,l,(l+r)/2);
      update(a,b,x,2*k+2,(l+r)/2,r);
      //      dat[k] = dat[2*k+1] + dat[2*k+2];
    }
  }

  void query(int a,X x,int k,int l,int r)
  {
    eval(k,l,r);
    if(a<l||r<=a) return ;

    if(k>=n-1) arr[k] += x;
    else{
      query(a,x,2*k+1,l,(l+r)/2);
      query(a,x,2*k+2,(l+r)/2,r);      
    }
  }

  int size(){
    return n;
  }

  int get_dat(int x){
    return dat[n-1+x];
  }    
  
  void all_eval(){
    rep(i,2*n-1){
      eval(i,0,0);
    }
  }
  
  void show(){
    int index = 0;
    int num = 1;
    while(index<n){
      rep(i,num){
	cout << dat[i+index] << " ";
      }
      cout << "\n";
      num *= 2;
      index = index*2+1;
    }
    index = 0;
    num = 1;
    while(index<n){
      rep(i,num){
	cout << delay[i+index] << " ";
      }
      cout << "\n";
      num *= 2;
      index = index*2+1;    
    }
    index = 0;
    num = 1;
    while(index<n){
      rep(i,num){
	cout << arr[i+index] << " ";
      }
      cout << "\n";
      num *= 2;
      index = index*2+1;    
    }    
  }

  void solve(int nn){
    rep(i,nn) cout << dat[n-1+i] << " ";
    cout  << "\n";
  }
  
};



int main()
{
  int n,q;cin >> n >> q;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  DST<ll> dst(n,a);
  rep(i,q){
    char c;int x,y;
    cin >> c >> x >> y;
    if(c=='A'){
      dst.query(x-1,y,0,0,dst.size());
    }
    else{
      dst.update(x-1,y,1,0,0,dst.size());
    }
    //    dst.show();
  }  
  dst.all_eval();
  //  dst.show();
  dst.solve(n);
  
  return 0;
}
0