https://vjudge.net/problem/CodeForces-359D

http://codeforces.com/problemset/problem/359/D

题目大意:

给一串数,问一个区间内所有的数是否能被其其中一个数所全部整除,求出满足条件的区间的长度最大值,并输出这样的区间的个数与它们的左端点。

换句话将,求区间GCD=区间MIN的最大长度区间。

明显st表解决。

对于最大区间长度,二分判断即可。

(因为在poj做过类似的题所以思路能很快……就是题看不懂有点难,所以特地给出翻译)

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
const int N=1e5*+;
inline int read(){
int X=,w=; char ch=;
while(ch<'' || ch>'') {w|=ch=='-';ch=getchar();}
while(ch>='' && ch<='') X=(X<<)+(X<<)+(ch^),ch=getchar();
return w?-X:X;
}
inline int qpow(int a){
if(a==)return ;
return (<<a);
}
int gcdd[N][];
int minn[N][];
int log[N];
int n;
int gcd(int a,int b){
if(!b)return a;
return gcd(b,a%b);
}
void st(){
for(int j=;j<=log[n];j++){
for(int i=;i<=n;i++){
int p=i+qpow(j)-;
if(p>n)continue;
gcdd[i][j]=gcd(gcdd[i][j-],gcdd[i+qpow(j-)][j-]);
minn[i][j]=min(minn[i][j-],minn[i+qpow(j-)][j-]);
}
}
return;
}
bool pan(int k){
for(int i=;i<=n;i++){
int j=i+k;
if(j>n)break;
int l=log[k];
int p=qpow(l);
int GCD=gcd(gcdd[i][l],gcdd[j-p+][l]);
int MIN=min(minn[i][l],minn[j-p+][l]);
if(GCD==MIN)return ;
}
return ;
}
int len;
void erfen(int l,int r){
if(l>r)return;
int mid=(l+r)>>;
if(pan(mid)){
len=mid;
erfen(mid+,r);
}else{
erfen(l,mid-);
}
return;
}
vector<int>ans;
int main(){
n=read();
log[]=-;
for(int i=;i<=n;i++){
gcdd[i][]=minn[i][]=read();
log[i]=log[i>>]+;
}
log[]=;
st();
erfen(,n-);
for(int i=;i<=n;i++){
int j=i+len;
if(j>n)break;
int l=log[len];
int p=qpow(l);
int GCD=gcd(gcdd[i][l],gcdd[j-p+][l]);
int MIN=min(minn[i][l],minn[j-p+][l]);
if(GCD==MIN)ans.push_back(i);
}
printf("%d %d\n",(int)ans.size(),len);
for(int i=;i<ans.size();i++){
printf("%d ",ans[i]);
}
return ;
}

CF359D:Pair of Numbers——题解的更多相关文章

  1. cf359D Pair of Numbers

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

  2. CF359D Pair of Numbers gcd+暴力

    利用区间 gcd 个数不超过 log 种来做就可以了~ code: #include <bits/stdc++.h> #define N 300005 #define setIO(s) f ...

  3. Codeforces 395 D.Pair of Numbers

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

  4. 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 ...

  5. CF55D Beautiful numbers 题解

    题目 Volodya is an odd boy and his taste is strange as well. It seems to him that a positive integer n ...

  6. Pair of Numbers

    Codeforces Round #209 (Div. 2) D:http://codeforces.com/contest/359/problem/D 题意:给以一个n个数的序列,然后问你最大的区间 ...

  7. Hdoj 1905.Pseudoprime numbers 题解

    Problem Description Fermat's theorem states that for any prime number p and for any integer a > 1 ...

  8. Hdoj 1058.Humble Numbers 题解

    Problem Description A number whose only prime factors are 2,3,5 or 7 is called a humble number. The ...

  9. [LeetCode] Add Two Numbers题解

    Add Two Numbers: You are given two non-empty linked lists representing two non-negative integers. Th ...

随机推荐

  1. 转 Cobar使用文档(可用作MySQL大型集群解决方案)

    转自:http://blog.csdn.net/shagoo/article/details/8191346 最近好不容易抽空研究了下Cobar,感觉这个产品确实很不错(在文档方面比Amoeba强多了 ...

  2. Django模型与创建管理员用户

    默认情况下, 配置使用SQLite:

  3. 用Anko和Kotlin实现Android上的对话框和警告提示(KAD 24)

    作者:Antonio Leiva 时间:Mar 9, 2017 原文链接:https://antonioleiva.com/dialogs-android-anko-kotlin/ 借助Builder ...

  4. git基础(2)

    三.查看提交历史日志查看·提交历史:git log 命令一个常用的选项是 -p,用来显示每次提交的内容差异. 你也可以加上 -2 来仅显示最近两次提交如果你想看到每次提交的简略的统计信息,你可以使用 ...

  5. 【quick-cocos2d-lua】 基本类及用法

    1.cc.Director(导演类) 获得导演类实例:local  director = cc.Director : getInstance() 其中 cc 是Cocos2d-x Lua 类的命名空间 ...

  6. LeetCode 135——分发糖果

    1. 题目 2. 解答 初始化左序奖赏全为 1,从左往右遍历,如果右边的人评分比左边高,右边奖赏比左边奖赏增 1. 初始化右序奖赏全为 1,从右往左遍历,如果左边的人评分比右边高,左边奖赏比右边奖赏增 ...

  7. HADOOP docker(五):hadoop用户代理 Proxy user

    1.hadoop用户代理简介2.配置3.实验 1.hadoop用户代理简介 hadoop用户代理功能的作用是让超级用户superuser模拟一个普通用户来执行任务.比如用户joe通过oozie提交一个 ...

  8. 微信小程序:封装全局的promise异步调用方法

    微信小程序:封装全局的promise异步调用方法 一:封装 function POST(url, params) { let promise = new Promise(function (resol ...

  9. M2迭代分数分配

    M2中仍然依据每个成员的工作量,贡献度分配相应得分. 成员 得分 申开亮 25 王皓南 24 许晋 21 黄玉冰 20 王宇杰 18 吴润凡 17 巴丹益昔 15

  10. 内存转储文件调试系统崩溃bug

    百度百科:内存转储文件 内存转储是用于系统崩溃时,将内存中的数据转储保存在转储文件中,供给有关人员进行排错分析用途.而它所保存生成的文件就叫做内存转储文件. 内存转储文件也被称作虚拟内存,它是用硬盘里 ...