HDU 5288 OO’s Sequence
题意: 给你一个序列, 有一个函数 F(L,R) 其中 ai 均不能 被 aL … aR整除的 函数值是这个ai个数
思路 : 反过来求 满足这样的条件的 ai 的区间,然后求和
#include<iostream>
#include<vector>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef __int64 LL;
const int maxn = 100002;
const LL MOD = 1e9 + 7;
vector<int> Cnt[10005];
int Left[maxn], Right[maxn];
int Num[maxn],Vis[maxn];
int Scan()
{
int res = 0, ch, flag = 0; if((ch = getchar()) == '-') //判断正负
flag = 1; else if(ch >= '0' && ch <= '9') //得到完整的数
res = ch - '0';
while((ch = getchar()) >= '0' && ch <= '9' )
res = res * 10 + ch - '0'; return flag ? -res : res;
}
void Init() {
for(int i = 1; i <= 10005; ++i)
{
for(int j = 1; j <= i; ++j)
if(i % j == 0) Cnt[i].push_back(j);
}
}
int main() {
int n;
Init();
while(scanf("%d",&n) != EOF) {
for(int i = 0; i < n; ++i) Num[i] = Scan();
memset(Left,-1,sizeof(Left));
memset(Right,-1,sizeof(Right));
memset(Vis,-1,sizeof(Vis));
//GET LEFT
for(int i = 0; i < n; ++i) {
for(int j = 0; j < Cnt[Num[i]].size(); ++j) {
int tmp = Cnt[Num[i]][j];
if(Vis[tmp] != -1 && Num[i] % tmp == 0) {
if(Left[i] == -1) Left[i] = Vis[tmp] + 1;
else Left[i] = max(Left[i],Vis[tmp]+1);
}
}
Vis[Num[i]] = i;
}
//GET RIGHT
memset(Vis,-1,sizeof(Vis));
for(int i = n-1; i >= 0; --i) {
for(int j = 0; j < Cnt[Num[i]].size(); ++j) {
int tmp = Cnt[Num[i]][j];
if(Vis[tmp] != -1 && Num[i] % tmp == 0) {
if(Right[i] == -1) Right[i] = Vis[tmp] - 1;
else Right[i] = min(Right[i],Vis[tmp]-1);
}
}
Vis[Num[i]] = i;
}
for(int i = 0; i < n; ++i) {
if(Left[i] == -1) Left[i] = 0;
if(Right[i] == -1) Right[i] = n-1;
}
LL ans = 0;
for(LL i = 0; i < n; ++i) {
LL L = i - Left[i] + 1;
LL R = Right[i] - i + 1;
ans = (ans + L * R) % MOD;
}
printf("%I64d\n",ans);
}
}
HDU 5288 OO’s Sequence的更多相关文章
- HDU 5288 OO's sequence (2015多校第一场 二分查找)
OO's Sequence Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- 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 ...
- HDU 5288 OO‘s sequence (技巧)
题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=5288 题面: OO's Sequence Time Limit: 4000/2000 MS (Jav ...
- HDU 5288 OO’s Sequence 水题
OO's Sequence 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5288 Description OO has got a array A ...
- 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 ...
- HDU 5288——OO’s Sequence——————【技巧题】
OO’s Sequence Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
- Hdu 5288 OO’s Sequence 2015多小联赛A题
OO's Sequence Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- hdu 5288 OO’s Sequence(2015 Multi-University Training Contest 1)
OO's Sequence Time Limit: 4000/2000 MS (Jav ...
- 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 ...
随机推荐
- A1078. Hashing
The task of this problem is simple: insert a sequence of distinct positive integers into a hash tabl ...
- [luogu2114][起床困难综合症]
luogu2114 思路 因为位运算对于每一位是独立的,所以对每一位都对这n个数进行操作,然后观察最后得出的是1还是0.并且保证每一位拼起来之后要比m小. 代码 #include<cstdio& ...
- poj 2785(折半枚举+二分搜索)
传送门:Problem 2785 题意: 给定 n 行数,每行都有 4 个数A,B,C,D. 要从每列中各抽取出一个数,问使四个数的和为0的所有方案数. 相同数字不同位置当作不同数字对待. 题解: 如 ...
- PHP的内存限制 Allowed memory size of 134217728 bytes exhausted (tried to allocate 1099 bytes) in
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 1099 bytes) in Fa ...
- Machine Learning Netsite
Google: Machine Learning
- 紧急通知:Onion勒索病毒正在大范围传播!已有大量学生中招!(转)
在5月12日晚上20点左右,全国各地的高校学生纷纷反映,自己的电脑遭到病毒的攻击,文档被加密,壁纸遭到篡改,并且在桌面上出现窗口,强制学生支付等价300美元的比特币到攻击者账户上.我们的一位成员和其多 ...
- gradle执行test任务报错
起初报错内容: > Task :compileJava FAILEDC:\Users\x\eclipse-workspace\old_code\src\main\java\CookieDemo. ...
- Hadoop集群-HDFS集群中大数据运维常用的命令总结
Hadoop集群-HDFS集群中大数据运维常用的命令总结 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 本篇博客会简单涉及到滚动编辑,融合镜像文件,目录的空间配额等运维操作简介.话 ...
- Springmvc和poi3.9导出excel并弹出下载框
Springmvc 和 poi3.9 用java程序从数据库导出数据到excel(在博客园的第一篇原创博客) @RequestMapping(value = "/importexcel.ht ...
- Log4net(一)-——配置文件
一.Log4Net框架介绍 Log4net 是 Apache 下一个开放源码的项目,它是Log4j 的一个克隆版.Log4net中定义了多种日志信息输出模式.它可以根据需要将日志输出到控制台,文本文件 ...