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 a i mod a j=0,now OO want to know

∑i=1n∑j=inf(i,j) mod (109+7).∑i=1n∑j=inf(i,j) mod (10 9+7).

InputThere 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 a
i(0<a
i<=10000)

OutputFor each tests: ouput a line contain a number ans.Sample Input

5
1 2 3 4 5

Sample Output

23

这道题目很难,不光是题意。
求不能被所有aj整除的ai有几个。规律还是比较好找的,难点在于数据大,二维暴力不存在的。
举上述例子,
11. 12 13 14 15
21. 22. 23 24 25
31. 32 33. 34 35
41. 42. 43 44. 45
51. 52 53 54 55.
有点的可以被整除。不能暴力想到以ai==aj为分界枚举左右区间
发现1*5+1*4+2+3+2*2+4*1
左区间的最大值乘以右区间最大值,左右区间的算法实在完蛋,看了题解找边界的算法懂了。
#include <iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define ll long long
#define mod 1000000007
ll a[100005];
ll l[100005];
ll r[100005];
ll pos[100005];
int main()
{
int n;
while(~scanf("%d",&n))
{
memset(l,0,sizeof(l));
memset(r,0,sizeof(r));
memset(pos,0,sizeof(pos));
for(ll i=1;i<=n;i++)
{
scanf("%d",&a[i]);
r[i]=n+1;
}
for(ll i=1;i<=n;i++)
{
for(ll j=1;j*j<=a[i];j++)
{
if(a[i]%j==0)
l[i]=max(l[i],max(pos[j],pos[a[i]/j]));
}
pos[a[i]]=i;
}
for(ll i=1;i<=10000;i++)
pos[i]=n+1;
for(ll i=n;i>0;i--)
{
for(ll j=1;j*j<=a[i];j++)
{
if(a[i]%j==0)
{r[i]=min(r[i],min(pos[j],pos[a[i]/j]));
//cout<<r[i]<<endl;
}
}
pos[a[i]]=i;
}
ll ans=0;
//l[1]=0;
/* for(ll i=1;i<=n;i++)
{
//cout<<i-l[i]<<endl,cout<<r[i]-i+1<<endl;
}*/
for(ll i=1;i<=n;i++)
{
ans=(ans+((i-l[i])*(r[i]-i)))%mod;
}
cout<<ans<<endl;
}
}

  

hdu_5288_OO’s Sequence的更多相关文章

  1. oracle SEQUENCE 创建, 修改,删除

    oracle创建序列化: CREATE SEQUENCE seq_itv_collection            INCREMENT BY 1  -- 每次加几个              STA ...

  2. Oracle数据库自动备份SQL文本:Procedure存储过程,View视图,Function函数,Trigger触发器,Sequence序列号等

    功能:备份存储过程,视图,函数触发器,Sequence序列号等准备工作:--1.创建文件夹 :'E:/OracleBackUp/ProcBack';--文本存放的路径--2.执行:create or ...

  3. DG gap sequence修复一例

    环境:Oracle 11.2.0.4 DG 故障现象: 客户在备库告警日志中发现GAP sequence提示信息: Mon Nov 21 09:53:29 2016 Media Recovery Wa ...

  4. Permutation Sequence

    The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

  5. [LeetCode] Sequence Reconstruction 序列重建

    Check whether the original sequence org can be uniquely reconstructed from the sequences in seqs. Th ...

  6. [LeetCode] Binary Tree Longest Consecutive Sequence 二叉树最长连续序列

    Given a binary tree, find the length of the longest consecutive sequence path. The path refers to an ...

  7. [LeetCode] Verify Preorder Sequence in Binary Search Tree 验证二叉搜索树的先序序列

    Given an array of numbers, verify whether it is the correct preorder traversal sequence of a binary ...

  8. [LeetCode] Longest Consecutive Sequence 求最长连续序列

    Given an unsorted array of integers, find the length of the longest consecutive elements sequence. F ...

  9. [LeetCode] Permutation Sequence 序列排序

    The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

随机推荐

  1. ubuntu下安装录屏软件

    sudo add-apt-repository ppa:maarten-baert/simplescreenrecorder sudo apt-get update sudo apt-get inst ...

  2. [Java][Liferay] File system in liferay

    EditFileEntryAction.java protected FileEntry updateFileEntry(PortletConfig portletConfig, ActionRequ ...

  3. Functional language(函数式编程语言)初步了解

    对于函数式语言并不太了解,查询了百度.博客.知乎等做了以下总结. What 函数式语言(functional language)一类程序设计语言,是一种非冯·诺伊曼式的程序设计语言.函数式语言主要成分 ...

  4. Spring课程 Spring入门篇 4-2 Spring bean装配(下)之Autowired注解说明1

    课程链接: 1 解析 2 代码演练 1 解析 1.1 @Required注解 该注解适用于bean属性的set方法 1.2 @Autowired 作用: 是为了把依赖的对象,自动的注入到bean里 使 ...

  5. CSS命名规范(规则)

    常用的CSS命名规则 头:header内容:content/container尾:footer导航:nav侧栏:sidebar栏目:column页面外围控制整体佈局宽度:wrapper左右中:left ...

  6. 关于node不需要重启即可刷新页面

    之前写node程序每次修改后台代码都需要重新node xxx.js重启该文件,但是发现有一个supervisor的模块可以解决这个问题,需要npm install -g supervisor一下,然后 ...

  7. 笨办法学Python(三十四)

    习题 34: 访问列表的元素 列表的用处很大,但只有你能访问里边的内容时它才能发挥出作用来.你已经学会了按顺序读出列表的内容,但如果你要得到第 5 个元素该怎么办呢?你需要知道如何访问列表中的元素.访 ...

  8. 寄生构造函数模式 js

    有一点需要说明:首先返回的对象与构造函数或者构造函数的原型属性之间没有关系,也就是说构造函数返回的对象与在构造函数外部创建的对象没有什么不同,为此不能依赖 instanceof 操作符来确定对象类型. ...

  9. Android 中间白色渐变到看不见的线的Drawable

    用gradient <gradient android:startColor="#00ffffff" android:centerColor="#ffffff&qu ...

  10. yum 源搭建

    RHEL系统部署网络yum源 配置网络yum源 RHEL系统本身光盘做成的yum源所提供的软件包有限,在实际使用过程中经常会出现缺包的现象,本文中以CentOS源作为替代,CentOS的软件包和RHE ...