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. 1013团队Beta冲刺day4

    项目进展 李明皇 今天解决的进度 因服务器端未完成登录态维护,故无法进行前后端联动. 明天安排 前后端联动调试 林翔 今天解决的进度 因上课和实验室事务未完成登录态维护 明天安排 完成登录态维护 孙敏 ...

  2. Python randrange() 函数

    Python randrange() 函数  Python 数字 描述 randrange() 方法返回指定递增基数集合中的一个随机数,基数缺省值为1. 语法 以下是 randrange() 方法的语 ...

  3. python的Collections 模块

    Collections 模块 知识点 Counter 类 defaultdict 类 namedtuple 类 在这个实验我们会学习 Collections 模块.这个模块实现了一些很好的数据结构,它 ...

  4. DES MEI号码加密

    对于加密来说,使用DES加密解密很好,但是为了使不同设备的密文不一样,可以使用 固定字符串 + 设备IMEI号码 加密的方式,这样可以分辨不同手机,限制手机的使用(若是注册,一个手机只有一个IMEI号 ...

  5. SpringMVC之HandlerMapping的使用

    上篇博客在了解SpringMVC的工作流程时留了一些疑问,今天先学习下HandlerMapping,在HandlerMapping中可以通过HandlerExecutionChain getHandl ...

  6. EasyUI 中datagrid 分页。

    注释:datagrid分页搞了好几天才完全搞好,网上没完全的资料.明天晚上贴代码. 睡觉.

  7. JAVA_SE基础——57.有了包之后类与类之间的访问使用import语句

    代码1访问代码2 代码1: class Demo3 { public static void main(String[] args) { Demo4 a = new Demo4(); a.print( ...

  8. 在windows环境下安装redis和phpredis的扩展

    在windows环境下安装redis和phpredis的扩展 1.首先配置php: 需要在windows的集成环境中找到php的扩展文件夹,ext,然后在网上寻找自己的php对应的.dll文件 比如说 ...

  9. SQL Server(MySql)中的联合主键(联合索引) 索引分析

    最近有人问到这个问题,之前也一直没有深究联合索引具体使用逻辑,查阅多篇文章,并经过测试,得出一些结论 测试环境:SQL Server 2008 R2 测试结果与MySql联合索引查询机制类似,可以认为 ...

  10. linux下的Shell编程(5)循环

    Shell Script中的循环有下面几种格式: while [ cond1 ] && { || } [ cond2 ] -; do - done for var in -; do - ...