5 条题解

  • 2
    @ 2025-11-6 8:46:21

    暴力

    以每个点为整除的那个数,向两边延伸,复杂度n方

    正解

    考虑优化暴力。注意到:一个数向左向右延伸到的数,一定是大于等于它的。所以被延伸到的数一定不会再作为整除的那个数(起码不会更新答案)。所以从一个数开始延伸,下次从延伸到的r+1开始暴力就可以。

    code

    bool M1;
    #include <bits/stdc++.h>
    using namespace std;
    #define ll long long
    #define look_memory cerr<<abs(&M1-&M2)/1024.0/1024<<"MB\n"
    
    namespace syr
    {
    	const ll N = 3e5+10;
    	ll n, ans;
    	ll a[N];
    	set <ll> w;
    	ll check (ll i) {
    		ll l=i, r=i;
    		while (l>=1 && a[l]%a[i]==0) l--;
    		while (r<=n && a[r]%a[i]==0) r++;
    		l++, r--;
    		ll len = r-l+1;
    		if (ans==len) w.insert(l);
    		else if (ans<len) {
    			ans = len;
    			w.clear();
    			w.insert(l);
    		}
    		return r+1;
    	}
    	void work()
    	{
    		cin>>n;
    		for (ll i=1; i<=n; i++) cin>>a[i];
    		ll x = 1;
    		while (x<=n) x = check(x);
    		cout<<w.size()<<" "<<ans<<'\n';
    		for (ll i : w) cout<<i<<" ";
    	}
    }
    
    bool M2;
    
    int main()
    {
    //	freopen("a.in", "r", stdin);
    	cin.tie(0)->sync_with_stdio(0);
    	look_memory;
    	syr::work();
    	return 0;
    }
    

    信息

    ID
    571
    时间
    1000ms
    内存
    256MiB
    难度
    8
    标签
    (无)
    递交数
    121
    已通过
    20
    上传者