题意: 给你一个序列, 有一个函数 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&rsquo;s Sequence的更多相关文章

  1. HDU 5288 OO&#39;s sequence (2015多校第一场 二分查找)

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

  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(2015多校第一场第1题)枚举因子

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

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

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

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

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

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

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

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

随机推荐

  1. 函数式编程(九)——map,filter,reduce

    编程方法论: 面向过程:按照一个固定的流程去模拟解决问题的流程 函数式:编程语言定义的函数 + 数学意义的函数 y = 2*x + 1 函数用编程语言实现 def fun(x): return 2*x ...

  2. vue router.push(),router.replace(),router.go()

    1.router.push(location)=====window.history.pushState 想要导航到不同的 URL,则使用 router.push 方法.这个方法会向 history ...

  3. HSRP vs VRRP

    HSRP:(Hot Standby Router Protocol)-热备份路由协议 是cisco平台一种特有的技术,是cisco的私有协议. VRRP:(Virtual Router Redunda ...

  4. LVM基本概念及工作原理

    LVM基本概念及工作原理 背景知识: 一直困惑于LVM,特地找资料查了查,终于对LVM的概念和工作原理有了深入的理解.接下来记录下.新的技术出来必定是为了改变现有的不足,所以LVM的出现是由于对现有磁 ...

  5. 我的 $OI$, 退役前写点东西

    离 \(NOIp2018\) 还有五天, 总想写点什么 马上退役了啊 是什么时候喜欢上信息技术的呢 记不清了, 很小的时候就喜欢捣鼓关于电脑的东西 当时也不知道有算法这种东西 只是知道有黑客 巨 j8 ...

  6. 20190320 Dojo常用方法总结

    0. 使用环境 Dojo版本:1.14.2 此次总结以dojo的base为主,即不需要手动引入组件 1. 常用不归类方法 1.1. dojo.addOnLoad 在页面加载完成并且dojo.requi ...

  7. shell中的循环语法

    shell中的循环语法              作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.for循环 1.语法格式1 for 变量 in 值1 值2 值3 ... do ...

  8. CentOS 7使用yum安装MYSQL

    来源:https://typecodes.com/linux/yuminstallmysql5710.html wget -i http://dev.mysql.com/get/mysql57-com ...

  9. HDU - 3006 The Number of set(状态压缩位运算)

    http://acm.hdu.edu.cn/showproblem.php?pid=3006 题意 给定n个集合,每个集合都是由大于等于1小于等于m的数字组成,m最大为14.问由给出的集合可以组成多少 ...

  10. Elastic Job入门(3) - 集成Springboot

    引入pom文件 <dependency> <groupId>com.dangdang</groupId> <artifactId>elastic-job ...