利用区间 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. CH01-ZYNQ修炼秘籍-LINUX篇-虚拟机环境搭建

    CH01基于Ubuntu系统的ZYNQ-7000开发环境的搭建 1.1概述 实验环境: Windows 10 专业版 Vmware workstation 14.1.1 Ubuntu 16.04.3 ...

  2. "一起来捉妖"怎么从瘸腿中组合到最合心意的妖灵

    背景: 最近两天活动,黑鬼白鬼合体觉醒秋容,陆无名,聂小倩,作为一个非土豪玩家,没有超高资质妖灵的我,想要在瘸腿妖灵中选取两个最佳选择,合体觉醒. 初选: 备选妖灵从5个维度录入数据,进行选择,分别为 ...

  3. WebHost.CreateDefaultBuilder

    返回WebHostBuilder: 1.用Kestrel做为web服务器,并根据配置提供器内容对其配置. 2.当前目录作为content根目录. 3.从appsettings.json,环境变量,ar ...

  4. Authentication failed for "http://xxxxxx"

    1.配置用户信息 git config --global user.name [username] git config --global user.email [email] 2.查询用户信息   ...

  5. Verilog HDL

    https://wenku.baidu.com/view/9943b7acf524ccbff1218463.html https://hdlbits.01xz.net/wiki/Main_Page h ...

  6. php中需要注意的函数(持续更新)

    explode 函数 $a = null; explode("#",$a); //不会报错会返回一个只包含空字符串的数组

  7. vue导出Excel文件

    1.需要安装file-saver和script-loader.xlsx npm install file-saver / yarn add file-saver npm install script- ...

  8. vue-cli项目开发运行时内存暴涨卡死电脑

    最近开发一个vue项目时遇到电脑卡死问题,突然间系统就非常卡,然后卡着卡着就死机了,鼠标也动不了了,只能冷启动.而且因为是突然卡死,没来得及打开任务管理器. 最开始以为是硬盘的问题,但是在卡死几次后, ...

  9. 九、分组查询详解(group by & having)

    本篇内容 分组查询语法 聚合函数 单字段分组 多字段分组 分组前筛选数据 分组后筛选数据 where和having的区别 分组后排序 where & group by & having ...

  10. 【leetcode】266. Palindrome Permutation

    原题 Given a string, determine if a permutation of the string could form a palindrome. For example, &q ...