OO’s Sequence

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 449    Accepted Submission(s): 158

Problem 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 ai mod aj=0,now OO want to know

∑i=1n∑j=inf(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 ai(0<ai<=10000)
 
Output
For each tests: ouput a line contain a number ans.
 
Sample Input
5
1 2 3 4 5
 
Sample Output
23
 
Source
求在[a , b] 中有多少个i 满足找不到另一个数j 使,a[i] % a[j] = 0
用L[],R[]分别记录左右离起最近的因子,ans+=(R[i]-i+1)*(i-L[i]+1)/2 %MOD
//自己并没有想到怎么做 (╯▽╰)
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std ;
const int maxn = 100010 ;
const int mod = 1e9+7 ;
int a[maxn];
long long last[maxn] ;
long long pre[maxn] ;
long long l[maxn] ;
long long r[maxn] ;
int main()
{
//freopen("1001.txt" ,"r" ,stdin) ;
int n;
while(~scanf("%d",&n))
{
memset(pre,0,sizeof(pre));
memset(last,0,sizeof(last));
for(int i = 1;i <= n;i++)
{
l[i] = 1;
r[i] = n;
scanf("%d",&a[i]);
for(int j = a[i];j < 10001;j+=a[i])
{
if(pre[j] && r[pre[j]] == n)
r[pre[j]] = i-1;
pre[a[i]] = i;
}
} for(int i = n;i >=1;i--)
{
for(int j = a[i];j < 10001;j+=a[i])
{
if(last[j] && l[last[j]]==1)
l[last[j]] = i+1;
last[a[i]] = i;
}
}
long long ans = 0;
for(long long int i = 1;i <= n;i++)
ans= (ans+(((i-l[i]+1)%mod)*((r[i] - i +1)%mod))%mod)%mod;
printf("%I64d\n",ans);
}
return 0 ;
}

2015多校联赛 ——HDU5288(数学)的更多相关文章

  1. 2015 多校联赛 ——HDU5334(构造)

    Virtual Participation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Ot ...

  2. 2015 多校联赛 ——HDU5302(构造)

    Connect the Graph Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others ...

  3. 2015 多校联赛 ——HDU5294(最短路,最小切割)

    Tricks Device Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) To ...

  4. 2015 多校联赛 ——HDU5325(DFS)

    Crazy Bobo Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Tota ...

  5. 2015 多校联赛 ——HDU5316(线段树)

    Fantasy magicians usually gain their ability through one of three usual methods: possessing it as an ...

  6. 2015 多校联赛 ——HDU5323(搜索)

    Solve this interesting problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ...

  7. 2015 多校联赛 ——HDU5319(模拟)

    Painter Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Su ...

  8. 2015 多校联赛 ——HDU5301(技巧)

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

  9. 2015 多校联赛 ——HDU5303(贪心)

    Delicious Apples Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Other ...

随机推荐

  1. Linux 磁盘和文件管理系统 文件打包解压备份 VIM、VI编辑器

  2. SAN LUN Mapping出错导致文件系统共享冲突,数据恢复成功

    [用户单位] 中国联通某分公司[数据恢复故障描述]    SUN 光纤存储系统,中心存储为6枚300G硬盘组成的RAID6,划分为若干LUN,MAP到不同业务的服务器上,服务器上运行SUN SOLAR ...

  3. 自制 h5 音乐播放器 可搜索

    闲言碎语: 有好几天没有发表博客了,这也是因为一直开发音乐和完善我的博客项目,好不容易抽出时间总结一下这几天所做的东西,笔试又不断通知,实则匆忙 今天难得逃了一次课,就趁这时间,该写写就写写吧~~ 进 ...

  4. JAVA_SE基础——49.多态的应用

    因为多态对以后开发的重要性,因此我在这里专门开个多态的应用来加深讲解,希望想弄懂多态的同学能耐心看完. 了解了对象多态性后,那么这多态到底有哪些用处了? 下面要求设计一个方法,要求此方法可以接受A类的 ...

  5. javascript中的数组对象

    1.创建数组的三种方式: 1.1 var 数组名=[元素1,元素2,元素3...]; 例如: var arr1=[1,2,3,4]; 1.2 var 数组名=new Array(元素1,元素2,元素3 ...

  6. Jenkins中展示HTML测试报告

    背景:测试报告是用reportNG生成的,属于java自动化测试项目. 1)         安装插件 首先要安装HTML Publisher plugin,这个在插件管理里面搜索并安装即可,如下我已 ...

  7. Docker加速器(阿里云)

    1. 登录阿里开发者平台: https://dev.aliyun.com/search.html,https://cr.console.aliyun.com/#/accelerator,生成专属链接 ...

  8. Linux CentOS7.0 (01)在Vmvare Workstation上 安装配置

    一.新建虚拟机 1.创建新的虚拟机 -> 默认典型 ->选择安装介质 2.指定虚拟机名称.安装目录.磁盘容量大小 点击 "完成",创建虚拟机! 随后虚拟机将自动启动安装 ...

  9. 由路由器AP隔离引起的WEB服务不能访问的问题

    最近在自己的电脑上运行了一个Web服务,发现它只能被本机访问,无法在同一个局域网的其它设备访问. 于是在网上搜索了各种资料,通通都是在操作系统层面来分析解决问题的. 而我怎么尝试都不成功的情况下,差点 ...

  10. 对于错误“Refused to execute script from '...' because its MIME type ('') is not executable, and strict MIME type checking is enabled.”的处理。

    今天在是用公司的报表插件Stimulsoft时发现的问题.之前可以正常使用,突然不能加载了.查看发现得到这个错误. 查看请求头 可以看到,请求正常响应,但是发现 Content-Type是空的,但是引 ...