CF359D Pair of Numbers gcd+暴力
利用区间 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+暴力的更多相关文章
- cf359D Pair of Numbers
Simon has an array a1, a2, ..., an, consisting of n positive integers. Today Simon asked you to find ...
- Codeforces 395 D.Pair of Numbers
D. Pair of Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- 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 ...
- CodeForces 359D Pair of Numbers (暴力)
题意:给定一个正整数数组,求最长的区间,使得该区间内存在一个元素,它能整除该区间的每个元素. 析:暴力每一个可能的区间,从数组的第一个元素开始考虑,向两边延伸,设延伸到的最左边的点为l, 最右边的点为 ...
- CF359D:Pair of Numbers——题解
https://vjudge.net/problem/CodeForces-359D http://codeforces.com/problemset/problem/359/D 题目大意: 给一串数 ...
- Codeforces 359D Pair of Numbers | 二分+ST表+gcd
题面: 给一个序列,求最长的合法区间,合法被定义为这个序列的gcd=区间最小值 输出最长合法区间个数,r-l长度 接下来输出每个合法区间的左端点 题解: 由于区间gcd满足单调性,所以我们可以二分区间 ...
- hdu 5726 GCD 暴力倍增rmq
GCD/center> 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5726 Description Give you a sequence ...
- Gym 100299C && UVaLive 6582 Magical GCD (暴力+数论)
题意:给出一个长度在 100 000 以内的正整数序列,大小不超过 10^ 12.求一个连续子序列,使得在所有的连续子序列中, 它们的GCD值乘以它们的长度最大. 析:暴力枚举右端点,然后在枚举左端点 ...
- UVa 1642 Magical GCD (暴力+数论)
题意:给出一个长度在 100 000 以内的正整数序列,大小不超过 10^ 12.求一个连续子序列,使得在所有的连续子序列中, 它们的GCD值乘以它们的长度最大. 析:暴力枚举右端点,然后在枚举左端点 ...
随机推荐
- VMWare linux虚拟机(centos没有GUI)联网(NAT模式)
使用yum list命令查看是否能连上网. 不能联网,需要对centos进行网络配置.但在此之前,需要: 1. 虚拟机网络连接方式设置成NAT. 2. window系统下的两个服务VMwareDHCP ...
- intellij idea 中右键项目没有git
1.没有GIT选项说明还没有关联你的仓库 2.ctrl + alt +s 打开VersionControl添加git仓库 3.添加后再次查看,GIT就出现了 4.可以查看历史版本了. 原文地址:htt ...
- 怎样查看python的所有关键字
关键字是python中具有特定功能的一组词汇, 这些词汇不能用作变量名, 一般会有高亮提示, code时请小心. python的关键字其实也是python的语法核心, 掌握了所有python关键字的用 ...
- Windows中的库编程
Windows操作系统中,库分为动态链接库(dll)和静态链接库(lib) 动态库是Windows中实现代码共享的一种方式.它是一个二进制式文件,不可单独运行,需要调用方调用才能运行.在Windows ...
- SQL SERVER 中如何获取日期(一个月的最后一日、一年的第一日等等)
https://blog.csdn.net/deepwishly/article/details/9101307 这是计算一个月第一天的SQL 脚本: SELECT DATEADD(mm, DAT ...
- wstngfw中配置freeradius
wstngfw中配置freeradius Radius为各种网络设备和服务提供了一个认证来源. Radius认证常用于***.入网门户.交换机.路由器和防火墙.Radius认证比在网络上的不同设备跟踪 ...
- 3_PHP表达式_5_数据类型转换_类型自动转换
以下为学习孔祥盛主编的<PHP编程基础与实例教程>(第二版)所做的笔记. PHP类型转换分为类型自动转换和类型强制转换. 1.布尔型数据参与算数运算时,TRUE被转换为整数1,FALSE被 ...
- Mybatis:缓存
1.什么是缓存[Cache] 存在内存中的临时数据. 将用户经常查询的数据放在缓存(内存)中,用户去查询数据就不用从磁盘上(关系型数据库数据文件)查询,从缓存中查询,从而提高查询效率,解决了高并发系统 ...
- IOS开发之——绘图(CGContext)
0 CGContextRef context = UIGraphicsGetCurrentContext(); 设置上下文 1 CGContextMoveToPoint 开始画线 2 CGContex ...
- 微信小程序开发demo
自己写的小程序,欢迎下载 https://gitee.com/lijunchengit/chengZiShengHuoBang