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. Ubuntu16.04搭建深度学习框架——TensorFlow

    TensorFlow是一个采用数据流图(data flow graphs),用于数值计算的开源软件库,说白了,就是一个库. 小编自己在Ubuntu搭建了深度学习框架TensorFlow,感觉挺简单,现 ...

  2. 百度网页分享js代码

    1.小图标 <div class="bdsharebuttonbox"> <a href="#" class="bds_qzone& ...

  3. SWIG 和 Python——c/c++与脚本交互

    C 和 C++ 被公认为(理当如此)创建高性能代码的首选平台.对开发人员的一个常见要求是向脚本语言接口公开 C/C++ 代码,这正是 Simplified Wrapper and Interface ...

  4. DotNetty 跨平台的网络通信库(转)

    久以来,.Net开发人员都非常羡慕Java有Netty这样,高效,稳定又易用的网络通信基础框架.终于微软的Azure团队,使用C#实现的Netty的版本发布.不但使用了C#和.Net平台的技术特点,并 ...

  5. intellijidea课程 intellijidea神器使用技巧 6-1 Spring的关联

    待学完spring之后再来看 Spring的关联位置:菜单->File->Project Structure->Facets功能:帮助管理Spring容器.还提供了很多其他的管理,比 ...

  6. react- 相关

    生命周期方法 组件的生命周期分成三个状态: Mounting:已插入真实 DOM Updating:正在被重新渲染 Unmounting:已移出真实 DOM React 为每个状态都提供了两种处理函数 ...

  7. EF--DB First

    DB First先有数据库,根据数据库生成Model实体对象. 1.新建数据库表,Poet,Poem,Meter.关系如下: 建表语句 create table Poet ( PoetId ,) pr ...

  8. 如何让MVC和多层架构和谐并存(二)

    上一节说了一些笼统的东西,这节说一些实际的操作. 1.取列表.这是一个新闻列表:         对应MVC的model是: public class NewsListModel { /// < ...

  9. Azure 媒体服务换新锁,更安全更方便,新钥匙请收好!

    不知道有多少人已经把家里的门锁换成了数字化的指纹锁?沿用了几百上千年的传统门锁,在技术的帮助下无疑变得更方便,不用带钥匙,还能远程控制和操作,最重要的是,终于不用担心「衣果(luǒ)着」出门扔垃圾,风 ...

  10. Android程序员不容错过的10款在线实用工具

    Android十款在线工具,在做Android开发过程中,会遇到一些小的问题,虽然自己动手也能解决,但是有了一些小工具,解决这些问题就得心应手了.Android在线工具,包括在线测试工具,及其他较为重 ...