预处理出每一个数字的左右两边能够整除它的近期的数的位置

OO’s Sequence

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)

Total Submission(s): 1880    Accepted Submission(s): 672

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 (109+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
 
Author
FZUACM
 
Source
 

/* ***********************************************
Author :CKboss
Created Time :2015年07月24日 星期五 08时12分15秒
File Name :HDOJ5288.cpp
************************************************ */ #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map> using namespace std; typedef long long int LL; const int maxn=100100;
const LL MOD=(LL)(1e9+7); int n;
int a[maxn];
int Left[maxn],Right[maxn];
vector<int> pos[10010]; void init()
{
for(int i=0;i<=10010;i++)
{
pos[i].clear();
}
for(int i=0;i<n;i++)
{
Left[i]=0; Right[i]=n-1;
}
} void pre()
{
for(int i=0;i<n;i++)
{
int x=a[i];
for(int j=x;j<=10000;j+=x)
{
for(int k=0,sz=pos[j].size();k<sz;k++)
{
int z=pos[j][k];
if(z==i) continue;
else if(z<i)
{
Right[z]=min(Right[z],i-1);
}
else if(z>i)
{
Left[z]=max(Left[z],i+1);
}
}
}
}
} int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout); while(scanf("%d",&n)!=EOF)
{
init();
for(int i=0;i<n;i++)
{
scanf("%d",a+i);
pos[a[i]].push_back(i);
}
pre();
LL ans=0;
for(int i=0;i<n;i++)
{
LL L=i-Left[i]+1LL;
LL R=Right[i]-i+1LL;
ans=(ans+(L*R)%MOD)%MOD;
}
cout<<ans<<endl;
} return 0;
}

HDOJ 5288 OO’s Sequence 水的更多相关文章

  1. 思维题 HDOJ 5288 OO’s Sequence

    题目传送门 /* 定义两个数组,l[i]和r[i]表示第i个数左侧右侧接近它且值是a[i]因子的位置, 第i个数被选择后贡献的值是(r[i]-i)*(i-l[i]),每个数都枚举它的因子,更新l[i] ...

  2. HDU 5288 OO’s Sequence 水题

    OO's Sequence 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5288 Description OO has got a array A ...

  3. hdoj 5288 OO’s Sequence

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5288 //*************头文件区************* #include<ios ...

  4. HDU 5288 OO’s Sequence [数学]

     HDU 5288 OO’s Sequence http://acm.hdu.edu.cn/showproblem.php?pid=5288 OO has got a array A of size ...

  5. HDU 5288 OO‘s sequence (技巧)

    题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=5288 题面: OO's Sequence Time Limit: 4000/2000 MS (Jav ...

  6. HDU 5288——OO’s Sequence——————【技巧题】

    OO’s Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

  7. Hdu 5288 OO’s Sequence 2015多小联赛A题

    OO's Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) ...

  8. hdu 5288 OO’s Sequence(2015 Multi-University Training Contest 1)

    OO's Sequence                                                          Time Limit: 4000/2000 MS (Jav ...

  9. 【HDOJ】5288 OO’s Sequence

    二分寻找对于指定pos的最左因数点和最右因数点. /* 5288 */ #include <iostream> #include <string> #include <m ...

随机推荐

  1. ArrayList的总结

    1.ArrayList的特点 主要特点:按照插入顺序来保存元素,可以利用下标来查找值 2.ArrayList的优点: 按照下标访问元素最快 3.ArrayList的缺点: 在中间插入元素很慢 删除元素 ...

  2. Java 与 Json的互相转换

    这几天一直在做Java解析Json数据的一个项目,因为初识json,所以很多东西都是有着懵懂的认识.这里写下我解析时遇到的问题和收获. 我解析json时用到的是json-lib包.下载地址:http: ...

  3. 苹果无法连接到itunes store怎么办

    方法1:设置--还原--还原网络设置,再进app store就可以了.方法2:重置访问限制“设置”–> “通用” –> “访问限制”,开启访问限制5秒,然后再关闭访问限制.方法3:重置当前 ...

  4. 邪恶力量第一至九季/全集Supernatural迅雷下载

    邪恶力量 第一季 Supernatural Season 1 (2005) 本季看点:一部充满吸引力的系列剧,超自然现象题材中的亲情与正义.迪恩(简森·阿克斯 Jensen Ackles 饰)和萨姆( ...

  5. 设置Images.xcassets后启动仍旧黑屏的问题

    换了XCode6之后,发现以前写Icon-76.png这样很麻烦,就使用了Image.xcassets,公司所有测试机跑了一下,发现没什么问题.唯独有一台设置有问题,iphone5 ios6.0系统, ...

  6. android自定义风格的toast

    先上图看一下我的自定义toast的样式 源码下载地址: CustomToastActivity.java源码 package com.jinhoward.ui_customtoast; /** * A ...

  7. go语言之进阶篇error接口应用

    1.error接口应用 示例: package main import "fmt" import "errors" func MyDiv(a, b int) ( ...

  8. RxJava【变换】操作符 map flatMap concatMap buffer MD

    Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...

  9. js 处理URL实用技巧

    escape().encodeURI().encodeURIComponent()三种方法都能对一些影响URL完整性的特殊字符进行过滤.     但后两者是将字符串转换为UTF-8的方式来传输,解决了 ...

  10. google map放大缩小地图去除 ctrl+,直接用鼠标放大缩小

    如图,最近突然需要ctrl+鼠标滚动,才可以放大缩小地图: 这个问题也困扰了我很久,这个解决办法也是在看到一个帖子才发现的,所以记录一下,如图: map = new google.maps.Map(d ...