JZOJ 6294. Dynamic Number Points [Violence] [Thinking]

233

Title:

Portal

Title:

In a sequence of length nnn, l, rl, R are selected to guarantee a k_a I (i_ l-r) a_k | a_i (iu epsilon_ l-r)ak_ai(i_ l-r)
What is the length, number and the left point of the longest interval satisfying the condition?

Analysis:

Direct violence okay
There is no explanation here, but let's mention the true violence O(n)O(n)O(n) given by Lord BPMBPMBPM.
Assuming that a K a_k a K has been determined, for a new number aja_j a j, if (aj,ak) = 1 (aj,ak) = 1 (aj,ak) = 1 (aj,ak) = 1, then we will determine the largest interval according to ordinary violence. When (aj,ak) 1(a_j,a_k)\neq 1(aj,ak) = 1, then aja_jaj will be counted into the answer when aka_kak is determined, and the interval of aja_j can not be larger. The number will only be traversed once, which is the excellent algorithm of O(n)O(n)O(n)O(n).

Code:

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<set>
#include<queue>
#include<vector>
#include<map>
#include<list>
#include<ctime>
#include<iomanip>
#include<string>
#include<bitset>
#include<deque>
#include<set>
#define LL long long
using namespace std;
inline LL read(){
    LL d=0,f=1;char s=getchar();
    while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
    while(s>='0'&&s<='9'){d=d*10+s-'0';s=getchar();}
    return d*f;
}
int n,a[500005],ans[500005],l,r,maxl=0,s=0,tot=0;
int main()
{
	freopen("point.in","r",stdin);
	freopen("point.out","w",stdout);
	n=read();
	for(int i=1;i<=n;i++) a[i]=read();
	for(int i=1;i<=n;i=r+1)
	{
		l=r=i;
		while(l>1&&a[l-1]%a[i]==0) l--;
		while (r<n&&a[r+1]%a[i]==0) r++;
		s=r-l;
		if(s>maxl) maxl=s,ans[tot=1]=l;
		else if(s==maxl) ans[++tot]=l;
	}
	printf("%d %d\n",tot,maxl);
	for (int i=1;i<=tot;i++) printf("%d ",ans[i]);
	return 0;
}

Posted on Wed, 09 Oct 2019 02:51:21 -0700 by Fabio9999