結果

問題 No.1000 Point Add and Array Add
ユーザー CleyLCleyL
提出日時 2020-02-28 22:36:26
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 130 ms / 2,000 ms
コード長 2,757 bytes
コンパイル時間 950 ms
コンパイル使用メモリ 94,368 KB
実行使用メモリ 9,400 KB
最終ジャッジ日時 2023-08-03 21:19:16
合計ジャッジ時間 4,417 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 2 ms
4,384 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 91 ms
8,376 KB
testcase_17 AC 72 ms
6,236 KB
testcase_18 AC 127 ms
9,312 KB
testcase_19 AC 126 ms
9,400 KB
testcase_20 AC 117 ms
9,320 KB
testcase_21 AC 110 ms
9,244 KB
testcase_22 AC 130 ms
9,332 KB
testcase_23 AC 113 ms
9,332 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//author:luckYrat(twitter:@luckYrat_)
//#include <bits/stdc++.h>

//def
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

//array
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <utility>
#include <climits>



using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)


#define MAX 1000000000
const int mod = 1000000007;
#define EPS (1e-10)

#define pb push_back
#define fir first
#define scn second
#define ednl endl

#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")


P ar[4] = {{0,1},{0,-1},{1,0},{-1,0}};
/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる
vector.unique()は隣接した同じ要素を削除するので先にソートをする

計算量は変わらないが楽できるシリーズ
C++11以降でmin({a,b,c...})で複数個のmic,maxを処理できる
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる

*/
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);
  }


};
__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}
int main(){
  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