QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#307877#8016. 不休陀螺ftt_fan_clubCompile Error//C++142.2kb2024-01-19 10:54:252024-01-19 10:54:25

Judging History

你现在查看的是最新测评结果

  • [2024-01-19 10:54:25]
  • 评测
  • [2024-01-19 10:54:25]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=1e6+7,inf=1e9+7;
int n,E,a[N],b[N],c[N];
ll sum[N],u[N];
int maxn[N][20],lg[N];
struct qry{
    int r,vl;
}f[2][N];
int tot=0;
int fi(ll x){
    int l=1,r=n+1;
    while(l<=r){
        int mid=(l+r)>>1;
        if(sum[mid]==x)
            return mid;
        if(sum[mid]<x)l=mid+1;
        else r=mid-1;
    }
}bool cmp(qry x,qry y){return x.r<y.r;}
void add(int ps){
    for(;ps<=n+1;ps+=ps&(-ps))
        c[ps]++;
    return;
}int qryy(int ps){
    int x=0;
    for(;ps;ps-=ps&(-ps))
        x+=c[ps];
    return x;
}int qry_maxn(int l,int r){
    int op=lg[r-l+1];
    return max(maxn[l][op],maxn[r-(1<<op)+1][op]);
}bool check(int l,int r){return sum[r]-sum[l-1]+qry_maxn(l,r)<=E;}
signed main(){
    freopen("top.in","r",stdin);
    freopen("top.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);cin>>n>>E;
    for(int i=2;i<=n;i++)
        lg[i]=lg[i/2]+1;
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=1;i<=n;i++)cin>>b[i];
    for(int i=1;i<=n;i++){
        u[i]=u[i-1]+a[i]-b[i];
        sum[i]=sum[i-1]+max(0,a[i]-b[i]);
        maxn[i][0]=min(a[i],b[i]);
    }for(int i=1;i<=19;i++)
        for(int j=1;j<=n;j++)
            if(j+(1<<(i-1))<=n)
            maxn[j][i]=max(maxn[j][i-1],maxn[j+(1<<(i-1))][i-1]);
    for(int i=1;i<=n;i++){
        int l=i,r=n,s=i-1;
        while(l<=r){
            int mid=(l+r)>>1;
            if(check(i,mid)){
                l=mid+1;
                s=mid;
            }else r=mid-1;
        }if(s>=i){
            tot++;
            f[0][tot].r=i-1;
            f[1][tot].r=s;
            f[0][tot].vl=f[1][tot].vl=u[i-1];
        }
    }/*for(int i=1;i<=n;i++)
        sum[i]=u[i];
    sum[n+1]=0;
    sort(sum+1,sum+n+2);
    for(int i=1;i<=n;i++)
        u[i]=fi(u[i]);
    ll ans=0;
    for(int h=0;h<=1;h++){
        memset(c,0,sizeof(c));
        int nw,rr=0;
        if(h==0)nw=-1;
        else nw=1;
        sort(f[h]+1,f[h]+tot+1,cmp);
        for(int i=1;i<=tot;i++){
            while(rr<f[h][i].r){
                rr++;
                add(u[rr]);
            }ans+=nw*qryy(fi(f[h][i].vl));
        }
    }*/cout<<ans<<"\n";
    return 0;
}

詳細信息

answer.code: In function ‘int main()’:
answer.code:85:14: error: ‘ans’ was not declared in this scope; did you mean ‘abs’?
   85 |     }*/cout<<ans<<"\n";
      |              ^~~
      |              abs
answer.code: In function ‘int fi(long long int)’:
answer.code:21:1: warning: control reaches end of non-void function [-Wreturn-type]
   21 | }bool cmp(qry x,qry y){return x.r<y.r;}
      | ^
answer.code: In function ‘int main()’:
answer.code:36:12: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   36 |     freopen("top.in","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~
answer.code:37:12: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   37 |     freopen("top.out","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~