玄学错误 求助大佬

P2801 教主的魔法

GMSD @ 2019-10-09 14:19:13

自己下载第一个数据,自测是对的,但是提交上去是错的

#include<bits/stdc++.h>
using namespace std;
#define cg ch=getchar()
#define int long long

const int _=3000002;
int number,magic,high[_],tot,pos[_],num[_],L[_],R[_],laze[_];

int read(){
    int s=0,w=1;char cg;
    while(ch<'0'||ch>'9')w=(ch=='-')?-1:1,cg;
    while(ch>='0'&&ch<='9')s=s*10+ch-'0',cg;
    return s*w;
}

void Build(){
    tot=sqrt(number);
    for(int i=1;i<=tot;i++)L[i]=(i-1)*tot+1,R[i]=i*tot;
    if(R[tot]<number)L[++tot]=R[tot-1]+1,R[tot]=number;
    for(int i=1;i<=tot;i++)
       for(int j=L[i];j<=R[i];j++)
          pos[j]=i;
    for(int i=1;i<=tot;i++)
       sort(num+L[i],num+R[i]+1);
}

void change(int x,int y,int z){
    if(pos[x]==pos[y]){
        for(int i=x;i<=y;i++)high[i]+=z;
        for(int i=L[pos[x]];i<=R[pos[x]];i++)num[i]=high[i];
        sort(num+L[pos[x]],num+R[pos[x]]+1);
    }
    else{
        for(int i=x;i<=R[pos[x]];i++)high[i]+=z;
        for(int i=L[pos[x]];i<=R[pos[x]];i++)num[i]=high[i];
        sort(num+L[pos[x]],num+R[pos[x]]+1);
        for(int i=L[pos[y]];i<=y;i++)high[i]+=z;
        for(int i=L[pos[y]];i<=R[pos[y]];i++)num[i]=high[i];
        sort(num+L[pos[y]],num+R[pos[y]]+1);
        for(int i=pos[x]+1;i<=pos[y]-1;i++)laze[i]+=z;
    }
}

void find(int x,int y,int z){
    int ans=0;
    if(pos[x]==pos[y]){
        for(int i=x;i<=y;i++)
           if(high[i]+laze[pos[i]]>=z)ans++;
    }
    else{
        for(int i=x;i<=R[pos[x]];i++)
           if(high[i]+laze[pos[i]]>=z)ans++;
        for(int i=L[pos[y]];i<=y;i++)
           if(high[i]+laze[pos[i]]>=z)ans++;
        for(int i=pos[x]+1;i<=pos[y]-1;i++){
            int l=L[i],r=R[i],now=0;
            while(l<=r){
                int mid=(l+r)>>1;
                if(num[mid]+laze[i]>=z)r=mid-1,now=R[i]-mid+1;
                else l=mid+1;
            }
            ans+=now;
        }
    }
    cout<<ans<<endl;
}

signed main(){
    number=read();magic=read();
    for(int i=1;i<=number;i++)high[i]=read(),num[i]=high[i];
    Build();
    for(int i=1;i<=magic;i++){
        char flag;cin>>flag;
        int x=read(),y=read(),z=read();
        if(flag=='A')find(x,y,z);
        else change(x,y,z);
    }
    return 0;
}

/*
in:
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

out:
8
8
5
10
10
10
*/

by JT_kk @ 2019-10-09 14:22:44

盲猜读入字符问题


|