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. 《Linux程序设计》笔记(一)入门

    1. 头文件 使用-I标志来包含头文件. gcc -I/usr/openwin/include fred.c 2. 库文件 通过给出 完整的库文件路径名 或 用-l标志 来告诉编译器要搜索的库文件. ...

  2. C++版的LLC代码

    图像稀疏编码总结:LLC和SCSPM,文章对稀疏编码讲解非常详细. <Locality-constrained Linear Coding for Image Classification> ...

  3. 据说现在很缺设计师,阿里云的LOGO是用键盘打出来的……

    今天,阿里云发布了自己的新LOGO,官方的解读是:“[]”这个呢其实是代码中常用的一个符号,代表着计算:中间的“—”则代表流动的数据.在官网等平台上,阿里云新LOGO是动态的,中间的“—”会匀速移动, ...

  4. (转)基于MVC4+EasyUI的Web开发框架经验总结(10)--在Web界面上实现数据的导入和导出

    http://www.cnblogs.com/wuhuacong/p/3873498.html 数据的导入导出,在很多系统里面都比较常见,这个导入导出的操作,在Winform里面比较容易实现,我曾经在 ...

  5. 移动APP 微信支付完整过程(wxPay 方案一)

    apicloud.weixinpay官方提供了两种方案. 本模块封装了两套支付方案: 方案一:开发者通过 getOrderId.payOrder 自己处理签名过程(微信开放平台建议把 getOrder ...

  6. Tomcat的几种部署方式

    1.  直接把项目的根目录放在: apache-tomcat-*.*\webapps\ROOT 这样即可以通过http://127.0.0.1:8080 来访问 2.  把项目根目录放在: apach ...

  7. vue scss 安装

    1.开始在vue项目中使用sass,在命令行输入一下命令进行安装(使用git命令行要用shift+insert 进行粘贴否则粘贴不上) cnpm install node-sass --save-de ...

  8. eas之利用KDTableHelper批量填充数据

    // 下述代码将创建一个KDTable,并指定列名.表头单元格的显示值.和表体数据KDTable table = new KDTable();String [] columnKeys = new St ...

  9. 洛谷P1057 传球游戏【递归+搜索】

    上体育课的时候,小蛮的老师经常带着同学们一起做游戏.这次,老师带着同学们一起做传球游戏. 游戏规则是这样的:nn个同学站成一个圆圈,其中的一个同学手里拿着一个球,当老师吹哨子时开始传球,每个同学可以把 ...

  10. javascript基础扫盲

    JavaScript基础扫盲 null和undefined 非十进制的表示方法 强制类型转换 运算 null和undefined null是一个是非来表示一个空对象的,故 typeof 的返回值是ob ...