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. Javascript IE 内存释放

    一个内存释放的实例 <SCRIPT LANGUAGE="JavaScript"><!--strTest = "1";for ( var i = ...

  2. Python3.0 操作MySQL数据库执行SQL语句

    py3不支持MySQLdb,需要导入pymysql模块 # coding: utf-8 # Team : Quality Management Center # Author:Carson # Dat ...

  3. 解决webstorm中vue语法没有提示

    首先看看webstrom内置的vue插件,打上勾,没有这个选项就要自己去下载插件了 如果插件还是没有语法提示,可以用下面的方法,自己添加语法进去搜索 unknown HTML tag attribut ...

  4. url编码函数encodeURI和encodeURIComponent

    var url = "http://www.wrox.com/illegal value.html#start";encodeURIComponent(url)  //" ...

  5. opencv笔记

    加载图像: OpenCV支持图像格式Windows位图(bmp),便携式图像格式(pbm,pgm,ppm)和Sun光栅(sr,ras). Mat image = imread( imageName, ...

  6. JVM优化(上)

    02.我们为什么要对jvm做优化: 1.标准参数:-help-version 2. -X参数(非标) -Xint-Xcomp -Xint : interpreted-Xcomp: complied   ...

  7. 原生javascript实现call、apply和bind的方法

    var context = {id: 12}; function fun (name, age) { console.log(this.id, name, age) } bind bind() 方法会 ...

  8. C++中const与constexpr区别

    对于对象来说 const指的是编译期常量和运行时常量,两者并没有区分 constexpr特指编译期常量 对于函数来说 const可以修饰类的成员函数,被修饰的函数在执行期间不会改变对象的值. clas ...

  9. 1. 垃圾收集简介 - GC参考手册

    说明: 在本文中, Garbage Collection 翻译为 “垃圾收集”, garbage collector 翻译为 “垃圾收集器”; 一般认为, 垃圾回收 和 垃圾收集 是同义词. Mino ...

  10. LeetCode(4)Median of Two Sorted Arrays

    题目 There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the ...