0pts简短分块WA求调

P2801 教主的魔法

Gumbo @ 2022-09-26 20:23:19

RT,这里是记录。记录

为防止有大佬不屑于A这个题,这里是代码:

#include<bits/stdc++.h>
using namespace std;
#define belong(x) ((x-1)/sqrtn+1)
#define begin(x) ((x-1)*sqrtn+1)
#define end(x) ((x)*sqrtn)
int ori[1002000],sot[1002000];
int add[2000];
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    int sqrtn=sqrt(n);
    int i;
    for(i=1;i<=n;++i)scanf("%d",ori+i),sot[i]=ori[i];
    for(i=1;begin(i)<=n;++i)sort(sot+begin(i),sot+end(i)+1);
    int l,r,w,ans;
    unsigned char opt;
    while(m--){
        do{opt=getchar();}while(opt!=77&&opt!=65);
        scanf("%d%d%d",&l,&r,&w);
        if(opt==77){
            if(belong(l)==belong(r)){
                for(i=begin(belong(l));i<=end(belong(l));++i)ori[i]+=add[belong(l)];
                add[belong(l)]=0;
                for(i=l;i<=r;++i)ori[i]+=w;
                for(i=begin(belong(l));i<=end(belong(l));++i)sot[i]=ori[i];
                sort(sot+begin(belong(l)),sot+end(belong(l))+1);
            }
            else{
                for(i=begin(belong(l));i<=end(belong(l));++i)ori[i]+=add[belong(l)];
                for(i=begin(belong(r));i<=end(belong(r));++i)ori[i]+=add[belong(r)];
                add[belong(l)]=0;
                add[belong(r)]=0;
                for(i=l;i<=end(belong(l));++i)ori[i]+=w;
                for(i=begin(belong(r));i<=r;++i)ori[i]+=w;
                for(i=belong(l)+1;i<belong(r);++i)add[i]+=w;
                for(i=begin(belong(l));i<=end(belong(l));++i)sot[i]=ori[i];
                for(i=begin(belong(r));i<=end(belong(r));++i)sot[i]=ori[i];
                sort(sot+begin(belong(l)),sot+end(belong(l))+1);
                sort(sot+begin(belong(r)),sot+end(belong(r))+1);
            }
        }
        else{
            ans=0;
            if(belong(l)==belong(r)){
                for(i=begin(belong(l));i<=end(belong(l));++i)ori[i]+=add[belong(l)];
                add[belong(l)]=0;
                for(i=l;i<=r;++i)if(ori[i]<=w)++ans;
            }
            else{
                for(i=begin(belong(l));i<=end(belong(l));++i)ori[i]+=add[belong(l)];
                for(i=begin(belong(r));i<=end(belong(r));++i)ori[i]+=add[belong(r)];
                add[belong(l)]=0;
                add[belong(r)]=0;
                for(i=l;i<=end(belong(l));++i)if(ori[i]<=w)++ans;
                for(i=begin(belong(r));i<=r;++i)if(ori[i]<=w)++ans;
                for(i=belong(l)+1;i<belong(r);++i)ans+=sot+end(i)+1-upper_bound(sot+begin(i),sot+end(i)+1,w-add[i]);
                for(i=begin(belong(l));i<=end(belong(l));++i)sot[i]=ori[i];
                for(i=begin(belong(r));i<=end(belong(r));++i)sot[i]=ori[i];
                sort(sot+begin(belong(l)),sot+end(belong(l))+1);
                sort(sot+begin(belong(r)),sot+end(belong(r))+1);
            }
            cout<<ans<<'\n';
        }
    }
    return 0;
}

不知为啥,hack数据过了。


by Gumbo @ 2022-09-26 20:26:19

其实66行不算长的,但是luogu换行有点难受


by Gumbo @ 2022-09-26 20:31:57

抱歉,脑残了,><打错了。

此帖结,警钟长鸣(L54、L55)

不过能过hack数据是真离谱


|