QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#614875 | #7904. Rainbow Subarray | wzxtsl# | WA | 1ms | 5696kb | C++23 | 1.6kb | 2024-10-05 17:04:35 | 2024-10-05 17:04:36 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define int long long
int n,m;
const int N=2e6+7;
int a[N];
int b[N];
int ch(int x){
int i=1,j=1,ans=0,ma1=0,sum=0,ma2=0;
for(int i=1;i<=n;i++){
b[i]=a[i]+x;
}
while(j<=n&&i<=j){
if(i==j&&abs(b[i])>m){
i++;
j++;
ans=0;
}else if(sum+abs(b[j])<=m){
ans++;
ma1=max(ma1,ans);
sum+=abs(b[j]);
j++;
}else{
sum-=abs(b[i]);
ans--;
i++;
}
//cout<<i<<"!"<<j<<endl;
}
for(int i=1;i<=n;i++){
b[i]=a[i]-x;
}
while(j<=n&&i<=j){
if(i==j&&abs(b[i])>m){
i++;
j++;
ans=0;
}else if(sum+abs(b[j])<=m){
ans++;
ma2=max(ma2,ans);
sum+=abs(b[j]);
j++;
}else{
sum-=abs(b[i]);
ans--;
i++;
}
//cout<<i<<"!"<<j<<endl;
}
return max(ma1,ma2);
}
void solve(){
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>a[i];
a[i]=a[i]-i;
}
int l=0,r=1e14;
int ans=0;
while(l<=r){
int mid=(l+r)>>1;
if(ch(mid)>ans){
ans=ch(mid);
r=mid-1;
}else{
l=mid+1;
}
}
cout<<ans<<endl;
}
signed main(){
fast;
int t=1;
cin>>t;
while(t--){
solve();
}
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5696kb
input:
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
output:
0 0 0 0 0
result:
wrong answer 1st lines differ - expected: '4', found: '0'