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. axios处理http请求

    axios中文文档 https://github.com/mzabriskie/axios#using-applicationx-www-form-urlencoded-format  axios文档 ...

  2. WEB服务器、网站、域名、IP地址、DNS服务器之间的关系

    域名首先指向你的服务器,这个过程叫解析.  服务器分成好多小块,每小块叫一个空间或者一个虚拟主机.  所以当你输入你的域名以后,服务器收到你域名的访问信息,但不知道要打开这么多个小块中的那一个.所以要 ...

  3. web相关知识

    1,网络编程/网站编程:敲一个网站,别人可以访问 访问:在地址栏里面敲入地址,就可以访问了. 服务器如果放在公网,那么别人就可以通过IP地址进行访问 所以我们可以先在本地把我们的网站搭好,别人就可以来 ...

  4. Python实现抓取CSDN热门文章列表

    1.使用工具: Python3.5 BeautifulSoup 2.抓取网站: csdn热门文章列表 http://blog.csdn.net/hot.html 3.分析网站代码: 4.实现代码: _ ...

  5. PHP运行机制

    PHP运行机制: 访问html文件:访问的域名à解析成IP地址(hosts文件,dns)à找到服务器àapache拿到html文件à返回给浏览器à浏览器解析html内容 访问php文件:apache拿 ...

  6. JNA简单使用

    近期使用Java开发有关于摄像机接收到数据的上传,因为摄像机处理图像是用C语言实现的,所以开发需要用到JNA,实现JAVA对C语言的回调,因为具体的开发方式官方文档里面有示例,所以本文只是简单的把需要 ...

  7. 快速排序c语言实现

    #include <stdio.h> void quick_sort(int* a, int n) { ) return; int i,j,tmp,k; k = a[n/]; ,j = n ...

  8. Ubuntu 16.10 安装mysql

    打开终端 sudo apt update 完成后 sudo apt install mysql-server 中间会提示设置root 账户的密码 有的文章提到 还要 install mysql-cli ...

  9. MySQL免安装版中 my-default.ini 的配置

    拷贝一份  “my-default.ini”  文件 重命名为 “my.ini” 这样根目录下就有两个.ini文件了 一个是my-default.ini 一个是my.ini 接下来我们只需修改my.i ...

  10. webpack了解

    一.理解webpack 什么是webpack? 是一个模块打包器.它的主要目标是将 JavaScript 文件打包在一起,打包后的文件用于在浏览器中使用,但它也能够胜任转换(transform).打包 ...