蒟蒻求助QAQ

P2801 教主的魔法

缥缈的鸿影 @ 2019-02-28 00:21:31

rt,我实在是太弱了QAQ 40分,其他全WA,写的是最基础的分块QAQ

#include<stdio.h>
#include<cctype>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std;
typedef unsigned long long ull;
typedef unsigned long int ul;
typedef long long ll;
char buf[1<<21],*p1=buf,*p2=buf;
inline int getch()
{
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;
}
char buf2[1<<21],pr[20];
int p,p3=-1;
inline void flush()
{
    fwrite(buf2,1,p3+1,stdout),p3=-1;
}
inline void print(int x)
{
    if(p3>1<<20) flush();
    do{pr[++p]=x%10+48;}while(x/=10);
    do{buf2[++p3]=pr[p];}while(--p);
    buf2[++p3]=' ';
}
template <class code>inline code read(const code &a)
{
    code x=0;short w=0;char ch=getchar();
    while(!isdigit(ch)) {w|=ch=='-';ch=getchar();}
    while(isdigit(ch)) {x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
    return w?-x:x;
}
const int N=1000000;
ll a[N+5];
int block;
int tag[1000+5];
int belong[N+5];
int l[1000+5];
int tot[1000+5];
int r[1000+5];
int num;
ll value[1000+5][1000+5];
inline void reinit(int now)
{
    int tot=0;
    for(register int i=l[now];i<=r[now];++i)
    {
        value[now][++tot]=a[i];
    }
    sort(value[now]+1,value[now]+r[now]-l[now]+1+1);
}
int main ()
{
    freopen("testdata.in","r",stdin);
//  freopen("blocking2.out","w",stdout);
    register int n,m;
//  scanf("%d",&n);
    n=read(n),m=read(m);
    block=sqrt(n);
    num=(n-1)/block+1;
    for(register int i=1;i<=n;i++)
    {
        a[i]=read(a[i]);
        belong[i]=(i-1)/block+1;
    }
    for(register int i=1;i<=num;i++)
    {
        l[i]=r[i-1]+1;
        r[i]=l[i]+block-1;
        tot[i]=r[i]-l[i]+1;
    }
    r[num]=n;
    tot[num]=r[num]-l[num]+1;
    for(register int i=1;i<=num;i++)
    {
        int tot=0;
        for(int j=l[i];j<=r[i];j++)
        {
            value[i][++tot]=a[j];
        }
    }
    while(m--)
    {
        char fir[6];
        char f;
        int left,right,c;
        scanf("%s %d %d %d",fir,&left,&right,&c);
        f=fir[0];
        if(f=='M')
        {
            for(register int i=left;i<=min(r[belong[left]],right);++i)
            {
                a[i]+=c;
            }
            reinit(belong[left]);
            if(belong[left]!=belong[right])
            {
                for(register int i=l[belong[right]];i<=right;++i)
                {
                    a[i]+=c;
                }
                reinit(belong[right]);
            }
            for(register int i=belong[left]+1;i<=belong[right]-1;++i)
            {
                tag[i]+=c;
            }
        }
        else
        {
            int ans=0;
            for(register int i=left;i<=min(r[belong[left]],right);++i)
            {
                if(a[i]+tag[belong[i]]>=c) ++ans;
            }
            if(belong[left]!=belong[right])
            {
                for(register int i=l[belong[right]];i<=right;++i)
                {
                    if(a[i]+tag[belong[i]]>=c) ++ans;
                }
            }
            for(register int i=belong[left]+1;i<=belong[right]-1;++i)
            {
                ans+=value[i]+r[i]-l[i]+1-lower_bound(value[i]+1,value[i]+tot[i]+1,c-tag[i])+1;
            }
            printf("%d\n",ans);
        }
    }
    return 0;
}

by 缥缈的鸿影 @ 2019-02-28 00:22:02

@Irressey @Rem°


by Rbu_nas @ 2019-02-28 00:23:32

@爱吃肉的瓶子 妈耶该碎觉了qaq... 中午来膜一发


by 缥缈的鸿影 @ 2019-02-28 00:25:19

@Rem° QAQ晚安巨佬


by 花里心爱 @ 2019-02-28 12:23:35

@爱吃肉的瓶子 Orz甘地

另外我最近碰不了电脑qwqwq


|