結果

問題 No.1000 Point Add and Array Add
ユーザー tko919tko919
提出日時 2020-03-05 01:12:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 405 ms / 2,000 ms
コード長 2,683 bytes
コンパイル時間 2,327 ms
コンパイル使用メモリ 174,748 KB
実行使用メモリ 19,552 KB
最終ジャッジ日時 2024-04-22 01:58:31
合計ジャッジ時間 7,058 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 4 ms
5,376 KB
testcase_13 AC 4 ms
5,376 KB
testcase_14 AC 5 ms
5,376 KB
testcase_15 AC 4 ms
5,376 KB
testcase_16 AC 261 ms
17,156 KB
testcase_17 AC 241 ms
12,408 KB
testcase_18 AC 386 ms
19,464 KB
testcase_19 AC 392 ms
19,468 KB
testcase_20 AC 245 ms
19,552 KB
testcase_21 AC 405 ms
19,468 KB
testcase_22 AC 314 ms
19,400 KB
testcase_23 AC 402 ms
19,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
void tostr(ll x,string& res){while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return;}
template<class T> inline bool chmax(T& a,T b){ if(a<b){a=b;return 1;}return 0; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){a=b;return 1;}return 0; }
//template end

template<typename M,typename N=M>
struct LazySegmentTree{
   using F=function<M(M,M)>; using G=function<M(M,N)>; using H=function<N(N,N)>;
   int sz,height; vector<M> data; vector<N> lazy;
   const F f;const G g; const H h; const M m1; const N n1;
   LazySegmentTree(int n,const F f,const G g,const H h,const M &m1,const N n1):f(f),g(g),h(h),m1(m1),n1(n1){
      sz=1,height=0; while(sz<n)sz<<=1,height++;
      data.assign(2*sz,m1); lazy.assign(2*sz,n1);
   }
   void build(vector<M> v){
      rep(i,0,v.size())data[i+sz]=v[i];
      rrep(k,sz-1,0)data[k]=f(data[2*k],data[2*k+1]);
   }
   M ref(int k){return lazy[k]==n1?data[k]:g(data[k],lazy[k]);}
   void recalc(int k){while(k>>=1)data[k]=f(ref(2*k),ref(2*k+1));}
   void thrust(int k){rrep(i,height,0)eval(k>>i);}
   void eval(int k){
      if(lazy[k]!=n1){
         lazy[2*k]=h(lazy[2*k],lazy[k]); lazy[2*k+1]=h(lazy[2*k+1],lazy[k]);
         data[k]=ref(k); lazy[k]=n1;
      }
   }
   void update(int a,int b,N x){
      thrust(a+=sz); thrust(b+=sz-1);
      for(int l=a,r=b+1;l<r;l>>=1,r>>=1){
         if(l&1)lazy[l]=h(lazy[l],x),++l;
         if(r&1)--r,lazy[r]=h(lazy[r],x);
      }
      recalc(a); recalc(b);
   }
   M query(int a,int b){
      thrust(a+=sz); thrust(b+=sz-1);
      M L=m1,R=m1;
      for(int l=a,r=b+1;l<r;l>>=1,r>>=1){
         if(l&1)L=f(L,ref(l++)); if(r&1)R=f(ref(--r),R);
      } return f(L,R);
   }
};

struct query{
   char c; int x,y;
};

int main(){
   int n,q; scanf("%d%d",&n,&q);
   vector<ll> a(n);
   rep(i,0,n)scanf("%lld",&a[i]);
   vector<query> b(q);
   rep(i,0,q){
      char c; int x,y; cin>>c>>x>>y;
      b.push_back(query{c,x,y});
   }
   reverse(ALL(b));
   LazySegmentTree<ll> seg(n,
   [](ll a,ll b){return a+b;},
   [](ll a,ll b){return a+b;},
   [](ll a,ll b){return a+b;},0,0);
   vector<ll> res(n,0);
   rep(i,0,q){
      if(b[i].c=='A'){
         ll add=seg.query(b[i].x-1,b[i].x);
         res[b[i].x-1]+=b[i].y*add;
      }
      else seg.update(b[i].x-1,b[i].y,1);
   }
   rep(i,0,n)res[i]+=seg.query(i,i+1)*a[i];
   rep(i,0,n)printf("%lld ",res[i]); puts("");
   return 0;
}
0