Description

OO has got a array A of size n ,defined a function f(l,r) represent the number of i (l<=i<=r) , that there's no j(l<=j<=r,j<>i) satisfy a imod a j=0,now OO want to know [∑i=1n ∑j=i n f(i,j) ] mod (10^9+7)
 

Input

There are multiple test cases. Please process till EOF. 
In each test case: 
First line: an integer n(n<=10^5) indicating the size of array 
Second line:contain n numbers a i(0<a i<=10000) 
 

Output

For each tests: ouput a line contain a number ans.
 

Sample Input

5
1 2 3 4 5
 

Sample Output

23
 
题意:给出长度为n的数列,设函数f(i,j)表示,在a[i]到a[j]中,其中i<=ti<=j,满足a[ti]%a[tj]!=0的ti的个数,其中tj为不等于ti的任意 i 到 j 中的数。
求出 [∑i=1n ∑j=i n f(i,j) ] mod (10^9+7)。
 
思路:对于数列中的每一个数,求出其被所有可行区间包含的次数。
 
代码与注释如下。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
const int maxn=,maxx=;
const long long mod=;
vector<int>divi[maxn];
int a[maxx],l[maxx],r[maxx],pos[maxn],n;
void ini(){
for(int i=;i<=;i++)
for(int j=;j<=i;j++)
if(i%j==) divi[i].push_back(j);
//预处理出10000内所有数的因子
}
int main(){
ini();
while(~scanf("%d",&n)){
for(int i=;i<n;i++)
scanf("%d",&a[i]);
memset(l,-,sizeof(l));
memset(r,0x3f,sizeof(r));
memset(pos,-,sizeof(pos));
//l[i]表示a[i]左边与之最接近的它的因子的下标
for(int i=;i<n;i++){
int lef=-;
for(int j=;j<divi[a[i]].size();j++)
lef=max(lef,pos[divi[a[i]][j]]);
pos[a[i]]=i;
//pos数组用于更新维护最靠近a[i]的因子数的下标
l[i]=lef;
}
memset(pos,0x3f,sizeof(pos));
//r[i]表示a[i]右边与之最接近的它的因子的下标
for(int i=n-;i>=;i--){
int rig=0x3f3f3f3f;
for(int j=;j<divi[a[i]].size();j++)
rig=min(rig,pos[divi[a[i]][j]]);
pos[a[i]]=i;
//pos数组用于更新维护最靠近a[i]的因子数的下标
r[i]=rig;
}
long long ans=,L,R;
for(int i=;i<n;i++){
if(l[i]==-) L=i+;
//若为原值,则说明a[i]左边不存在因子
else L=i-l[i];
//否则,令L为a[i]到其因子右边第一个数之间的个数
if(r[i]==0x3f3f3f3f) R=n-i;
else R=r[i]-i;
ans=(L*R%mod+ans)%mod;
//L*R为包含a[i]的连续区间的组合数。
}
printf("%d\n",ans);
}
return ;
}
 

2015 多校赛 第一场 1001 (hdu 5288)的更多相关文章

  1. 2015 多校赛 第一场 1007 (hdu 5294)

    总算今天静下心来学算法.. Description Innocent Wu follows Dumb Zhang into a ancient tomb. Innocent Wu’s at the e ...

  2. 2015 多校赛 第一场 1002 (hdu 5289)

    Description Tom owns a company and he is the boss. There are n staffs which are numbered from 1 to n ...

  3. hdu 5288||2015多校联合第一场1001题

    pid=5288">http://acm.hdu.edu.cn/showproblem.php?pid=5288 Problem Description OO has got a ar ...

  4. 2015 多校赛 第二场 1006 (hdu 5305)

    Problem Description There are n people and m pairs of friends. For every pair of friends, they can c ...

  5. 2015 多校赛 第二场 1004 hdu(5303)

    Problem Description There are n apple trees planted along a cyclic road, which is L metres long. You ...

  6. 2015 多校赛 第二场 1002 (hdu 5301)

    Description Your current task is to make a ground plan for a residential building located in HZXJHS. ...

  7. HDU6578 2019HDU多校训练赛第一场 1001 (dp)

    HDU6578 2019HDU多校训练赛第一场 1001 (dp) 传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6578 题意: 你有n个空需要去填,有 ...

  8. hdu5294||2015多校联合第一场1007 最短路+最大流

    http://acm.hdu.edu.cn/showproblem.php? pid=5294 Problem Description Innocent Wu follows Dumb Zhang i ...

  9. 2019牛客多校赛第一场 补题 I题

    I题  Points Division 题意: 给你n个点,每个点有坐标(xi,yi)和属性(ai,bi),将点集划分为两个集合, 任意 A 集合的点 i 和 B 集合点 j, 不允许 xi > ...

随机推荐

  1. 阿里巴巴矢量库IconFont__使用小录

    使用阿里巴巴矢量库方法虽然不难,但本人记性不好,遂在次记录几笔 阿里巴巴矢量库地址:http://www.iconfont.cn/plus 阿里巴巴矢量库图标好处: 1:图标矢量化 2:自己总结:ic ...

  2. sql server time(7) 默认值

    语句为 ALTER TABLE dbo.YourTable ADD CONSTRAINT DF_TimeDefault DEFAULT '00:00:00' FOR YourTimeColumn 比如 ...

  3. 【转载】CentOS 安装rz和sz命令 lrzsz

    lrzsz在linux里可代替ftp上传和下载.lrzsz 官网入口:http://freecode.com/projects/lrzsz/ lrzsz是一个unix通信套件提供的X,Y,和ZMode ...

  4. 对 Lua闭包 知识点的学习的总结 ,在这里和大家分享一下,希望对大家有所帮助

    Lua闭包 --当一个函数内部嵌套另外一个函数定义时,内部的函数体可以访问外部的函数的局部变量,这种特征为词法定界.--闭包是由函数与其相关的引用环境组合而成的实体 闭包=函数+引用环境--不是在局部 ...

  5. Linux内核tracepoints

    Linux内核tracepoints 简单介绍 内核中的每个tracepoint提供一个钩子来调用probe函数. 一个tracepoint可以打开或关闭.打开时,probe函数关联到tracepoi ...

  6. List集合中把其中一个元素 调整到集合的第一位

    要求:现在想把集合中的某个元素,放到该集合的第一个位置,但是其他元素的顺序不需要管. 方法:需要遍历集合,找到这个元素在集合中的位置,然后使用Collections.swap(list,o,i) (O ...

  7. 0209利用innobackupex进行简单数据库的备份

    利用innobackupex进行简单数据库的备份yum install perl-DBIyum install perl-DBD-MySQLyum install perl-Time-HiResyum ...

  8. 【ACM】nyoj_143_第几是谁_201308071558

    第几是谁?时间限制:3000 ms  |  内存限制:65535 KB 难度:3描述 现在有"abcdefghijkl”12个字符,将其按字典序排列,如果给出任意一种排列,我们能说出这个排列 ...

  9. 1103 N的倍数

    1103 N的倍数  题目来源: Ural 1302 基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题  收藏  关注 一个长度为N的数组A,从A中选出若干个数,使得 ...

  10. 韩国 DBA 博客

    http://mysqldba.tistory.com/ http://cafe.naver.com/mysqlpg http://cafe.naver.com/realmysql http://wi ...