結果

問題 No.1000 Point Add and Array Add
ユーザー ChanyuhChanyuh
提出日時 2020-05-03 16:19:43
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 175 ms / 2,000 ms
コード長 3,712 bytes
コンパイル時間 2,438 ms
コンパイル使用メモリ 105,028 KB
実行使用メモリ 12,840 KB
最終ジャッジ日時 2023-09-03 15:28:23
合計ジャッジ時間 8,167 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,404 KB
testcase_01 AC 2 ms
5,364 KB
testcase_02 AC 2 ms
5,676 KB
testcase_03 AC 2 ms
5,412 KB
testcase_04 AC 2 ms
5,396 KB
testcase_05 AC 2 ms
5,404 KB
testcase_06 AC 2 ms
5,396 KB
testcase_07 AC 2 ms
5,540 KB
testcase_08 AC 2 ms
5,392 KB
testcase_09 AC 2 ms
5,364 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,460 KB
testcase_12 AC 3 ms
5,448 KB
testcase_13 AC 2 ms
5,508 KB
testcase_14 AC 3 ms
5,480 KB
testcase_15 AC 3 ms
5,484 KB
testcase_16 AC 113 ms
12,048 KB
testcase_17 AC 94 ms
9,560 KB
testcase_18 AC 175 ms
12,564 KB
testcase_19 AC 165 ms
12,840 KB
testcase_20 AC 125 ms
12,644 KB
testcase_21 AC 158 ms
12,648 KB
testcase_22 AC 136 ms
12,756 KB
testcase_23 AC 157 ms
12,612 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<char,P> PP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

template <typename T>
struct SegmentTree{
  using F = function<T(T,T)>;
  int n;
  F f;//二項演算
  T ti;//単位元
  vector<T> dat;

  SegmentTree(){}
  SegmentTree(F f,T ti):f(f),ti(ti){}

  void init(int n_){//sizeがn_のsegtreeを作る
    n=1;
    while(n<n_) n<<=1;
    dat.assign(n<<1,ti);
  }

  void build(const vector<T> &v){//vによってsegtreeをbuildする
    int n_=v.size();
    init(n_);
    for(int i=0;i<n_;i++) dat[n+i]=v[i];
    for(int i=n-1;i;i--)
      dat[i]=f(dat[(i<<1)|0],dat[(i<<1)|1]);
  }

  void set_val(int k,T x){//k番目をxにする
    dat[k+=n]=x;
    while(k>>=1)
      dat[k]=f(dat[(k<<1)|0],dat[(k<<1)|1]);
  }

  T query(int a,int b){//区間[a,b)に対しFを適応した値を返す
    if(a>=b) return ti;
    T vl=ti,vr=ti;
    for(int l=a+n,r=b+n;l<r;l>>=1,r>>=1) {
      if(l&1) vl=f(vl,dat[l++]);
      if(r&1) vr=f(dat[--r],vr);
    }
    return f(vl,vr);
  }

  template<typename C>
  int find(int st,C &check,T &acc,int k,int l,int r){//
    if(l+1==r){
      acc=f(acc,dat[k]);
      return check(acc)?k-n:-1;
    }
    int m=(l+r)>>1;
    if(m<=st) return find(st,check,acc,(k<<1)|1,m,r);
    if(st<=l&&!check(f(acc,dat[k]))){
      acc=f(acc,dat[k]);
      return -1;
    }
    int vl=find(st,check,acc,(k<<1)|0,l,m);
    if(~vl) return vl;
    return find(st,check,acc,(k<<1)|1,m,r);
  }

  template<typename C>
  int find(int st,C &check){
    T acc=ti;
    return find(st,check,acc,1,0,n);
  }

  T &operator [] (int i) {return dat[i+n];};
};


int n,q;
ll a[200010],b[200010];
PP query[200010];


void solve(){
  cin >> n >> q;
  rep(i,n){
    cin >> a[i];
  }
  auto f=[](ll a,ll b){return a+b;};
  SegmentTree<ll> seg(f,0);
  seg.init(n+1);
  rep(i,q){
    cin >> query[i].first >> query[i].second.first >> query[i].second.second;
    query[i].first-='A';
    query[i].second.first-=1;
    if((int)query[i].first==1)query[i].second.second-=1;
    //cout << (int)query[i].first << endl;
    if((int)query[i].first==1){
      int x=query[i].second.first,y=query[i].second.second;
      seg.set_val(x,seg[x]+1);
      seg.set_val(y+1,seg[y+1]-1);
    }
  }
  rep(i,n){
    //cout << i << " " << a[i] << " " << seg.query(0,i+1) << endl;
    b[i]+=a[i]*seg.query(0,i+1);
  }
  rep(i,q){
    int c,x,y;c=query[i].first;x=query[i].second.first;y=query[i].second.second;
    if(c==0){
      //cout << x << " " << y << " " << seg.query(0,x+1) << endl;
      b[x]+=y*seg.query(0,x+1);
    }
    else{
      seg.set_val(x,seg[x]-1);
      seg.set_val(y+1,seg[y+1]+1);
    }
  }
  rep(i,n){
    cout << b[i] << " ";
  }
  cout << "" << endl;
}

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