結果

問題 No.1000 Point Add and Array Add
ユーザー eQeeQe
提出日時 2020-04-02 05:17:55
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,174 bytes
コンパイル時間 1,414 ms
コンパイル使用メモリ 148,404 KB
実行使用メモリ 18,108 KB
最終ジャッジ日時 2023-09-10 04:28:42
合計ジャッジ時間 8,078 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 3 ms
8,368 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <string>
#define ft first
#define sc second
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) (a)=max(a, b)
#define chmin(a, b) (a)=min(a, b)
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;


/*
 for(i=0; i<N; i++)
   cin >> a[i];
*/

class LazySumSegTree {
public:
  ll n, height;
  vector<ll> data, lazy;
  
  LazySumSegTree(ll _n) {
    n=1;
    height=1;
    while(n<_n) {
      n*=2;
      height++;
    }
    data=vector<ll>(2*n-1);
    lazy=vector<ll>(2*n-1);
  }
  
  void eval(ll k, ll l, ll r) {
    if(lazy[k]!=0) {
      data[k]+=lazy[k];
      
      if(r-l>1) {
        lazy[k*2+1]+=lazy[k]/2;
        lazy[k*2+2]+=lazy[k]/2;
      }
      lazy[k]=0;
    }
  }
  
  void _add(ll a, ll b, ll x, ll k, ll l, ll r) {
    eval(k, l, r);
    if(r<=a || b<=l) return;
    
    if(a<=l && r<=b) {
      lazy[k]+=(r-l)*x;
      eval(k, l, r);
    }else {
      _add(a, b, x, k*2+1, l, (l+r)/2);
      _add(a, b, x, k*2+2, (l+r)/2, r);
      data[k]=data[k*2+1]+data[k*2+2];
    }
  }
  
  void add(ll a, ll b, ll x) {_add(a, b, x, 0, 0, n);}
  
  //[a, b):要求区間,[l, r):今見ている区間
  ll _sum(ll a, ll b, ll k, ll l, ll r) {
    if(r<=a || b<=l) return 0;
    
    eval(k, l, r);
    if(a<=l && r<=b) {
      return data[k];
    }else {
      ll s=_sum(a, b, k*2+1, l, (l+r)/2);
      ll t=_sum(a, b, k*2+2, (l+r)/2, r);
      return s+t;
    }
  }
  
  ll sum(ll a, ll b) {return _sum(a, b, 0, 0, n);}
  
};


int main(void) {
  ll i, j, k;
  
  ll N, Q;
  cin >> N >> Q;
  ll a[MAX*2];
  
  LazySumSegTree lst=LazySumSegTree(N);
  
  for(i=0; i<N; i++) cin >> a[i];
  
  char c[MAX*2];
  ll x[MAX*2], y[MAX*2];
  
  for(i=0; i<Q; i++) cin >> c[i] >> x[i] >> y[i];
  
  ll b[MAX*2]={};
  for(i=Q-1; i>=0; i--) {
    if(c[i]=='A') {
      x[i]--;
      b[x[i]]+=y[i]*lst.sum(x[i], x[i]+1);
    }else if(c[i]=='B') {
      x[i]--; y[i]--;
      lst.add(x[i], y[i]+1, 1);
    }
  }
  for(i=0; i<N; i++) b[i]+=a[i]*lst.sum(i, i+1);
  
  for(i=0; i<N; i++) pt(b[i]);
}

0