lostinue @ 2024-05-19 15:08:36
pts
#include<bits/stdc++.h>
#define ll long long
#define rep(i,aaa,bbb) for(int i=(aaa);i<=(bbb);i++)
#define per(i,aaa,bbb) for(int i=(aaa);i>=(bbb);i--)
#define min(a,b) ((a)>(b)?(b):(a))
#define fre for_each
#define pb push_back
using namespace std;
ll read(){
ll f=1,x=0;
char c=getchar();
while(c>'9'||c<'0'){
if(c=='-') f=-1;
c=getchar();
}
while(c>='0'&&c<='9'){
x=(x<<1)+(x<<3)+(c^48);
c=getchar();
}
return x*f;
}
const int maxn=1e6+10;
int n,m;
struct block{
const static int bsize=2048;
const int N;
vector<ll> a,b,lazy;//从0开始
block(int n): N((n+bsize-1)/bsize),a(n),b(n),lazy(N){}//a:yuanshi,ab:sort
#define bid(x) ((x)/bsize)
#define bg(x) ((x)/bsize*bsize)
#define ed(x) (min(bg(x)+bsize,(int)a.size()))
#define ae(l,r) a.begin()+l,a.begin()+r
#define be(l,r) b.begin()+l,b.begin()+r
#define le(l,r) lazy.begin()+l,lazy.begin()+r
void init(){
rep(i,0,N-1){
sort(b.begin()+i*bsize,b.begin()+min(i*bsize+bsize,(int)b.size()));
}
}
void add(int l,int r,ll v){
if(bid(l)==bid(r)){
fre(ae(l,r+1),[v](ll&x)mutable{x+=v;});
rep(i,bg(l),ed(l)-1)b[i]=a[i];
sort(be(bg(r),ed(r)));
}else{
fre(ae(l,ed(l)),[v](ll&x)mutable{x+=v;});
rep(i,bg(l),ed(l)-1)b[i]=a[i];
sort(be(bg(l),ed(l)));
fre(ae(bg(r),r+1),[v](ll&x)mutable{x+=v;});
rep(i,bg(r),ed(r)-1)b[i]=a[i];
sort(be(bg(r),ed(r)));
fre(le(bid(l)+1,bid(r)),[v](ll&x)mutable{x+=v;});
}
}
int que(int l,int r,ll c){
int ans=0;
if(bid(l)==bid(r)){
rep(i,l,r)if(a[i]+lazy[bid(i)]>=c)ans++;
return ans;
}else{
rep(i,l,ed(l)-1)if(a[i]+lazy[bid(i)]>=c)ans++;
rep(i,bg(r),r)if(a[i]+lazy[bid(i)]>=c)ans++;
rep(i,bid(l)+1,bid(r)-1){
int lll=i*bsize,rr=i*bsize+bsize-1;
while(lll<=rr){
int mm=(lll+rr)>>1;
if(b[mm]+lazy[i]>=c)rr=mm-1;
else lll=mm+1;
}
ans+=(i*bsize+bsize-lll);
}
return ans;
}
}
};
int main(){
int n=read(),q=read();
block B(n);
rep(i,0,n-1)B.a[i]=B.b[i]=read();
B.init();
while(q--){
char op; cin>>op;
int l=read(),r=read(),v=read();
if(op=='M')B.add(l,r,v);
if(op=='A')printf("%d\n",B.que(l,r,v));
}
return 0;
}
by xiaoyuhao0503 @ 2024-06-02 20:22:07
@lostinue 建议阅读这个