OO’s Sequence

                                                         Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K
(Java/Others)

                                                                                            Total Submission(s): 1080    Accepted Submission(s): 403

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 (109+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
 
Author
FZUACM
 
Source
 



题目大意:
     
       给出一段序列。它的全部非空且里面的元素也为连续的子集中。不存在它能够整除数的元素的个数的和。


解题思路:

      对序列的每一个元素分开考虑,对于每一个元素。往左边找能够找到连续区间长度为a的序列(包含这个元素),往右边可

以找到长度为b的序列(包含这个元素),那么这个元素出现了a*b次,将每一个元素出现的次数相加就能够了。怎样找这个区

间?发现序列元素值就10000。于是能够开个10000的数组。数组记录这个值最后一次出现的位置。然后枚举约数就

就能够了。

代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
const int inf=0x7fffffff;
const int maxn=100000+1000;
const int mod=1000000000+7;
int a[maxn];
long long l[maxn];
long long r[maxn];
int h[maxn];
int main()
{
int n;
while(~scanf("%d",&n))
{
memset(h,0,sizeof(h));
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
int cur=inf,te;
for(int i=1;i<=n;i++)
{
cur=inf;
for(int j=1;j*j<=a[i];j++)
{
if(a[i]%j==0)
{
cur=min(cur,i-h[j]);
te=a[i]/j;
cur=min(cur,i-h[te]);
} }
l[i]=cur;
h[a[i]]=i;
}
for(int i=1;i<=10500;i++)
h[i]=n+1;
for(int i=n;i>0;i--)
{
cur=inf;
for(int j=1;j*j<=a[i];j++)
{
if(a[i]%j==0)
{
cur=min(cur,h[j]-i);
te=a[i]/j;
cur=min(cur,h[te]-i);
}
}
h[a[i]]=i;
r[i]=cur;
}
long long ans=0;
for(int i=1;i<=n;i++)
{
ans=(ans+(l[i]*r[i]))%mod;
}
printf("%I64d\n",ans);
}
return 0;
}


hdu 5288 OO’s Sequence(2015 Multi-University Training Contest 1)的更多相关文章

  1. Hdu 5288 OO’s Sequence 2015多小联赛A题

    OO's Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) ...

  2. 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 ...

  3. HDU 5288 OO‘s sequence (技巧)

    题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=5288 题面: OO's Sequence Time Limit: 4000/2000 MS (Jav ...

  4. HDU 5288 OO’s Sequence 水题

    OO's Sequence 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5288 Description OO has got a array A ...

  5. 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 ...

  6. 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 ...

  7. HDU 5288——OO’s Sequence——————【技巧题】

    OO’s Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

  8. 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 ...

  9. HDU 5288 OO’s Sequence

    题意:给一个序列,函数f(l, r)表示在[l, r]区间内有多少数字不是其他数字的倍数,求所有区间的f(l, r)之和. 解法:第一次打多校……心里还有点小激动……然而一道签到题做了俩点……呜呜呜… ...

随机推荐

  1. iOS之NSAttributedString-------字符属性

    NSAttributedString 字符属性 字符属性可以应用于 attributed string 的文本中. NSString *const NSFontAttributeName;(字体) N ...

  2. Farseer.net轻量级开源框架 中级篇:SQL执行报告

    导航 目   录:Farseer.net轻量级开源框架 目录 上一篇:Farseer.net轻量级开源框架 中级篇: 数据库切换 下一篇:Farseer.net轻量级开源框架 中级篇: 探究ORM(M ...

  3. 富文本KindEditor使用

    1.官网down KindEditor,添加到自己的项目中:添加时可把不需要的文件夹干掉,asp/php等等.我的项目用的是纯html和js,直接调用后台api: 2.页面引入相关js.eclipse ...

  4. mysql 常用的语句

    1.查出当前的字段,放到一个字段中:GROUP_CONCAT(distinct b.patent_ip) ,如 (select GROUP_CONCAT(distinct b.patent_ip) f ...

  5. JavaSE-12 面向对象程序设计的几条基础原则

    摘取代码中变化的行为,形成接口 在设计基类的时候,如果该类某个成员方法在子类中的实现变化差别比较大(一部分子类实现该方法是相同的),作为基类有两个问题:一是该方法不再通用:二是子类如果重写该方法,存在 ...

  6. socket编程(Java实现)

    主要是前段时间学习的网络知识的基于TCP与UDP编程,Java实现简单的大小写字母的转化,该文主要参考: https://blog.csdn.net/yjp19871013/article/detai ...

  7. 当执行计划中出现BITMAP CONVERSION TO ROWIDS关键字时,需要注意了。

    前言 前些天优化了一些耗费buffers较多的SQL,但系统CPU降低的效果不明显,于是又拉了awr报告,查看了SQL ordered by Gets排名前列的SQL. 分析 SQL代码: selec ...

  8. zabbix源码安装后,设置为服务启动和关闭

    zabbix源码安装,使用service启动与关闭服务 1. zabbix客户端的系统服务脚本 1.1 拷贝启动脚本 zabbix的源码提供了系统服务脚本,在/usr/local/src/zabbix ...

  9. leds-gpio driver

    我们还是先看看platform device是如何define的 platform device 是如何定义的 example1 在板级驱动中定义, 通过platform_add_devices()函 ...

  10. buf.swap16()

    buf.swap16() 返回:{Buffer} 将 Buffer 解释执行为一个16位的无符号整数数组并以字节顺序交换到位.如果 Buffer 的长度不是16位的倍数,则抛出一个 RangeErro ...