hdu 5288 OO’s Sequence 枚举+二分
In each test case:
First line: an integer n(n<=10^5) indicating the size of array
Second line:contain n numbers ai(0<ai<=10000)
1 2 3 4 5
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector> #define LL long long
#define pb push_back using namespace std; const int maxn=1e5+;
const int mod=1e9+;
const int inf=0x3f3f3f3f; int a[maxn];
int l[maxn];
int r[maxn];
vector <int> di[maxn];
vector <int> pos[maxn]; void pre_init()
{
for(int i=;i<maxn;i++){
for(int j=;j*j<=i;j++){
if(i%j==){
di[i].pb(j);
if(i/j != j)
di[i].pb(i/j);
}
}
}
} void init(int n)
{
for(int i=;i<maxn;i++){
pos[i].clear();
}
} void solve(int ); int main()
{
pre_init(); int n;
while(~scanf("%d",&n)){
init(n);
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
pos[a[i]].pb(i);
}
solve(n);
}
return ;
} void solve(int n)
{
for(int i=;i<=n;i++){
l[i]=,r[i]=n;
} for(int i=;i<=n;i++){
for(int j=;j<di[a[i]].size();j++){
int k=di[a[i]][j]; int left=,right=pos[k].size()-; if(right<left)
continue; if(pos[k][left]<i){
while(right-left>){
int mid=(left+right)>>;
if(pos[k][mid]>=i)
right=mid;
else
left=mid;
}
if(pos[k][right]<i)
l[i]=max(l[i],pos[k][right]+);
else
l[i]=max(l[i],pos[k][left]+);
} left=,right=pos[k].size()-;
if(pos[k][right]>i){
while(right-left>){
int mid=(left+right)>>;
if(pos[k][mid]<=i)
left=mid;
else
right=mid;
}
if(pos[k][left]>i)
r[i]=min(r[i],pos[k][left]-);
else
r[i]=min(r[i],pos[k][right]-);
} }
} /*
for(int i=1;i<=n;i++)
printf("%d %d\n",l[i],r[i]);
*/ LL ret=;
for(int i=;i<=n;i++){
ret+=(i-l[i]+)*(r[i]-i+)%mod;
ret=(ret+mod)%mod;
} printf("%I64d\n",ret);
return ;
}
hdu 5288 OO’s Sequence 枚举+二分的更多相关文章
- HDU 5288 OO’s Sequence [数学]
HDU 5288 OO’s Sequence http://acm.hdu.edu.cn/showproblem.php?pid=5288 OO has got a array A of size ...
- HDU 5288 OO‘s sequence (技巧)
题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=5288 题面: OO's Sequence Time Limit: 4000/2000 MS (Jav ...
- HDU 5288 OO’s Sequence 水题
OO's Sequence 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5288 Description OO has got a array A ...
- HDU 5288——OO’s Sequence——————【技巧题】
OO’s Sequence Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
- hdu 5288 OO’s Sequence(2015 Multi-University Training Contest 1)
OO's Sequence Time Limit: 4000/2000 MS (Jav ...
- Hdu 5288 OO’s Sequence 2015多小联赛A题
OO's Sequence Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- hdu 5288 OO’s Sequence(2015多校第一场第1题)枚举因子
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5288 题意:在闭区间[l,r]内有一个数a[i],a[i]不能整除 除去自身以外的其他的数,f(l,r ...
- hdu 5288 OO’s Sequence(计数)
Problem Description OO has got a array A of size n ,defined a function f(l,r) represent the number o ...
- HDU 5288 OO’s Sequence
题意:给一个序列,函数f(l, r)表示在[l, r]区间内有多少数字不是其他数字的倍数,求所有区间的f(l, r)之和. 解法:第一次打多校……心里还有点小激动……然而一道签到题做了俩点……呜呜呜… ...
随机推荐
- 改造dede 后台会员目录
可以在后台目录(默认 dede),里面的inc->inc_menu.php 文件里进行添加或更改,实现功能!
- FZU-2216 The Longest Straight (二分枚举)
题目大意:给n个0~m之间的数,如果是0,那么0可以变为任意的一个1~m之间的一个数.从中选出若干个数,使构成一个连续的序列.问能构成的最长序列的长度为多少? 题目分析:枚举连续序列的起点,二分枚举二 ...
- 不带www的域名跳转至www域名
由于我网站是架设在Linux的VPS上的,所以我用例如下方法 .htaccess文件 首先要开启Apache服务器的.htaccess功能,我在Apache安全配置中有分享过:开启之后新建一个.hta ...
- Linux内核源代码的结构(转)
源代码所有在目录:/usr/src/linux (大部分linux发行版本中) init 内核初始化代码 kernel 内核核心部分:进程.定时.程序执行.信号.模块... mm 内存处理 a ...
- 【转】ios的控件UIScrollView的位置定位---------逐渐积累
原文网址:http://blog.csdn.net/z343929897/article/details/8106408 UIScrollView的判断位置的属性如下: contentSize:C ...
- SQL 将一列多行数据合并为一行 FOR XML PATH
FOR XML PATH 方法是用于将查询结果集以XML形式展示,这样展示方式的好处不言而喻.现在我要介绍的FOR XML PATH的"另类"用法. 首先,我们先来看看它的正常用法 ...
- linux包之包管理命令rpm-yum
背景 YUM(Yellow dog Updater, Modified)为多个Linux发行版的前端软件包管理器,例如 Redhat RHEL, CentOS & Fedora. YUM通过调 ...
- .net 实现 URL重写,伪静态(方法一)
一,获得Mircosoft URLRewriter.dll(注意:此dll文件大小约为20KB,网上有8Kb的是不完整的文件,会报错) 二,在项目中该dll文件:添加引用(可以直接拷贝放入Bin文件夹 ...
- Ajax编程中,经常要能动态的改变界面元素的样式
在Ajax编程中,经常要能动态的改变界面元素的样式,可以通过对象的style属性来改变,比如要改变背景色为红色,可以这样写:element.style.backgroundColor=”#ff0000 ...
- PorterDuff.Mode error
Android PorterDuff.Mode error: PorterDuff cannot be resolved to a variable Answers: Add this t ...