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

  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(计数)

    Problem Description OO has got a array A of size n ,defined a function f(l,r) represent the number o ...

  10. HDU 5288 OO’s Sequence

    题意:给一个序列,函数f(l, r)表示在[l, r]区间内有多少数字不是其他数字的倍数,求所有区间的f(l, r)之和. 解法:第一次打多校……心里还有点小激动……然而一道签到题做了俩点……呜呜呜… ...

随机推荐

  1. vue中nextTick

    vue中nextTick可以拿到更新后的DOM元素 如果在mounted下不能准确拿到DOM元素,可以使用nextTick 在Vue生命周期的created()钩子函数进行的DOM操作一定要放在Vue ...

  2. Ajax和Json实现自动补全

    1.index.jsp <%@ page language="java" import="java.util.*" pageEncoding=" ...

  3. Android Studio的project中两个build.gradle配置的区别

    一般创建一个android项目后回出现两个gradle: build.gradle(Project):用来配置整个工程的 build.gradle(app):一个是用来配置app的 对compile和 ...

  4. IIS服务器的安全保护措施

    转载自:https://www.williamlong.info/archives/118.html 部分内容做了修改. 通过标注Web服务器安全级别以及可用性的安全策略,网络管理员将能够从容地在不同 ...

  5. ubuntu 18.04//18.10&&windows 7/10双系统系统时间不一致

    新版本的Ubuntu使用systemd启动之后,时间也改成了由timedatectl来管理,因此网上的许多方法就不适用了. 经过测试发现下面的方法可以解决双系统时间不一致问题: 1.将硬件时间UTC改 ...

  6. ThinkPHP5基础学习(慕课版)

    一.thinkphp 5.0 的安装及配置 二.URL和路由 三.请求和相应 四.视图和模板 五.数据库的操作 六.模型的操作

  7. 上架一台Cisco防火墙及其架构

    领导给小白两条线,分别是电源线和网线,去吧,机房上架一台防火墙... 额, 然后小白抱着防火墙就去了...

  8. mui的switch开关的应用

    HTML: <!--mui的switch开关--> <div class="mui-content-padded"> <h5>switch开关m ...

  9. Path for IClasspathEntry must be absolute:

    关掉eclipse, 删除workspace工作目录下面的.metadata文件,看不到.metadata文件就 "ctril + H" 就可以看到了.然后重新打开eclipse, ...

  10. [kuangbin带你飞]专题一 简单搜索(回顾)

    A - 棋盘问题 POJ - 1321 注意条件:不能每放一个棋子,就标记一行和一列,我们直接枚举每一行就可以了. AC代码: #include<iostream> #include< ...