OO’s Sequence

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

Total Submission(s): 1751    Accepted Submission(s): 632

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
 
Recommend
We have carefully selected several similar problems for you:  5299 5298 5297 5296 

pid=5295" target="_blank" style="color:rgb(26,92,200); text-decoration:none">5295 

题意非常easy :求随意区间内满足条件的ai有多少个
假设依照题意 程序应该这样写:
四层循环 - - (不超时吃键盘)
尽管最后优化到 n^2/2也超时 数据太大了
#include<stdio.h>
int main()
{
int n,i,j,k,kk,a[100050];
while(scanf("%d",&n)!=EOF)
{
for(i=1; i<=n; i++)
scanf("%d",&a[i]);
long long suma=0;
for(i=1; i<=n; i++)
{
for(j=i; j<=n; j++)
{ for(k=i; k<=j; k++)//相当于i
{
int flag=0;
for(kk=i; kk <= j ; kk++)//相当于j
{
if(a[k]%a[kk] == 0 && k!=kk)
{
flag=1;
break;
}
}
if(flag!=1)
{
suma++;
suma%=100000007;
}
}
printf("%d %d=%d %d=%d\n",i,j,a[i],a[j],suma);
}
}
printf("%I64d\n",suma);
}
}

脑洞大开:换个思路是不是题意求的是找那些区间能满足第ai个值存在呢?

也就是说看ai能提供几个答案 

定义两个数组 l r 表示i数的左側和右側

最接近他的值且值是a[i]因子的数字的位置

那么第i个数字能提供的答案就是(r[i]-i) * (l[i]-i)

事实上这样的方法有漏洞 假设我给你 10w个1 程序就跪了 ╮(╯▽╰)╭  没有这数据 所以放心大胆的做吧
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
using namespace std;
const int M = 10e5 + 5;
const long mod = 1e9+7;
int vis[M],a[M],l[M],r[M];
int main()
{
int n;
while(~scanf("%d",&n))
{
memset(l,0,sizeof(l));
memset(r,0,sizeof(r));
memset(vis,0,sizeof(vis)); for(int i = 1;i <= n; ++i)
{
scanf("%d",&a[i]);
r[i] = n+1;
for(int j = a[i];j <= 10000; j+=a[i]) //找到离他近期的因子
{
if(vis[j])
{
r[vis[j]] = i;
vis[j] = 0;
}
}
vis[a[i]] = i;
}
memset(vis,0,sizeof(vis));
for(int i = n;i >= 1; --i)
{
for(int j = a[i];j <= 10000; j+=a[i])
{
if(vis[j])
{
l[vis[j]] = i;
vis[j] = 0;
}
}
vis[a[i]] = i;
} long long ans = 0;
for(int i = 1;i <= n; ++i)
{
ans = ((ans + (long long)(r[i]-i)*(long long)(i-l[i])%mod)%mod);
} printf("%I64d\n",ans);
}
}

Hdu 5288 OO’s Sequence 2015多小联赛A题的更多相关文章

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

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

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

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

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

  4. HDU 5288 OO’s Sequence 水题

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

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

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

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

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

  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. 洛谷——2871[USACO07DEC]手链Charm Bracelet——01背包

    题目描述 Bessie has gone to the mall's jewelry store and spies a charm bracelet. Of course, she'd like t ...

  2. 注册表数据提取工具RegRipper

    注册表数据提取工具RegRipper   注册表是Windows操作系统一个数据库,用来存储系统和应用程序设置信息.注册表信息分别保存在操作系统中的6个Hive文件中.获取这几个文件,就可以从中提取注 ...

  3. Mybatis中的XML中需要用到的转义符号整理

    使用这么久的Mybatis中需要转义的符号整理一下,小结一下: 1.       <         小于符号        < 2.       <=       小于等于     ...

  4. Bean的实例化--构造器

    1,编写Bean对象 package com.songyan.ico; public class Bean1 { } 2,配置xml <?xml version="1.0" ...

  5. XP右键菜单添加“打开所在文件夹”功能

    把以下文字保存为add.reg文件,双击后确定就可以了. REGEDIT4 [HKEY_CLASSES_ROOT\*\Shell\打开所在文件夹(&O)] [HKEY_CLASSES_ROOT ...

  6. python virtualenv virtualenvwrapper

    python中的virtualenv模块能够将项目环境分隔开,而不是使用全局的环境,非常实用. 首先pip install virtualenv 如何创建一个环境virtualenv testvir ...

  7. GPU hang

    最近做新项目 初期一直遇到个gpu hang的问题 就是command 提交过去gpu 就一直在那里 直到time out 也没什么别的错误提示 gpu debugger还抓不了 解决方案是 缩小之后 ...

  8. JSONUtil.bean2Json()报Property 'key' of class has no read method. SKIPPED的问题处理

    错误警告信息描述: net.sf.json.JSONObject.defaultBeanProcessing(JSONObject.java:) Property 'handler' of class ...

  9. ES6中的Map集合(与java里类似)

    Set类型可以用来处理列表中的值,但是不适用于处理键值对这样的信息结构.ES6也添加了Map集合来解决类似的问题 一.Map集合 JS的对象(Object),本质上是键值对的集合(Hash结构),但是 ...

  10. 使用websocket进行消息推送服务

    Websocket主要做消息推送,简单,轻巧,比comet好用 入门了解:https://www.cnblogs.com/xdp-gacl/p/5193279.html /** * A Web Soc ...