hello_world_djh @ 2022-07-13 09:29:39
第八个点TLE了,运行时间1.20s
#include<bits/stdc++.h>
#define L(i) block[id[i]].l
#define R(i) block[id[i]].r
#define TG(i) block[id[i]].tg
using namespace std;
typedef long long ll;
const int MAXN=1e6+10;
ll a[MAXN];
int n,q,size,id[MAXN];
struct Deblock{
int l,r;
ll tg;
Deblock(int _l=0,int _r=0,ll _tg=0)
{
l=_l;r=_r;tg=_tg;
return;
}
}block[1010];
void update(int l,int r,ll x)
{
if(l==r)
{
a[l]+=x;
return;
}
for(int i=l;i<=R(l);i++)
a[i]+=x;
for(int i=L(r);i<=r;i++)
a[i]+=x;
for(int i=id[l]+1;i<id[r];i++)
block[i].tg+=x;
return;
}
int query(int l,int r,int c)
{
if(id[l]==id[r])
{
int ans=0;
for(int i=l;i<=r;i++)
if(a[i]>=c-TG(i))
ans++;
return ans;
}
int ans=0;
for(int i=l;i<=R(l);i++)
if(a[i]+TG(i)>=c)
ans++;
for(int i=L(r);i<=r;i++)
if(a[i]+TG(i)>=c)
ans++;
for(int i=id[l]+1;i<id[r];i++)
{
int b[1010];
for(int j=block[i].l;j<=block[i].r;j++)
b[j-block[i].l+1]=a[j];
sort(b+1,b+block[i].r-block[i].l+2);
ans+=block[i].r-block[i].l+2-(lower_bound(b+1,b+block[i].r-block[i].l+2,c-block[i].tg)-b);
}
return ans;
}
int main()
{
scanf("%d%d",&n,&q);
size=sqrt((n*2/5+4)*8/7*3/5)/10;
for(int i=1;i<=n;i++)
{
scanf("%lld",a+i);
id[i]=i/n;
if(i==1)
L(i)=i;
else if(id[i-1]!=id[i])
R(i-1)=i-1,
L(i)=i;
else if(i==n)
R(i)=i;
}
for(int i=1;i<=q;i++)
{
char ch=getchar();
while(ch!='M' && ch!='A')ch=getchar();
int l,r,x;
scanf("%d%d%d",&l,&r,&x);
if(ch=='M')
{
update(l,r,x);
}
else
{
printf("%d\n",query(l,r,x));
}
}
return 0;
}
by __Seniorious__ @ 2022-07-13 09:33:52
别开long long 试下?
by __Seniorious__ @ 2022-07-13 09:35:00
呃……还是会T
by __Seniorious__ @ 2022-07-13 09:40:35
@hello_world_djh
sort(b+1,b+block[i].r-block[i].l+2);
您的复杂度带一个log
by __Seniorious__ @ 2022-07-13 09:42:45
嘶——就是要带个log,对不起看错了
by chlchl @ 2022-07-13 09:45:11
常数问题???
by __Seniorious__ @ 2022-07-13 09:46:43
不过每块每次查询排序的话,查询的复杂度是
by __Seniorious__ @ 2022-07-13 09:48:02
应该是每块块内排好序,修改时两侧散块重新排序,查询时直接二分,这样的复杂度是
by hello_world_djh @ 2022-07-13 10:47:58
好的,thank you