利用区间 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. 撸一个 vue 的截图组件,按比例截取

    <template> <div class="clip-img" :style="imgStyle"> <img :src=&qu ...

  2. java 线程实现、线程暂停和终止 、线程联合join、线程基本信息获取和设置、线程优先级

    转载地址:速学堂 https://www.sxt.cn/Java_jQuery_in_action/eleven-inheritthread.html 1. 通过继承Thread类实现多线程 继承Th ...

  3. Spring Bean的作用域以及lookup-method标签的使用

    Spring Framework支持五种作用域,如下图所示: singleton:表示一个容器中只会存在一个bean实例,无论在多少个其他bean里面依赖singleton bean,整个容器都只会存 ...

  4. Python 帮你玩微信跳一跳 GitHub Python脚本

    前言想自己搞游戏小程序的 在github 有人已经利用 python程序, 通过adb 获取不同型号安卓手机的系统截图,然后通过计算小人与目标位置距离之后得到准确的触摸时间,再通过 开发者模式里的 a ...

  5. 学习笔记之Google

    Google Pro Tip: Use Back-of-the-envelope-calculations to Choose the Best Design - High Scalability - ...

  6. UI5-技术篇-事务Tcode

    1.LPD_CUST 快速启动板概览 2./N/UI2/FLPD_CONF 创建目录与组(全部客户端) 3./N/UI2/FLPD_CUST 创建目录与组(当前客户端) 4./N/UI2/FLP 编辑 ...

  7. iOS滤镜功能

    一.iOS自带滤镜 1.CoreImage 使用苹果自带的CoreImage框架对图片进行处理,用CoreImage框架里的CIFilter对图片进行滤镜处理, 首先我们应该了解下CoreImage框 ...

  8. windows系统Android-sdk的下载与环境变量配置

    最近一段时间在做app的开发,作为前端而言,开发app并不像android工程师那样熟悉android开发:无论是使用cordova.js或者react-native开发都需要配置android开发环 ...

  9. C++——Big Three(copy ctor、copy op=、dtor)

    Big Three C++ 中Big Three指的是copy ctor 和 copy op=  和  dtor m_data是个字符串指针.一般而言,处理字符串,都是使用指针,在需要存储字符的时候再 ...

  10. Ubuntu16.04, CUDA8 CUDNN6 下安装 Tensorflow-gpu, Keras, Pytorch, fastai

    如何访问tensorflow官方网站 tensorflow官方网站变为:https://tensorflow.google.cn/ 安装深度学习框架 0. ubuntu查看CUDA和cuDNN版本 C ...