QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#299866#7897. Largest Digitucup-team870#WA 2ms11732kbC++142.0kb2024-01-07 12:39:232024-01-07 12:39:23

Judging History

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

  • [2024-01-07 12:39:23]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:11732kb
  • [2024-01-07 12:39:23]
  • 提交

answer

#include <bits/stdc++.h>
#define rep(i,l,r) for(int i=l; i<=r; i++)
#define per(i,r,l) for(int i=r; i>=l; i--)
#define IOS {cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);}
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define ilr int i,int l,int r
#define li i<<1
#define ls li,l,mid
#define ri i<<1|1
#define rs ri,mid+1,r
#define mi int mid=(l+r)/2;
#define pil pair<int,ll>
const int N=5e5+5;
int a[N],mp[N];
P q[N];
int s0[N<<2]; ll s1[N<<2];
void add(ilr,int x,int v){
    if(l==r){
        s0[i]+=v; s1[i]=s0[i]*mp[x]; return;
    }
    mi
    if(mid>=x)add(ls,x,v);
    else add(rs,x,v);
    s0[i]=s0[li]+s0[ri]; s1[i]=s1[li]+s1[ri];
}
int kth(ilr,int k){
    // cout<<l<<" "<<r<<" "<<k<<endl;
    if(l==r){
        assert(k==1 && s0[i]==1); return l;
    }
    mi
    if(s0[li]>=k)return kth(ls,k);
    return kth(rs,k-s0[li]);
}
pil qu(ilr,int x,int y){
    if(l>=x && r<=y)return {s0[i],s1[i]};
    mi pil res={0,0};
    if(mid>=x)res=qu(ls,x,y);
    if(y>mid){
        auto [s0,s1]=qu(rs,x,y);
        res.first+=s0; res.second+=s1;
    }
    return res;
}
void slv(){
    int n; ll K; cin>>n>>K;
    rep(i,0,n*4)s0[i]=s1[i]=0;
    rep(i,1,n)cin>>a[i],a[i]-=i,q[i]={a[i],i};
    // rep(i,1,n)cout<<a[i]<<" "; cout<<endl;
    sort(q+1,q+n+1);
    rep(i,1,n){
        auto [v,id]=q[i];
        mp[i]=v; a[id]=i;
    }
    auto ck=[&](int len){
        int k=(len+1)/2;
        int kx=kth(1,1,n,k);
        auto [s00,s01]=qu(1,1,n,1,kx);
        auto [s10,s11]=qu(1,1,n,kx,n);
        ll res=s00*mp[kx]-s01 + s11-s10*mp[kx];
        return res<=K;
    };
    int l=1,ans=1;
    rep(r,1,n){
        // cout<<a[r]<<"ega"<<endl;
        add(1,1,n,a[r],1);
        while(!ck(r-l+1))add(1,1,n,a[l++],-1);
        ans=max(ans,r-l+1);
    }
    cout<<ans<<"\n";
}
int main() {
    IOS
    int T;cin>>T;
    while(T--)slv();
    return 0;
}
/*
5
7 5
7 2 5 5 4 11 7
6 0
100 3 4 5 99 100
5 6
1 1 1 1 1
5 50
100 200 300 400 500
1 100
3
*/

详细

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 11732kb

input:

2
178 182 83 85
2 5 3 6

output:

27
19

result:

wrong answer 1st lines differ - expected: '7', found: '27'