結果

問題 No.1000 Point Add and Array Add
ユーザー tanimani364tanimani364
提出日時 2020-02-29 11:37:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 315 ms / 2,000 ms
コード長 3,563 bytes
コンパイル時間 1,798 ms
コンパイル使用メモリ 152,096 KB
実行使用メモリ 17,664 KB
最終ジャッジ日時 2024-04-21 21:31:35
合計ジャッジ時間 5,779 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 3 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 4 ms
5,376 KB
testcase_15 AC 4 ms
5,376 KB
testcase_16 AC 215 ms
16,768 KB
testcase_17 AC 178 ms
10,496 KB
testcase_18 AC 315 ms
17,536 KB
testcase_19 AC 305 ms
17,536 KB
testcase_20 AC 216 ms
17,536 KB
testcase_21 AC 287 ms
17,536 KB
testcase_22 AC 261 ms
17,664 KB
testcase_23 AC 291 ms
17,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
using namespace std;
//ここから
template<typename T>
struct LazySegmentTree{//区間加算,区間更新,0オリジン
    private:
        int n;
        vector<T>node,lazy;
        const T E;//単位元
    
    public:
        LazySegmentTree(vector<T>v,T e):E(e){
            int sz=(int)v.size();
            n=1;
            while(n<sz)n<<=1;
            node.resize(2*n-1);
            lazy.resize(2*n-1,E);
            for(int i=0;i<sz;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];
        }

        //k番目のノードについて遅延評価
        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 update(int a,int b,T x,int k=0,int l=0,int r=-1){
            if(r<0)r=n;

            //k番目のノードに遅延評価
            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{
                update(a,b,x,2*k+1,l,(l+r)/2);
                update(a,b,x,2*k+2,(l+r)/2,r);
                node[k]=node[2*k+1]+node[2*k+2];
            }
        }

        T getval(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 E;
            if(a<=l&&r<=b)return node[k];
            T vall=getval(a,b,2*k+1,l,(l+r)/2);
            T valr=getval(a,b,2*k+2,(l+r)/2,r);
            return vall+valr;
        }
};


void solve(){
  int n,q;
  cin>>n>>q;
  vector<ll>a(n),add(n);
  vector<ll>v(n);
  rep(i,n)cin>>a[i];
  LazySegmentTree<ll>sg(v,0);
  while(q--){
    char c;
    ll x,y;
    cin>>c>>x>>y;
    if(c=='A'){
      x--;
      a[x]+=y;
      add[x]-=y*sg.getval(x,x+1);
    }
    else {
      x--;y--;
      sg.update(x,y+1,1);
    }
  }
  rep(i,n){
    if(i)cout<<" ";
    cout<<a[i]*sg.getval(i,i+1)+add[i];
  }
  cout<<endl;
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}
0