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. spring jpa data笔记

    tomcat启动Maven项目的时候总抛出这样的错误: Error creating bean with name 'org.springframework.boot.autoconfigure.or ...

  2. linux 服务器信息查看

    写项目总结报告,需要统计需要系统的配合 1.# uname -a   (Linux查看版本当前操作系统内核信息) Linux localhost.localdomain 2.4.20-8 #1 Thu ...

  3. hash算法散列算法

    Hash,一般翻译做“散列”,也有直接音译为“哈希”的,就是把任意长度的输入(又叫做预映射, pre-image),通过散列算法,变换成固定长度的输出,该输出就是散列值.这种转换是一种压缩映射,也就是 ...

  4. 基于pydash临控linux服务器

    pydash项目地址:https://github.com/k3oni/pydash 一.安装过程 1.安装pip dnf install git python-pip -ypip install v ...

  5. tensorflow BasicRNNCell调试

    运行以下代码,进入~/anaconda3/lib/python3.5/site-packages/tensorflow/python/ops/rnn.py和~/anaconda3/lib/python ...

  6. tomcat修改默认访问首页

    找到conf下server.xml文件修改如下位置内容 <Host name="localhost" appBase="webapps" unpackWA ...

  7. 2017.8.1 logstash基础语法学习

    数据类型 bool:debug => true string:host => "hostname" int:port => 514 array:match =&g ...

  8. notepad++ 在每一行最后加上逗号

    1.全选缩进对齐 2.替换功能,入下全部替换 3.在入下替换 4.结果 完成!

  9. modal html

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. Win10 导航窗口不能移动文件win10 资源管理器 无法拖动文件到左侧驱动器

    Win10 导航窗口不能移动文件怎么办 Win10左侧导航栏不能移动文件怎么办 win10 资源管理器 无法拖动文件到左侧驱动器怎么办 在同一个文件夹可以拖动来移动文件,拖到地址栏的面包屑也可以移动文 ...