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. TRY

  2. CocoaPods 基础知识--------安装 及 使用第三方库

    极客学院:http://www.jikexueyuan.com/course/2665_2.html?ss=1

  3. vmware ubuntu蓝屏

    ctrl+alt+f4 sudo apt-get update sudo apt-get upgrade sudo apt-get install xserver-xorg-lts-utopic su ...

  4. Scrum 冲刺 第四日

    目录 要求 项目链接 燃尽图 问题 今日任务 明日计划 成员贡献量 小组会议 要求 各个成员今日完成的任务(如果完成的任务为开发或测试任务,需给出对应的Github代码签入记录截图:如果完成的任务为调 ...

  5. 深入分析Java Web中的编码问题

    编码问题一直困扰着我,每次遇到乱码或者编码问题,网上一查,问题解决了,但是实际的原理并没有搞懂,每次遇到,都是什么头疼. 决定彻彻底底的一次性解决编码问题. 1.为什么要编码 计算机的基本单元是字节, ...

  6. vue style width a href动态拼接问题 ?

    style width 这个问题 折磨了我一个上午了  好惭愧 因为项目涉及到 进度条 所以必须用行内样式  style 用过vue的都知道 vue中style的用法 大众用法 :style=&quo ...

  7. KNN算法的代码实现

    # -*- coding: utf-8 -*-"""Created on Wed Mar 7 09:17:17 2018 @author: admin"&quo ...

  8. linux下的Shell编程(4)特殊的变量和占位符

    $#表示包括$0在内的命令行参数的个数.在Shell中,脚本名称本身是$0,剩下的依次是$0.$1.$2-.${9},等等. $*表示整个参数列表,不包括$0,也就是说不包括文件名的参数列表. $?表 ...

  9. CSS中容易混淆的伪元素类型和用法

    :first-of-type 匹配属于其父元素的第一个特定类型的子元素. 1.例子 <head> <meta charset="UTF-8"> <ti ...

  10. MySql查询正在进行中的事务

    用法 SELECT * FROM information_schema.INNODB_TRX 这个只能查询此刻正在进行中的事务,已经完成的是查不到的 表字段定义 The INFORMATION_SCH ...