OO’s Sequence

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 449    Accepted Submission(s): 158

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 (10^9+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
 
Source
求在[a , b] 中有多少个i 满足找不到另一个数j 使,a[i] % a[j] = 0
用L[],R[]分别记录左右离起最近的因子,ans+=(R[i]-i+1)*(i-L[i]+1)/2 %MOD
//自己并没有想到怎么做 (╯▽╰)
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std ;
const int maxn = 100010 ;
const int mod = 1e9+7 ;
int a[maxn];
long long last[maxn] ;
long long pre[maxn] ;
long long l[maxn] ;
long long r[maxn] ;
int main()
{
//freopen("1001.txt" ,"r" ,stdin) ;
int n;
while(~scanf("%d",&n))
{
memset(pre,0,sizeof(pre));
memset(last,0,sizeof(last));
for(int i = 1;i <= n;i++)
{
l[i] = 1;
r[i] = n;
scanf("%d",&a[i]);
for(int j = a[i];j < 10001;j+=a[i])
{
if(pre[j] && r[pre[j]] == n)
r[pre[j]] = i-1;
pre[a[i]] = i;
}
} for(int i = n;i >=1;i--)
{
for(int j = a[i];j < 10001;j+=a[i])
{
if(last[j] && l[last[j]]==1)
l[last[j]] = i+1;
last[a[i]] = i;
}
}
long long ans = 0;
for(long long int i = 1;i <= n;i++)
ans= (ans+(((i-l[i]+1)%mod)*((r[i] - i +1)%mod))%mod)%mod;
printf("%I64d\n",ans);
}
return 0 ;
}

2015多校联赛 ——HDU5288(数学)的更多相关文章

  1. 2015 多校联赛 ——HDU5334(构造)

    Virtual Participation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Ot ...

  2. 2015 多校联赛 ——HDU5302(构造)

    Connect the Graph Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others ...

  3. 2015 多校联赛 ——HDU5294(最短路,最小切割)

    Tricks Device Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) To ...

  4. 2015 多校联赛 ——HDU5325(DFS)

    Crazy Bobo Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Tota ...

  5. 2015 多校联赛 ——HDU5316(线段树)

    Fantasy magicians usually gain their ability through one of three usual methods: possessing it as an ...

  6. 2015 多校联赛 ——HDU5323(搜索)

    Solve this interesting problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ...

  7. 2015 多校联赛 ——HDU5319(模拟)

    Painter Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Su ...

  8. 2015 多校联赛 ——HDU5301(技巧)

    Your current task is to make a ground plan for a residential building located in HZXJHS. So you must ...

  9. 2015 多校联赛 ——HDU5303(贪心)

    Delicious Apples Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Other ...

随机推荐

  1. maven添加oracle驱动

    由于oracle商业版权问题,maven是不可以直接下载jar包的,所以..   先将ojdbc14.jar放到用户目录,win7放到C:\Users\Administrator然后在cmd执行   ...

  2. Ubuntu下tomcat或eclipse启动提示没有java环境问题

    tomcat和eclipse默认使用了openjdk,通过压缩包安装的jdk无法被识别,通过修改tomcat/bin下的catalina.sh添加jdk和jre路径即可 sudo gedit cata ...

  3. PostgreSQL 配置安装

    Mac 安装 http://postgresapp.com/ 创建和删除数据库用户 对应命令如下(在postgres=# 环境下):1.查看数据库用户列表: \du2.创建数据库用户: create ...

  4. python day1 基本语法作业

    一.过7 start =1 while start<=10: if start !=7: print(start) start +=1 二.100以内的和 sum = 0 start = 1 w ...

  5. 关于collectionView和tableView的两种cell的出列方法的区别

    相信好多人一定会对collectionView和tableView的两种cell出列方法有所疑问,下面以UICollection为例子进行举例说明 假设我们已经创建了一个collectionView, ...

  6. SpringMVC源码情操陶冶#task-executor解析器

    承接Spring源码情操陶冶-自定义节点的解析.线程池是jdk的一个很重要的概念,在很多的场景都会应用到,多用于处理多任务的并发处理,此处借由spring整合jdk的cocurrent包的方式来进行深 ...

  7. EasyUI 中easyui-textbox和easyui-searchbox文本框的点击事件。

    html: <input id="txtsearch" class="easyui-textbox" data-options="buttonT ...

  8. 简单介绍 CPU 的工作原理

    1.内部架构 CPU 的根本任务就是执行指令,对计算机来说最终都是一串由 0 和 1 组成的序列.CPU 从逻辑上可以划分成 3 个模块,分别是控制单元.运算单元和存储单元 .其内部架构如下: [1] ...

  9. django处理cookie的机制

    title: django处理cookie的机制 tags: djaogo, cookie, session grammar_cjkRuby: true --- cookie的意义 在多数日常使用的网 ...

  10. Python-面向对象(一)-Day7

    Day7-面向对象基础 1一.isinstance(obj, cls) 1二.issubclass(sub, super) 1三.异常处理 11.异常基础 12.异常种类 23.异常其他结构 54.主 ...