萌新求助,测试点本机AC,提交RE,求解

P2801 教主的魔法

xiaolou @ 2019-06-10 18:54:04

数据:

10 9
719 583 321 556 741 430 50 28 326 804
A 1 10 321
M 1 10 101
A 1 10 337
A 1 10 596
M 1 10 511
A 1 10 142
A 1 10 99
A 1 10 88
M 1 10 609
8
8
5
10
10
10

代码:

#include <bits/stdc++.h>

using namespace std;
int n,m;
int a[1000005];
int l[10005],r[10005];
int w[1000005];
int b[1000005];
int f[10005];
void Query(int x,int y,int z)
{
    int zz=z;
    int res=0;
    for(int i=x;i<=y;++i)
    {
        zz=z-f[i];
        f[i]=0;
        sort(b+l[i],b+r[i]+1);
        int ll=l[i],rr=r[i];
        while(ll!=rr)
        {
            int mid=(ll+rr)/2;
            if(b[mid]>=z)
            {
                rr=mid-1;
            }
            else
            {
                ll=mid+1;
            }
        }
        res+=r[i]-rr+1;
    }   
    printf("%d\n",res);
}

int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;++i)
    {
        scanf("%d",&a[i]);
        b[i]=a[i];
    }
    int len=sqrt(n);
    int cnt=0;
    r[0]=0;
    int now=1;
    while(n-now>=len)
    {
        l[++cnt]=r[cnt-1]+1;
        now+=len;
        r[cnt]=now;
    }
    r[cnt]=n;
    char op;
    int x,y,z;
    while(m--)
    {
        while(scanf("%c",&op))
        {
            if(op!='\n')
            {
                break;
            }
        }
        scanf("%d%d%d",&x,&y,&z);
//      cout << "s" <<endl;
        if(op=='M')
        {
            if(w[y]-w[x]<=1)
            {
                for(int i=x;i<=y;++i)
                {
                    a[i]+=z;
                    b[i]=a[i];
                }
            }
            else
            {
                for(int i=x;i<=r[w[x]];++i)
                {
                    a[i]+=z;
                    b[i]=a[i];
                }
                for(int i=l[w[y]];i<=y;++i)
                {
                    a[i]+=z;
                    b[i]=a[i];
                }
                for(int i=w[x]+1;i<=w[y]-1;++i)
                {
                    f[i]+=z;
                }
            }
        }
        else
        {
            int ans=0;
            if(w[y]-w[x]<=1)
            {
                for(int i=x;i<=y;++i)
                {
                    if(a[i]>=z)
                    {
                        ans++;
                    }
                }
                printf("%d\n",ans);
            }
            else
            {
                for(int i=x;i<=r[w[x]];++i)
                {
                    if(a[i]>=z)
                    {
                        ans++;
                    }
                }
                for(int i=l[w[y]];i<=y;++i)
                {
                    if(a[i]>z)
                    {
                        ans++;
                    }
                }
                Query(w[x]+1,w[y]-1,z);
            }
        }
    }
    return 0;
}

by xiaolou @ 2019-06-10 18:54:29

我tm的好自闭啊


by 幻之陨梦 @ 2019-06-10 18:57:40

@xiaolou 不要说脏字


by xiaolou @ 2019-06-10 18:59:05

震惊!改成cin就A了


by xiaolou @ 2019-06-10 18:59:14

此贴完结


by EPSILONCXL @ 2019-06-10 21:44:52

代码里面尽量还是不要用

scanf("%c",&c);

这样的语句吧。应该是换行符的问题。可以用

char s[5];
scanf("%s",s);
c=s[0];

来解决。

本蒟蒻被坑过很多次的经验


|