OO’s Sequence

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

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
 

题目大意:给你一个长度为n的区间。求这个区间内任意子区间中ai没有因子的ai的个数。

解题思路:从左往右遍历a数组得到L数组。对于ai,枚举j  1-->sqrt(ai),如果j是ai的约数并且j已经在ai之前,那么我用max取离i最近的位置;相应的ai/j也是ai的约数,同理如果ai/j也在ai之前,也用max取离i最近的位置。对于R数组,同理可得。

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
const int maxn=1e5+20;
const int INF=0x3f3f3f3f;
const int MOD=1e9+7;
int a[maxn],L[maxn],R[maxn];
int pos[maxn];
int main(){
int n,limj;
while(scanf("%d",&n)!=EOF){
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
}
memset(pos,0,sizeof(pos));
for(int i=1;i<=n;i++){
L[i]=0;
limj=(int)sqrt(a[i]);
for(int j=1;j<=limj;j++){
if(a[i]%j==0){
if(pos[j]){
L[i]=max(L[i],pos[j]);
}
if(pos[a[i]/j]){
L[i]=max(L[i],pos[a[i]/j]);
}
}
}
pos[a[i]]=i;
}
memset(pos,0,sizeof(pos));
for(int i=n;i>=1;i--){
R[i]=n+1;
limj=(int)sqrt(a[i]);
for(int j=1;j<=limj;j++){
if(a[i]%j==0){
if(pos[j]){
R[i]=min(R[i],pos[j]);
}
if(pos[a[i]/j]){
R[i]=min(R[i],pos[a[i]/j]);
}
}
}
pos[a[i]]=i;
}
int sum=0,res;
for(int i=1;i<=n;i++){
sum=(sum%MOD+((i-L[i])*(R[i]-i))%MOD)%MOD;
}
printf("%d\n",sum);
}
return 0;
}

  

HDU 5288——OO’s Sequence——————【技巧题】的更多相关文章

  1. HDU 5288 OO’s Sequence 水题

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

  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 2015多小联赛A题

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

  5. hdu 5288 OO’s Sequence(2015 Multi-University Training Contest 1)

    OO's Sequence                                                          Time Limit: 4000/2000 MS (Jav ...

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

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

  8. HDU 5288 OO’s Sequence

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

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

随机推荐

  1. [转]B+Tree图解

    一,    M阶B+树的定义(M阶是指一个节点最多能拥有的孩子数,M>2): 图1.1 3阶B+树 (1)根结点只有1个,分支数量范围[2,m]. (2)除根以外的非叶子结点,每个结点包含分支数 ...

  2. 警惕C#事件使用过程中的GC陷阱

    关于C#中的事件,园里已经有大量的文章对其内在实现做过剖析,如果还不甚了解的可以阅读这篇文章 通过Demo来细看C#事件的内在机制 虽然比较早,但非常清楚地展示了事件的内部机制,总结一下就是 1.事件 ...

  3. NSCalendar日历

    前言 NSCalendar 对世界上现存的常用的历法进行了封装,既提供了不同历法的时间信息,又支持日历的计算. NSCalendar -- 日历类,它提供了大部分的日期计算接口,并且允许您在NSDat ...

  4. dota有哪些经典的典故或笑话?

    ----------------------------------------------------dota有哪些经典的典故或笑话?虽然现在玩游戏也没什么热情了, 但是看到这些还是笑尿,笑点低 = ...

  5. 《Effective Java》——读后总结

    这本书在Java开发的行业里,颇有名气.今天总算是粗略的看完了…后面线程部分和序列化部分由于心浮气躁看的不仔细.这个月还剩下一周,慢慢总结消化. 1.静态工厂方法代替构造器 静态工厂方法有名称,能确切 ...

  6. 如何理解<base href="<%=basePath%>" ---转载

    原文链接http://316325524.blog.163.com/blog/static/6652052320111118111620897/ "base href " 今天在写 ...

  7. OpenStack-Mitaka

    一.Cloud 基础概念 IAAS:Infrastructre As A Service 基础架构及服务,OpenStack,CloudStack PAAS:Platform As A Service ...

  8. 构建docker镜像

    一.通过docker commit命令构建镜像 docker commit 构建镜像可以想象为是将运行的镜像进行重命名另存一份.我们先创建一个容器,并在容器里做出修改,就像修改代码一样,最后再将修改提 ...

  9. swarm1

    type 必选项,1表示container,2表示swarm stack,3表示compose stack title 必选项 description 必选项 image 必选项,该应用使用的dock ...

  10. 洛谷 P4001 [ICPC-Beijing 2006]狼抓兔子

    题目描述 现在小朋友们最喜欢的"喜羊羊与灰太狼",话说灰太狼抓羊不到,但抓兔子还是比较在行的,而且现在的兔子还比较笨,它们只有两个窝,现在你做为狼王,面对下面这样一个网格的地形: ...