arrow_king @ 2024-07-05 16:26:38
RT. 我在正常分块的过程中令
而下面这个数据就可以卡掉:
4 1
2 1 3 4
A 2 3 2
应当输出
建议增加 hack 数据。
错误代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
#define ll long long
#define il inline
#define N 1000005
#define sqr 1005
il ll read() {
ll x=0,f=1;char c=getchar();
while(c<'0'||c>'9') {if(c=='-') {f=-1;} c=getchar();}
while(c>='0'&&c<='9') {x=(x<<3)+(x<<1)+(c^48);c=getchar();}
return x*f;
}
int n,q,sq,a[N],b[N],tag[sqr];
int st[sqr],ed[sqr],belong[N];
il void add(int l,int r,int v) {
int bl=belong[l],br=belong[r];
if(bl==br) {
for(int i=l;i<=r;i++) b[i]+=v;
sort(b+st[bl],b+ed[bl]+1);
return;
}
for(int i=l;i<=ed[bl];i++) b[i]+=v;
for(int i=st[br];i<=r;i++) b[i]+=v;
sort(b+st[bl],b+ed[bl]+1);
sort(b+st[br],b+ed[br]+1);
for(int i=bl+1;i<br;i++) tag[i]+=v;
}
il int query(int l,int r,int v) {
int bl=belong[l],br=belong[r],ans=0;
if(bl==br) {
for(int i=l;i<=r;i++) if(v<=tag[bl]+b[i]) ans++;
return ans;
}
for(int i=l;i<=ed[bl];i++) if(v<=tag[bl]+b[i]) ans++;
for(int i=st[br];i<=r;i++) if(v<=tag[br]+b[i]) ans++;
for(int i=bl+1;i<br;i++) {
int nl=st[i],nr=ed[i],best=nr;
while(nl<=nr) {
int mid=(nl+nr)>>1;
if(v<=tag[i]+b[mid]) best=mid,nr=mid-1;
else nl=mid+1;
}
ans+=ed[i]-best+1;
}
return ans;
}
int main() {
n=read(),q=read(),sq=sqrt(n);
for(int i=1;i<=n;i++) a[i]=read();
for(int i=1;i<=sq;i++) st[i]=ed[i-1]+1,ed[i]=(n/sq)*i;
ed[sq]=n;
for(int i=1;i<=sq;i++) {
for(int j=st[i];j<=ed[i];j++) {
b[j]=a[j],belong[j]=i;
}
sort(b+st[i],b+ed[i]+1);
}
while(q--) {
char opt;scanf("%s",&opt);
int l=read(),r=read(),c=read();
switch(opt) {
case 'M':{
add(l,r,c);
break;
}
case 'A':{
printf("%d\n",query(l,r,c));
break;
}
}
}
return 0;
}
by arrow_king @ 2024-07-05 16:27:20
我应该at谁。
by arrow_king @ 2024-07-05 16:28:23
@chen_zhe
by return_TLE @ 2024-07-05 16:31:28
@10circle
by arrow_king @ 2024-07-05 16:33:30
@一扶苏一
by arrow_king @ 2024-07-05 16:40:13
@离散小波变换° @览遍千秋
by ZHZ0810 @ 2024-07-05 16:50:26
我也遇到过......
by lin_er @ 2024-07-07 10:56:03
+1
by mkx2023275 @ 2024-07-26 20:13:19
+1
by OrinLoong @ 2024-08-29 20:45:14
+1