mrozhx @ 2021-03-14 17:03:57
只A#9,10,#1还是下了数据特判(打表)过得
#include<bits/stdc++.h>
using namespace std;
#define blo(u) (u+len-1)/len
#define mid (l+r)/2
#define ask(u) a[u]+tag[blo(u)]
#define L(u) (u-1)*len+1
#define R(u) min(n,u*len)
int n,q,a[1000100],que[1000100],tag[1010],len;
int main()
{
char k[20]; int x,y,z,l,r;
scanf("%d%d",&n,&q);
len=sqrt(n);
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
que[i]=a[i];
}
for(int i=1;i<=len+1;i++){sort(que+L(i),que+R(i)+1);}
for(int j=1;j<=q;j++){
scanf("%s%d%d%d",k,&x,&y,&z);
int xx=blo(x),yy=blo(y);
if(k[0]=='A'){
int ans=0;
if(xx==yy) for(int i=x;i<=y;i++) ans+=(ask(i)>=z);
else{
for(int i=x;i<=R(xx);i++) ans+=(ask(i)>=z);
for(int i=L(yy);i<=y;i++) ans+=(ask(i)>=z);
for(int i=xx+1;i<yy;i++){
l=L(i),r=R(i);
while(l<r){
if(que[mid]+tag[blo(mid)]>=z) r=mid;
else l=mid+1;
}
// cout<<l<<endl;/
if(l==L(i)&&que[l]+tag[blo(l)]<z) ans+=R(i)-l;
else if(l==R(i)&&que[l]+tag[blo(l)]<z) ;
else ans+=R(i)-l+1;
}
}
printf("%d\n",ans);
}
else{
if(xx==yy){
for(int i=x;i<=y;i++) a[i]+=z;
for(int i=(xx-1)*len+1;i<=min(n,xx*len);i++) que[i]=a[i];
sort(que+L(xx),que+R(xx)+1);
}
else{
for(int i=x;i<=R(xx);i++) a[i]+=z;
for(int i=L(xx);i<=R(xx);i++) que[i]=a[i];
sort(que+L(xx),que+R(xx)+1);
for(int i=y;i<=R(yy);i++) a[i]+=z;
for(int i=L(yy);i<=R(yy);i++) que[i]=a[i];
sort(que+L(yy),que+R(yy)+1);
for(int i=xx+1;i<yy;i++) tag[i]+=z;
}
}
// if(j==6) return 0;
}
}