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. VS2013配置编译Caffe-Win10_X64

    原文链接:http://blog.csdn.net/joshua_1988/article/details/45036993 有少量修改................ 2014年4月的时候自己在公司 ...

  2. 读白帽子web安全笔记

    点击劫持 frame buseting if (top.location != location) { top.location = self.location } html5的sandbox属性   ...

  3. webapi部署到IIS 404错误

    环境:win2008r2+IIS 解决方案: 添加一个映射 可执行文件地址(根据系统决定64位可32位): C:\Windows\Microsoft.NET\Framework64\v4.0.3031 ...

  4. (转)基于MVC4+EasyUI的Web开发框架经验总结(9)--在Datagrid里面实现外键字段的转义操作

    http://www.cnblogs.com/wuhuacong/p/3872890.html 我们在使用EasyUI的时候,很多情况下需要使用到表格控件datagrid,这个控件控件非常强大,使用起 ...

  5. shell脚本操作mysql数据库,使用mysql的-e参数可以执行各种sql的(创建,删除,增,删,改、查)等各种操作

    mysql  -hhostname -Pport -uusername -ppassword  -e  相关mysql的sql语句,不用在mysql的提示符下运行mysql,即可以在shell中操作m ...

  6. luogu P2852 [USACO06DEC]牛奶模式Milk Patterns 后缀数组 + Height数组 + 二分答案 + 扫描

    后缀数组有一个十分有趣的性质: $height[rk[i]] >= height[rk[i-1]] - 1$    Code: #include <bits/stdc++.h> #d ...

  7. py西游公关之模块

    Py西游攻关之模块   模块&包(* * * * *) 模块(modue)的概念: 在计算机程序的开发过程中,随着程序代码越写越多,在一个文件里代码就会越来越长,越来越不容易维护. 为了编写可 ...

  8. android keystore的生成和使用

    android要求所有的程序必须有签名,否则就不会安装该程序.在我们开发过程中,adt使用debug keystore,在 preference->android->buid中设置.deb ...

  9. Git 基础教程 之 版本回退

    不断对文件进行修改,然后不断提交修改到版本库里. 当你觉得文件修改到一定程度时,可以保存一个“快照”,这个“快照”在Git中称为“commit”. 一旦文件被改乱了.误删了,都可以从最近一个“comm ...

  10. mongodb--作为windows服务启动

    注意需要以管理员权限运行CMD