結果

問題 No.1000 Point Add and Array Add
ユーザー CleyLCleyL
提出日時 2020-03-07 17:24:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 250 ms / 2,000 ms
コード長 1,425 bytes
コンパイル時間 815 ms
コンパイル使用メモリ 73,372 KB
実行使用メモリ 9,600 KB
最終ジャッジ日時 2024-04-23 02:01:11
合計ジャッジ時間 5,566 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 3 ms
6,944 KB
testcase_13 AC 3 ms
6,944 KB
testcase_14 AC 4 ms
6,940 KB
testcase_15 AC 3 ms
6,944 KB
testcase_16 AC 180 ms
8,704 KB
testcase_17 AC 146 ms
6,940 KB
testcase_18 AC 246 ms
9,472 KB
testcase_19 AC 249 ms
9,600 KB
testcase_20 AC 234 ms
9,472 KB
testcase_21 AC 232 ms
9,600 KB
testcase_22 AC 250 ms
9,472 KB
testcase_23 AC 234 ms
9,472 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
//B
template<typename T>
struct BIT{//1_Indexed
  int n;
  vector<T> bit;
  vector<T> range;
  BIT(int n_):n(n_+1),bit(n,0),range(n,0){}

  T sum(int a){
    T ret = 0;
    for(int i = a; i > 0; i -= i & -i) ret += bit[i];
    return ret;
  }
  T rangesum(int a){
    T ret = 0;
    for(int i = a; i > 0; i -= i & -i) ret += range[i];
    return ret;
  }

  void add(int a,T w){
    for(int i = a; i <= n; i += i & -i)bit[i] += w;
  }
  void rangeadd(int x,int y,T w){// x < y
    y++;
    for(int i = x; i <= n; i += i & -i)range[i] += w;
    for(int i = y; i <= n; i += i & -i)range[i] -= w;
  }

  T query(int l,int r){
    if(r==1){
      return sum(l)+rangesum(l);
    }
    return sum(l)-sum(r-1)+rangesum(l);
  }


};
//E
int main(){//https://yukicoder.me/submissions/440699
  int n,q;cin>>n>>q;
  vector<long long> A(n);
  vector<long long> B(n);
  for(int i = 0; n > i; i++){
    cin>>A[i];
    B[i] = 0;
  }
  BIT<long long> Z(n);
  for(int i = 0; q > i; i++){
    char c;long long x,y;cin>>c>>x>>y;
    if(c == 'A'){
      //bit[x]+=y;
      if(Z.query(x,x)){
        int m = Z.query(x,x);
        B[x-1] += m*A[x-1];
        Z.add(x,m*-1);
      }
      A[x-1] += y;
    }else{
      Z.rangeadd(x,y,1);
    }
  }
  for(int j = 0; n > j; j++){
    cout << B[j]+Z.query(j+1,j+1)*A[j];
    if(j+1 != n)cout << " ";
  }
  cout << endl;
}
0