qzmoot @ 2024-05-06 20:34:53
rt,60pts全是wa。
#include <bits/stdc++.h>
using namespace std;
const int N=1e6+5,SN=1005;
int n,q,a[N];
int b[SN],id[N],l[SN],r[SN],len,lz[SN];
int read()
{
int x=0,f=1;
char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
while(isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
void rd(char &x)
{
x=getchar();
while(x!='A' && x!='M')
x=getchar();
}
int ef(int le,int ri,int val)
{
int as=0,nr=ri;
while(le<=ri)
{
int mid=le+ri>>1;
if(b[mid]>=val)
ri=mid-1,as=nr-mid+1;
else
le=mid+1;
}
return as;
}
void upd(int x,int y,int k)
{
int nx=id[x],ny=id[y];
if(nx==ny)
{
for(int i=x;i<=y;i++)
a[i]+=k;
for(int i=l[nx];i<=r[nx];i++)
b[i]=a[i];
sort(b+l[nx],b+r[nx]+1);
return;
}
for(int i=x;i<=r[nx];i++)
a[i]+=k;
for(int i=l[nx];i<=r[nx];i++)
b[i]=a[i];
sort(b+l[nx],b+r[nx]+1);
for(int i=l[ny];i<=y;i++)
a[i]+=k;
for(int i=l[ny];i<=r[ny];i++)
b[i]=a[i];
sort(b+l[nx],b+r[nx]+1);
for(int i=nx+1;i<ny;i++)
lz[i]+=k;
}
int query(int x,int y,int k)
{
int res=0,nx=id[x],ny=id[y];
if(nx==ny)
{
for(int i=x;i<=y;i++)
if(a[i]+lz[nx]>=k)
res++;
return res;
}
for(int i=x;i<=r[nx];i++)
if(a[i]+lz[nx]>=k)
res++;
for(int i=l[ny];i<=y;i++)
if(a[i]+lz[ny]>=k)
res++;
for(int i=nx+1;i<ny;i++)
res+=ef(l[i],r[i],k-lz[i]);
return res;
}
int main()
{
n=read(),q=read();
len=sqrt(n);
for(int i=1;i<=n;i++)
{
a[i]=read();
b[i]=a[i];
}
for(int i=1;i<=len;i++)
l[i]=(i-1)*len+1,r[i]=i*len;
if(r[len]!=n)
l[len+1]=r[len]+1,r[len+1]=n,len++;
for(int i=1;i<=len;i++)
{
for(int j=l[i];j<=r[i];j++)
id[j]=i;
sort(b+l[i],b+r[i]+1);
}
while(q--)
{
char op;
rd(op);
int x=read(),y=read(),k=read();
if(op=='M')
upd(x,y,k);
else
printf("%d\n",query(x,y,k));
}
return 0;
}
by Loser_Syx @ 2024-05-06 21:15:02
我靠你这个分块写的太对了。
by UnfortunatelyDead @ 2024-05-06 21:25:27
@Loser_Syx 小丑菜就多练,哈哈
@qzmoot 看看你的 b 数组多大。
by qzmoot @ 2024-05-06 22:03:30
@Loser_Syx md,这里不二分你写几把呢
by qzmoot @ 2024-05-06 22:03:55
@UnforgettableDream b数组没问题啊?
by qzmoot @ 2024-05-06 22:07:00
@UnforgettableDream 我是小丑?
by UnfortunatelyDead @ 2024-05-07 05:57:46
@qzmoot b[SN]
你 b 实际要是 b[N]