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. xencenter迁移云主机方法

    问题:POOL中计算节点内存不足. 解决方法:1.为计算节点添加内存(费用高)2.将部分资源迁移到其它POOL中. 方法: 1.选择要迁移的虚拟机 2.选择保存路径 这里可以看到可以批量导出: 注意: ...

  2. unity3d 角色头顶信息3D&2D遮挡解决方案(二)

    在阅读本文之前请先阅读上一篇文章:http://www.cnblogs.com/shenggege/p/4179012.html 本来一篇文章就可以说完了,但是上次只是实现了已知的一些功能 后来在实际 ...

  3. PS 给天空添加蓝天白云<转载>

    https://jingyan.baidu.com/article/b2c186c8e83b1cc46ef6ffee.html 给图片添加蓝天白云的步骤: 1.打开要加蓝天白云的照片.(如图一) [图 ...

  4. hdu2553N皇后问题(dfs,八皇后)

    N皇后问题 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  5. Python字符串操作大全(非常全!!!)

    1. python编程里字符串的内置方法(非常全) capitalize() 把字符串的第一个字符改为大写 casefold() 把整个字符串的所有字符改为小写 center(width) 将字符串居 ...

  6. Unity操作小技巧

    1.操作类 1)F:选择物体后聚焦 2)V:选择物体的顶点,顶点吸附 3)Ctrl:摁住后拖动物体,可以按照系统设置的步长进行移动(Edit -> Snap setting) 4)Q W E R ...

  7. Java开发工程师(Web方向) - 04.Spring框架 - 第5章.Web框架

    第5章--Web框架 Web框架概述 Web框架单元测验 本次得分为:13.50/15.00, 本次测试的提交时间为:2017-09-25 1单选(2分) 关于Spring MVC中Dispatche ...

  8. 机器学习-支持向量机SVM

    简介: 支持向量机(SVM)是一种二分类的监督学习模型,他的基本模型是定义在特征空间上的间隔最大的线性模型.他与感知机的区别是,感知机只要找到可以将数据正确划分的超平面即可,而SVM需要找到间隔最大的 ...

  9. python 智能合约日志操作

    from __future__ import unicode_literals import json from time import sleep, time # 中文编码 def encode_s ...

  10. Juice账号

    zhangxiaocong69 zxc6545398 15657167502 区块链账户: 0x00680404766965143796a0a070835c3cdf9a4a50