QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#614875#7904. Rainbow Subarraywzxtsl#WA 1ms5696kbC++231.6kb2024-10-05 17:04:352024-10-05 17:04:36

Judging History

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

  • [2024-10-05 17:04:36]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5696kb
  • [2024-10-05 17:04:35]
  • 提交

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'