跳到正文

题解

题解:AT_abc032_c [ABC032C] 列

New_Void约 2 分钟
原文
文章信息与版本

文章信息

发布
2025年9月2日
收录
2025年12月12日
更新
2026年11月21日
篇幅
约 2 分钟

版本

  1. v1当前

AT_abc032_c [ABC032C] 列

思路

首先题目给出的是连续的子序列,所以可以直接用双指针进行维护,定义一个变量,如果这个变量乘上 ar≤ka_r \leq k 那么指针的右端点就往右移就可以了,最后窗口的变量要除以掉 ala_l 进行滑动指针。要特判一下其中一个 aia_i 是零的情况,直接输出 nn 就可以了。

Code

C++
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e5+5;
int a[N],ans;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    int n,k;cin>>n>>k;
    for (int i=1;i<=n;i++){
        cin>>a[i];
        if (a[i]==0){
            cout<<n<<endl;
            return 0;
        }
    }
    int l=1,r=0;
    int res=1;
    while (l<n){
        while (r<n && res*a[r+1]<=k) r++,res*=a[r];
        ans=max(ans,r-l+1);
        if (l<=r) res/=a[l];
        l++;
    }
    cout<<ans<<endl;
    return 0;
}

通过记录:https://atcoder.jp/contests/abc032/submissions/68990116

原文
存档评论2 条抓取于