#include #include #include #include #include #include #include #include #include #include #define mkp make_pair #define mkt make_tuple #define rep(i,n) for(int i = 0; i < (n); ++i) using namespace std; typedef long long ll; const ll MOD=1e9+7; template void chmin(T &a,const T &b){if(a>b) a=b;} template void chmax(T &a,const T &b){if(a node,lazy; public: LazySegmentTree(vector v){ n=1; while(n=0;i--) node[i]=node[2*i+1]+node[2*i+2]; } 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 add(int a,int b,ll x,int k=0,int l=0,int r=-1){ if(r<0) r=n; 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{ add(a,b,x,2*k+1,l,(r+l)/2); add(a,b,x,2*k+2,(r+l)/2,r); node[k]=node[2*k+1]+node[2*k+2]; } } ll getSum(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 0; if(a<=l&&r<=b) return node[k]; ll vl,vr; vl=getSum(a,b,2*k+1,l,(l+r)/2); vr=getSum(a,b,2*k+2,(l+r)/2,r); return vl+vr; } }; int main(){ cin.tie(0); ios::sync_with_stdio(false); int N,Q; cin>>N>>Q; vector A(N); rep(i,N) cin>>A[i]; vector C(Q); vector X(Q),Y(Q); rep(i,Q) cin>>C[i]>>X[i]>>Y[i]; LazySegmentTree seg(vector (N,0)); vector B(N,0); for(int q=Q-1;q>=0;q--){ X[q]--; if(C[q]=='A'){ ll val=seg.getSum(X[q],X[q]+1); B[X[q]]+=Y[q]*val; }else{ Y[q]--; seg.add(X[q],Y[q]+1,1); } } for(int i=0;i