利用区间 gcd 个数不超过 log 种来做就可以了~

code:

#include <bits/stdc++.h>
#define N 300005
#define setIO(s) freopen(s".in","r",stdin)
using namespace std;
int n;
set<int>s;
struct solve
{
int A[N],pos[N],len[N],gc[N],b[N],top,tmp;
void get()
{
int i,j;
for(i=1;i<=n;++i)
{
for(j=1;j<=top;++j) gc[j]=__gcd(gc[j], A[i]);
gc[++top]=A[i], pos[top]=i, b[tmp=1]=1;
for(j=2;j<=top;++j) if(gc[j]!=gc[j-1]) b[++tmp]=j;
for(top=0,j=1;j<=tmp;++j) gc[++top]=gc[b[j]], pos[top]=pos[b[j]];
len[i]=i-pos[top]+1;
}
}
}ori,rev;
int main()
{
// setIO("input");
int i,j,re=0,cnt=0;
scanf("%d",&n);
for(i=1;i<=n;++i) scanf("%d",&ori.A[i]);
for(i=1;i<=n;++i) rev.A[i]=ori.A[n-i+1];
ori.get(), rev.get();
for(i=1;i<=n;++i) re=max(re, ori.len[i]+rev.len[n-i+1]-2);
for(i=1;i<=n;++i) if(ori.len[i]+rev.len[n-i+1]-2==re) s.insert(i-ori.len[i]+1);
printf("%d %d\n",s.size(), re);
for(set<int>::iterator it=s.begin();it!=s.end();it++) printf("%d ",*it);
return 0;
}

  

CF359D Pair of Numbers gcd+暴力的更多相关文章

  1. cf359D Pair of Numbers

    Simon has an array a1, a2, ..., an, consisting of n positive integers. Today Simon asked you to find ...

  2. Codeforces 395 D.Pair of Numbers

    D. Pair of Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  3. Codeforces Round #209 (Div. 2) D. Pair of Numbers (模拟)

    D. Pair of Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  4. CodeForces 359D Pair of Numbers (暴力)

    题意:给定一个正整数数组,求最长的区间,使得该区间内存在一个元素,它能整除该区间的每个元素. 析:暴力每一个可能的区间,从数组的第一个元素开始考虑,向两边延伸,设延伸到的最左边的点为l, 最右边的点为 ...

  5. CF359D:Pair of Numbers——题解

    https://vjudge.net/problem/CodeForces-359D http://codeforces.com/problemset/problem/359/D 题目大意: 给一串数 ...

  6. Codeforces 359D Pair of Numbers | 二分+ST表+gcd

    题面: 给一个序列,求最长的合法区间,合法被定义为这个序列的gcd=区间最小值 输出最长合法区间个数,r-l长度 接下来输出每个合法区间的左端点 题解: 由于区间gcd满足单调性,所以我们可以二分区间 ...

  7. hdu 5726 GCD 暴力倍增rmq

    GCD/center> 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5726 Description Give you a sequence ...

  8. Gym 100299C && UVaLive 6582 Magical GCD (暴力+数论)

    题意:给出一个长度在 100 000 以内的正整数序列,大小不超过 10^ 12.求一个连续子序列,使得在所有的连续子序列中, 它们的GCD值乘以它们的长度最大. 析:暴力枚举右端点,然后在枚举左端点 ...

  9. UVa 1642 Magical GCD (暴力+数论)

    题意:给出一个长度在 100 000 以内的正整数序列,大小不超过 10^ 12.求一个连续子序列,使得在所有的连续子序列中, 它们的GCD值乘以它们的长度最大. 析:暴力枚举右端点,然后在枚举左端点 ...

随机推荐

  1. AS3.0 位图(BMP)解析类

    /** * *-----------------------------* * | *** BMP格式解析类 *** | * *-----------------------------* * * 编 ...

  2. session和cookie有什么区别?

    1.存储位置不同 cookie的数据信息存放在客户端浏览器上. session的数据信息存放在服务器上. 2.存储容量不同 单个cookie保存的数据<=4KB,一个站点最多保存20个Cooki ...

  3. C#操作Windows控制面板

    先介绍一下Windows控制面板的一些操作,再介绍如何用C#语言来操作控制面板. 1.如何快速打开控制面板中的项目: 运行输入(大小写不敏感) control system 打开系统信息 contro ...

  4. Jenkins 发邮件的Job

    Jenkins要做到构建失败的时候发送邮件,常规做法是加个全局的post failure,类似这样的代码 pipeline { agent any stages { stage('deploy') { ...

  5. processon使用教程

    原文地址:https://www.cnblogs.com/yangliheng/p/6082250.html 一.引言 作为一名IT从业者,不仅要有扎实的知识储备,出色的业务能力,还需要具备一定的软实 ...

  6. 基于【 bug解决】一 || mysql的ONLY_FULL_GROUP_BY导致的sql语句错误

    一.Mysql错误: In aggregated query without GROUP BY, expression #1 of SELECT list contains nonaggregated ...

  7. UNIX常用shell

    /bin/sh Bourne shell 它是Unix的默认Shell,也是其它Shell的开发基础.Bourne Shell在编程方面相当优秀,但在处理与用户的交互方面不如其它几种Shell /bi ...

  8. cocos-js 精灵移动转圈

    cc.Class({ extends: cc.Component, properties: { carModel: { default: null, type: cc.Sprite }, bgMode ...

  9. OpenStack kilo版(7) 部署dashboard

    安装dashboard  root@controller:~# apt-get install openstack-dashboard  配置 /etc/openstack-dashboard/loc ...

  10. 【DRF框架】序列化组件——ModelSerializer

    ModelSerializer 1.ModelSerializer类似于ModelForm 2.根据模型自动生成一组字段 3.自带实现了.update()以及.create()方法 ModelSeri ...