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

code:

  1. #include <bits/stdc++.h>
  2. #define N 300005
  3. #define setIO(s) freopen(s".in","r",stdin)
  4. using namespace std;
  5. int n;
  6. set<int>s;
  7. struct solve
  8. {
  9. int A[N],pos[N],len[N],gc[N],b[N],top,tmp;
  10. void get()
  11. {
  12. int i,j;
  13. for(i=1;i<=n;++i)
  14. {
  15. for(j=1;j<=top;++j) gc[j]=__gcd(gc[j], A[i]);
  16. gc[++top]=A[i], pos[top]=i, b[tmp=1]=1;
  17. for(j=2;j<=top;++j) if(gc[j]!=gc[j-1]) b[++tmp]=j;
  18. for(top=0,j=1;j<=tmp;++j) gc[++top]=gc[b[j]], pos[top]=pos[b[j]];
  19. len[i]=i-pos[top]+1;
  20. }
  21. }
  22. }ori,rev;
  23. int main()
  24. {
  25. // setIO("input");
  26. int i,j,re=0,cnt=0;
  27. scanf("%d",&n);
  28. for(i=1;i<=n;++i) scanf("%d",&ori.A[i]);
  29. for(i=1;i<=n;++i) rev.A[i]=ori.A[n-i+1];
  30. ori.get(), rev.get();
  31. for(i=1;i<=n;++i) re=max(re, ori.len[i]+rev.len[n-i+1]-2);
  32. for(i=1;i<=n;++i) if(ori.len[i]+rev.len[n-i+1]-2==re) s.insert(i-ori.len[i]+1);
  33. printf("%d %d\n",s.size(), re);
  34. for(set<int>::iterator it=s.begin();it!=s.end();it++) printf("%d ",*it);
  35. return 0;
  36. }

  

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. VMWare linux虚拟机(centos没有GUI)联网(NAT模式)

    使用yum list命令查看是否能连上网. 不能联网,需要对centos进行网络配置.但在此之前,需要: 1. 虚拟机网络连接方式设置成NAT. 2. window系统下的两个服务VMwareDHCP ...

  2. intellij idea 中右键项目没有git

    1.没有GIT选项说明还没有关联你的仓库 2.ctrl + alt +s 打开VersionControl添加git仓库 3.添加后再次查看,GIT就出现了 4.可以查看历史版本了. 原文地址:htt ...

  3. 怎样查看python的所有关键字

    关键字是python中具有特定功能的一组词汇, 这些词汇不能用作变量名, 一般会有高亮提示, code时请小心. python的关键字其实也是python的语法核心, 掌握了所有python关键字的用 ...

  4. Windows中的库编程

    Windows操作系统中,库分为动态链接库(dll)和静态链接库(lib) 动态库是Windows中实现代码共享的一种方式.它是一个二进制式文件,不可单独运行,需要调用方调用才能运行.在Windows ...

  5. SQL SERVER 中如何获取日期(一个月的最后一日、一年的第一日等等)

    https://blog.csdn.net/deepwishly/article/details/9101307 这是计算一个月第一天的SQL 脚本:   SELECT DATEADD(mm, DAT ...

  6. wstngfw中配置freeradius

    wstngfw中配置freeradius Radius为各种网络设备和服务提供了一个认证来源. Radius认证常用于***.入网门户.交换机.路由器和防火墙.Radius认证比在网络上的不同设备跟踪 ...

  7. 3_PHP表达式_5_数据类型转换_类型自动转换

    以下为学习孔祥盛主编的<PHP编程基础与实例教程>(第二版)所做的笔记. PHP类型转换分为类型自动转换和类型强制转换. 1.布尔型数据参与算数运算时,TRUE被转换为整数1,FALSE被 ...

  8. Mybatis:缓存

    1.什么是缓存[Cache] 存在内存中的临时数据. 将用户经常查询的数据放在缓存(内存)中,用户去查询数据就不用从磁盘上(关系型数据库数据文件)查询,从缓存中查询,从而提高查询效率,解决了高并发系统 ...

  9. IOS开发之——绘图(CGContext)

    0 CGContextRef context = UIGraphicsGetCurrentContext(); 设置上下文 1 CGContextMoveToPoint 开始画线 2 CGContex ...

  10. 微信小程序开发demo

    自己写的小程序,欢迎下载 https://gitee.com/lijunchengit/chengZiShengHuoBang