QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#275693 | #7904. Rainbow Subarray | Qingyu | Compile Error | / | / | C++23 | 2.0kb | 2023-12-04 23:15:32 | 2023-12-04 23:15:33 |
Judging History
你现在查看的是最新测评结果
- [2024-06-09 00:00:26]
- hack成功,自动添加数据
- (/hack/652)
- [2023-12-04 23:15:33]
- 评测
- 测评结果:Compile Error
- 用时:0ms
- 内存:0kb
- [2023-12-04 23:15:32]
- 提交
answer
#include<bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define pre(i,a,n) for(int i=n;i>=a;i--)
#define ls(x) lson[(x)]
#define rs(x) rson[(x)]
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
using ll=long long;
#define N int(5e5+10)
int rt,a[N],lson[N<<2],rson[N<<2],sz[N<<2],cnt;
ll sum[N<<2],b[N];
int build(int cl,int cr)
{
int n1=cnt++;
if(cl<cr)
{
int mid=(cl+cr)>>1;
ls(n1)=build(cl,mid);
rs(n1)=build(mid+1,cr);
}
return n1;
}
void modify(int n1,int cl,int cr,int pos,int x)
{
if(cl==cr)
{
sz[n1]+=x,sum[n1]+=1ll*x*b[cl];
return;
}
int mid=(cl+cr)>>1;
if(pos<=mid) modify(ls(n1),cl,mid,pos,x);
else modify(rs(n1),mid+1,cr,pos,x);
sz[n1]=sz[ls(n1)]+sz[rs(n1)];
sum[n1]=sum[ls(n1)]+sum[rs(n1)];
}
ll que(int n1,int cl,int cr,int ki,int tp)
{
if(cl==cr) return (tp?(1ll*ki*b[cl]):b[cl]);
int mid=(cl+cr)>>1;
if(sz[ls(n1)]>=ki) return que(ls(n1),cl,mid,ki,tp);
else return (tp?sum[ls(n1)]:0)+que(rs(n1),mid+1,cr,ki-sz[ls(n1)],tp);
}
int n;ll k;
void solve()
{
cin>>n>>k;
rep(i,1,n) cin>>a[i],a[i]-=i,b[i]=a[i];
sort(b+1,b+n+1,[&](ll x,ll y){return x<y;});
int tot=unique(b+1,b+n+1)-b-1;
rep(i,1,n) a[i]=lower_bound(b+1,b+tot+1,a[i])-b;
rt=build(1,tot);
int ans=1,p=1;
rep(i,1,n)
{
while(p<=n)
{
modify(rt,1,tot,a[p],1);
int ki=(p-i+1)>>1;
ll v1=que(rt,1,tot,ki,1);
ll v2=que(rt,1,tot,p-i+1,1)-v1;
if((p-i+1)%2==0)
{
if(v2-v1<=k)
ans=max(ans,p-i+1),p++;
else
{
modify(rt,1,tot,a[p],-1);
break;
}
}
else
{
ll v3=que(rt,1,tot,ki+1,0);
if(v2-v1-v3<=k)
ans=max(ans,p-i+1),p++;
else
{
modify(rt,1,tot,a[p],-1);
break;
}
}
}
modify(rt,1,tot,a[i],-1);
if(p>n) {ans=max(ans,n-i+1); break;}
}
cout<<ans<<"\n";
}
int main()
{
IOS
int t=1;cin>>t;
while(t--) solve();
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
*/
Details
answer.code:44:11: error: expected initializer before ‘k’ 44 | int n;ll k; | ^ answer.code: In function ‘void solve()’: answer.code:47:14: error: ‘n’ was not declared in this scope; did you mean ‘yn’? 47 | cin>>n>>k; | ^ | yn answer.code:47:17: error: ‘k’ was not declared in this scope 47 | cin>>n>>k; | ^