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 (+).
Input
There are multiple test cases. Please process till EOF.
In each test case:
First line: an integer n(n<=^) indicating the size of array
Second line:contain n numbers ai(<ai<=)
Output
For each tests: ouput a line contain a number ans.
Sample Input
    
Sample Output

Author
FZUACM
 
 
Source
 

题意:

本来的题意问  枚举所有i,j ,1<=i<=j<=n,  然后计算f(i,j)和是多少。

f(l,r)的值 是 输入的数组下标 l到r中有多少 数是无法被这个区间 任意一个数整除的。 

 

做法:

转换种思想就是 某个数num[i],在多少个区间内 可以不被区间其他任何数整除。  答案加上区间个数。

所以 可以左右两边枚举过来。

以左边枚举过来为例:

把最近出现的数 记录下来,记录到 has数组。   如num[i]      记录成has[num[i]]=i     

 

然后把每个数的因子枚举,判断最近左边出现因子在哪。  然后那个位子+1 就是左端点了。

 

在同样处理出右端点, 左右端点知道就很容易算出num[i]在多少区间内符合要求 加到ans里。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<cmath>
#include<stdlib.h>
#include<map>
#include<vector>
using namespace std;
#define N 100006
#define M 10006
#define MOD 1000000007
int n;
int vis[M];
int a[N];
vector<int> G[M];
int L[N];
int R[N];
void init(){
for(int i=;i<M;i++){
for(int j=;j<=i;j++){
if(i%j==){
G[i].push_back(j);
}
}
}
}
int main()
{
init();
while(scanf("%d",&n)==){
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
}
memset(vis,,sizeof(vis));
memset(L,-,sizeof(L));
memset(R,-,sizeof(R));
for(int i=;i<=n;i++){
for(int j=;j<G[a[i]].size();j++){
int tmp=G[a[i]][j];
if(vis[tmp]){
if(a[i]%tmp==){
if(L[i]!=-){
L[i]=max(L[i],vis[tmp]+);
}
else{
L[i]=vis[tmp]+;
}
} }
}
vis[a[i]]=i;
}
memset(vis,,sizeof(vis));
for(int i=n;i>=;i--){
for(int j=;j<G[a[i]].size();j++){
int tmp=G[a[i]][j];
if(vis[tmp]){
if(a[i]%tmp==){
if(R[i]!=-){
R[i]=min(R[i],vis[tmp]-);
}
else{
R[i]=vis[tmp]-;
}
} }
}
vis[a[i]]=i;
}
int ans=;
for(int i=;i<=n;i++){
if(L[i]==-){
L[i]=;
}
if(R[i]==-){
R[i]=n;
}
}
for(int i=;i<=n;i++){
ans=(ans+(i-L[i]+)*(R[i]-i+))%MOD;
}
printf("%d\n",ans);
}
return ;
}

hdu 5288 OO’s Sequence(计数)的更多相关文章

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

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

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

  3. HDU 5288 OO’s Sequence 水题

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

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

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

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

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

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

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

  7. hdu 5288 OO’s Sequence(2015多校第一场第1题)枚举因子

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5288 题意:在闭区间[l,r]内有一个数a[i],a[i]不能整除 除去自身以外的其他的数,f(l,r ...

  8. hdu 5288 OO’s Sequence 枚举+二分

    Problem Description OO has got a array A of size n ,defined a function f(l,r) represent the number o ...

  9. HDU 5288 OO’s Sequence

    题意:给一个序列,函数f(l, r)表示在[l, r]区间内有多少数字不是其他数字的倍数,求所有区间的f(l, r)之和. 解法:第一次打多校……心里还有点小激动……然而一道签到题做了俩点……呜呜呜… ...

随机推荐

  1. poj 3187 Backward Digit Sums(穷竭搜索dfs)

    Description FJ and his cows enjoy playing a mental game. They write down the numbers to N ( <= N ...

  2. Collections.sort()

    Comparator是个接口,可重写compare()及equals()这两个方法,用于比价功能:如果是null的话,就是使用元素的默认顺序,如a,b,c,d,e,f,g,就是a,b,c,d,e,f, ...

  3. ibatis使用--SqlMapClient对象

    SqlMapClient对象 这个对象是iBatis操作数据库的接口(执行CRUD等操作),它也可以执行事务管理等操作.这个类是我们使用iBATIS的最主要的类.它是线程安全的.通常,将它定义为单例. ...

  4. BNU10806:请在此处签到

    每年圣诞,ZUN都会邀请很多人到幻想乡举行联欢,今年也不例外.在联欢前,所有人需要在自己的昵称旁签到(签全名),以示出席.然后ZUN 会把大家的签到表保存下来作为纪念,以激励来年努力工作.   昵称: ...

  5. Java_.jar .war .ear 详解

      .jar 全称:                     java archive: 包含:                     class.properties文件,是文件封装的最小单元: ...

  6. 破解Veeam过程

    1)运行Veeam_Backup_Setup.exe,但是不要继续下一步: 2)进入到%temp%\IXP000.TMP目录,例如windows xp sp3环境默认为C:\Documents and ...

  7. display:inline和display:inline-block的区别

    先来一张图: 测试代码: <!DOCTYPE html> <html> <head> <style> #bb { overflow: hidden; b ...

  8. Java 中关键字transient引出序列化与反序列化

    一:transient(临时的)关键字 1.transient关键字只能修饰变量,而不能修饰方法和类.注意,本地变量是不能被transient关键字修饰的. 2.被transient关键字修饰的变量不 ...

  9. JSON.stringify 语法实例讲解 字符串

    语法: JSON.stringify(value [, replacer] [, space]) var student = new Object(); student.name = "La ...

  10. WordPress插件制作教程(七): 插件函数之过滤器(Filter)函数

    上一篇对插件函数之动作(Action)函数做了下介绍,这篇在介绍下过滤器(Filters). 过滤器是一类函数,WordPress执行传递和处理数据的过程中,在针对这些数据做出某些动作之前的特定运行( ...