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. Murano Weekly Meeting 2015.09.22

    Meeting time: 2015.September.22th 1:00~2:00 Chairperson:  Serg Melikyan, PTL from Mirantis Meeting s ...

  2. DedeCms中Channel用typeid无效

    DedeCms中channel 用typeid调用无法达目的吗?请换成type试试! {dede:channel type='son' typeid='19' row='1'} <a href= ...

  3. net图片转格式

    http://blog.csdn.net/nrlovestudy/article/details/48137339 图片转格式 Bitmap bmp=new Bitmap("filename ...

  4. XtraReport三动态数据绑定

    代码还用上一节的,把Report的Datasource去掉.各个绑定的字段也去掉,有了第二节的基础,现在看这个就不难了,无非就是传到report一个数据集,在把这个数据集绑定到各控件里 清空detai ...

  5. Model对象嵌套list赋值方式(备忘)

    首先定义Model对象:var deliveryInfoModel = new DeliveryInfo(); 第二步定义嵌套的list对象:var list = new List<Delive ...

  6. [Java][Servlet] Failed to destroy end point associated with ProtocolHandler ["http-nio-8080"]

    Background: Servlet version 3.1(3.0之后就有了@WebServlet注解) Error 严重: Failed to destroy end point associa ...

  7. java-logic====吃货联盟

    1.系统界面 2.功能一 3.查看餐袋 4.签收订单 5.删除订单 6.我要点赞 主要分在两个类中: 第一个类entity,主要的是一些共有的属性 主要代码: public class entity ...

  8. 特殊的流程控制语句break continue exit

    break语句可以结束当前的for.foreach.while.do-while.或者switch的执行. for($i=1; $i<10; $i++) { if($i == 5) { echo ...

  9. css改变透明背景png图片的图标颜色

    HTML: <p><strong>原始图标</strong></p> <i class="icon icon-del"> ...

  10. XCode 如何真机运行别人的demo项目

    iOS应用安装到真机需要证书和mobileprovision 文件,拿到别人的项目 是没有这些的 ,也就运行不起来. 要想运行起来, 需要选中项目,  target - > 修改 bundlei ...