114514xxx @ 2024-08-14 20:17:49
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e6;
int pos[N],add[N],a[N],L[N],R[N],n,t,m;
int find1(int x,int d){
int l=L[x],r=R[x];
int mid=0;
while(l<=r){
mid=(l+r)/2;
if(a[mid]<d)l=mid+1;
else r=mid-1;
}
return R[x]-l+1;
}
void modify(int l,int r,int d){
int p=pos[l],q=pos[r];
if(p==q){
for(int i=l;i<=r;i++)
a[i]+=d;
sort(a+L[p],a+R[p]+1);
}else{
for(int i=p+1;i<=q-1;i++)
add[i]+=d;
for(int i=l;i<=R[p];i++)
a[i]+=d;
sort(a+L[p],a+R[p]+1);
for(int i=L[q];i<=r;i++)
a[i]+=d;
sort(a+L[q],a+R[q]+1);
}
}
int query(int l,int r,int d){
int ans=0;
int p=pos[l],q=pos[r];
if(p==q){
for(int i=l;i<=r;i++)
if(a[i]+add[p]>=d)++ans;
return ans;
}else{
for(int i=l;i<=R[p];i++)
if(a[i]+add[p]>=d)++ans;
for(int i=L[q];i<=r;i++)
if(a[i]+add[q]>=d)++ans;
for(int i=p+1;i<=q-1;i++)
ans+=find1(i,d-add[i]);
return ans;
}
}
signed main(){
cin>>n>>m;
for (int i=1;i<=n;i++)
cin>>a[i];
t=sqrt(n);
for (int i=1;i<=t;i++)
L[i]=(i-1)*t+1,R[i]=i*t;
R[t]=n;
for (int i=1;i<=t;i++)
for (int j=L[i];j<=R[i];j++)
pos[j]=i;
char opt;int l,r,c;
for(int i=1;i<=m;i++){
cin>>opt>>l>>r>>c;
if(opt=='M')modify(l,r,c);
else cout<<query(l,r,c)<<endl;
}
}
by 114514xxx @ 2024-08-14 21:19:44
已AC,此贴完结。
by ydkxj @ 2024-08-30 21:45:20
@114514xxx 怎么回事啊,我也是40pts