【NOIP2017提高B组模拟9.7】NYG的动态数点

【NOIP2017提高模拟9.7】NYG的动态数点

Description

在这里插入图片描述

Input

Output

在这里插入图片描述

Sample Input

输入1:
5
4 6 9 3 6

输入2:
30
15 15 3 30 9 30 27 11 5 15 20 110 25 20 30 15 30 15 25 5 10 20 7 7 16 2 7 7 28 7

Sample Output

输出1:
1 3
2

输出2:
1 13
9

Data Constraint

Hint

在这里插入图片描述

题解

水题
从左到右枚举除数,再向左和向右拓展
剪枝:扩展过的点就不用再做了
时间复杂度 近似O(N)

code

#include<cstdio>
#include<cctype>
#include<cstdlib>
#include<algorithm>
#define R register
using namespace std;
int n,cnt,ans,a[500101],l[500101];
inline void read(R int &x){
	x=0;char ch=getchar();
	while(!isdigit(ch))ch=getchar();
	while(isdigit(ch))x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
}
int main(){
	read(n);
	for(R int i=1;i<=n;++i)read(a[i]);
	for(R int i=1;i<=n;++i){
		R int x=i,y=i;
		while(a[x-1]%a[i]==0&&x>1&&a[x-1]!=a[i])--x;
		while(a[y+1]%a[i]==0&&y<n)++y;
		if(y-x>=ans)l[++cnt]=x;
		if(y-x>ans)ans=y-x,l[cnt=1]=x;
		i=y;
	}
	printf("%d %d\n",cnt,ans);
	sort(l+1,l+1+cnt);
	for(R int i=1;i<=cnt;++i)printf("%d ",l[i]);
} 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值