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. JS字符串拼接优化

    // 请把以下用于连接字符串的JavaScript代码修改为更高效的方式 var htmlString = ‘ < div class=”container” > ’ + ‘ < u ...

  2. Java:单例模式的七种写法[转]

    第一种(懒汉,线程不安全):  1 public class Singleton {   2     private static Singleton instance;   3     privat ...

  3. Head First Html 与 Css 截图

    1.认识HTML web语言 2.深入了解超文本 HTML中的"HT" 3. 构建模块 web页面建设 4. 连接起来 5. 认识媒体,为页面添加图像 6. 严肃的HTML标准及其 ...

  4. 企业生产环境中linux系统分区的几种方案

    方案1:针对网站集群架构中的某个节点服务器分区 该服务器上的数据有多份(其他节点也有)且数据不太重要,建议分区方案如下: /boot: 200MB swap: 物理内存的1.5倍,当内存大于或等于8G ...

  5. android实现计算器功能

    设计一个简单的计算器. 第一个Activity的界面. 第二个Activity显示算式和计算结果. 第一个Activity代码: import android.app.Activity; import ...

  6. oracle数据库常用查询一

    oracle数据库常用查询一 sqlplus / as sysdba; 或sqlplus sys/密码 as sysdba;两者都是以sys登录.conn scott/tiger@orcl; conn ...

  7. Android调试系列—使用android studio调试smali代码

    1.工具介绍 使用工具 android killer:用于反编译apk包,得到smali代码 android studio:调试smali代码工具,或者使用idea,android studio就是在 ...

  8. Linux的用户和组

    1. 查看配置文件/etc/shadow第一行中root账号的第三个字段(以':'分隔)中的数字,请算一下这个数字是怎么来的?距离1970年1月1日到上次更改密码的时间的间隔天数.例如root密码日期 ...

  9. Windows消息机制(转)1

    Windows的应用程序一般包含窗口(Window),它主要为用户提供一种可视化的交互方式,窗口是总是在某个线程(Thread)内创建的.Windows系统通过消息机制来管理交互,消息(Message ...

  10. 查看Sql语句执行速度

    原文链接:http://www.cnblogs.com/New-world/archive/2012/11/28/2793560.htmlMS_SQL模糊查询like和charindex的对比 lik ...