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 UnfortunatelyDead @ 2024-05-06 20:39:48
几把宇别卷了,我要疯了。
by Loser_Syx @ 2024-05-06 20:40:29
几把宇别卷了,我要疯了。
by Loser_Syx @ 2024-05-06 20:41:38
long long 没开吧
by qzmoot @ 2024-05-06 20:41:55
可恶,第二个sort中写了个nx,但是改完后还是60pts
by qzmoot @ 2024-05-06 20:42:41
@UnforgettableDream syx你小号是吧
by qzmoot @ 2024-05-06 20:43:10
@Loser_Syx md也不帮我看看:(
by qzmoot @ 2024-05-06 20:44:17
@Loser_Syx 决定不用(自信
by qzmoot @ 2024-05-06 20:45:50
@Loser_Syx 开了也挂了
by UnfortunatelyDead @ 2024-05-06 20:46:10
@qzmoot 诶,还真不是syx
by Loser_Syx @ 2024-05-06 20:48:13
不是你在二分什么啊,分块你这么写我第一次见啊