题目链接:http://acm.hdu.edu.cn/showproblem.php?

pid=5288

题面:

OO’s Sequence

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

Total Submission(s): 985    Accepted Submission(s): 375

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
 

解题:

仅仅想到从左到右去找近期的不合法点。没想到从右往左找,那么答案就出来了。事实上数据范围那么小,就已经是一种暗示了。能够用数组记录下其最后出现的位置。注意扫的操作,要和记录同一时候进行。注意小心处理1的情况就好。

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <map>
#include <vector>
#include <cmath>
#include <algorithm>
#define mod 1000000007
#define maxn 100010
#define LL long long
using namespace std;
int t,le[100010],ri[100010],store[100010],pre[100010],tmp,root;
LL ans;
int main()
{
while(~scanf("%d",&t))
{
ans=0;
for(int i=1;i<=t;i++)
scanf("%d",&store[i]);
for(int i=1;i<=t;i++)
pre[i]=0;
for(int i=1;i<=t;i++)
{
tmp=1;
root=sqrt((double)store[i]);
for(int j=1;j<=root;j++)
{
if(store[i]%j==0)
{
tmp=max(tmp,pre[j]+1);
tmp=max(tmp,pre[store[i]/j]+1);
}
}
le[i]=tmp;
pre[store[i]]=i;
}
for(int i=1;i<=t;i++)
pre[i]=t+1;
for(int i=t;i>=1;i--)
{
tmp=t;
root=sqrt((double)store[i]);
for(int j=1;j<=root;j++)
{
if(store[i]%j==0)
{
tmp=min(pre[j]-1,tmp);
tmp=min(tmp,pre[store[i]/j]-1);
}
}
ri[i]=tmp;
pre[store[i]]=i;
}
/*for(int i=1;i<=t;i++)
cout<<i<<" "<<le[i]<<" "<<ri[i]<<endl;*/
for(int i=1;i<=t;i++)
{
ans=(ans+1LL*(i-le[i]+1)*(ri[i]-i+1))%mod;
}
printf("%lld\n",ans);
}
return 0;
}

HDU 5288 OO‘s sequence (技巧)的更多相关文章

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

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

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

  3. HDU 5288 OO’s Sequence 水题

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

  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(计数)

    Problem Description OO has got a array A of size n ,defined a function f(l,r) represent the number o ...

  9. HDU 5288 OO’s Sequence

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

随机推荐

  1. 如何优雅的设计 React 组件

    作者:晓冬 本文原创,转载请注明作者及出处 如今的 Web 前端已被 React.Vue 和 Angular 三分天下,一统江山十几年的 jQuery 显然已经很难满足现在的开发模式.那么,为什么大家 ...

  2. PHPMailer < 5.2.21 - Local File Disclosure(CVE-2017-5223)

    CVE-2017-5223 :PHPMailer < 5.2.21 - Local File Disclosure 本文主要介绍一下PHPMailer < 5.2.21 - Local F ...

  3. jquery实现抽奖小游戏

    在很多网站或游戏活动中我们都会看到有关抽奖的活动或界面: 下面我将给大家介绍下如何通过javascript来实现这样的一个抽奖功能,主要从下面三个步骤入手(文中着重介绍第三部分有关功能的实现): 1. ...

  4. 关于thinkphp控制器引用model里的方法的一点收获

    有时候真的是很绕,为了这一点点收获,我几乎花了一天的时间.当我弄明白了的那一刻,我.........好吧,写到这里,我发现不能换行.好吧,就这样吧,开始说正题:要想在controler从model引用 ...

  5. HTML基础--position 绝对定位 相对定位 锚点链接

    position 定位属性,检索对象的定位方式 一.语法:position:static /absolute/relative/fixed 取值: 1.static:默认值,无特殊定位,对象遵循HTM ...

  6. Python字符编码详解(转)

    http://www.cnblogs.com/huxi/archive/2010/12/05/1897271.html 在没有reload(sys)之前调用sys.setdefaultencoding ...

  7. HTML5技术分享 ES2017继发与并发

    大家都知道,async函数的返回值是 Promise 对象,这比 Generator 函数的返回值是 Iterator 对象方便多了.你可以用then方法指定下一步的操作. 进一步说,async函数完 ...

  8. 程序、计算机程序、java初论

    一.程序? 程序一词来自生活,通常指完成某些事情的一种既定方式和过程,可以将程序看成对一系列动作的执行过程的描述. 例如:个人去银行取钱 1.带上存折/银行卡去银行 2.取号排队 3.将存折或储蓄卡递 ...

  9. Hibernate持久化对象的三种状态深入理解

    关于OID hibernate缓存是一个map,他会根据OID作为缓存对象的key,我们的映射文件中<id>标签指定的属性值会作为OID 持久化对象的三种状态 为了方便理解,Hiberna ...

  10. 十、Hadoop学习笔记————Hive与Hbase以及RDBMS(关系型数据库)的关系

    Hive目的是为了简化MapReduce编程 实际应用中,Hive与Hbase不经常链接