题意: 给你一个序列, 有一个函数 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. 几个简单常用的Sql语句

    '; --查Cids为2的Gnumber列的和,列名为Ids select Cids,Plevel from People; select * from Salary; select * from S ...

  2. [luogu2657][windy数]

    luogu2657 思路 数位dp,记录下上个位置的数,如果当前的数字与上个数字的差值小于2,就不再转移.还是要注意排除前导0.在记忆化的时候,全都是前导0的情况不能记忆化. 代码 #include& ...

  3. 装饰页面decorators.xml

    WEB-INF/decorators.xml 这个配置可以增加页面的 装饰页面

  4. 线程的状态有哪些,线程中的start与run方法的区别

    线程在一定条件下,状态会发生变化.线程一共有以下几种状态: 1.新建状态(New):新创建了一个线程对象. 2.就绪状态(Runnable):线程对象创建后,其他线程调用了该对象的start()方法. ...

  5. C# 多窗体之间方法调用

    看似一个简单的功能需求,其实很多初学者处理不好的,很多朋友会这么写: //父窗体是是frmParent,子窗体是frmChildA //在父窗体中打开子窗体 frmChildA child = new ...

  6. 记一次B站答题经历

    第一题部分:社区规范卷 --------- ------------ 第二题:社区规范第二部分 -------------------- 第三部分自由选择题 --------------------- ...

  7. eclipse中编辑properties文件无法看到中文

    如果在eclipse中编辑properties文件无法看到中文则参考“Eclipse开发环境配置-indigo.docx”添加propedit插件.

  8. MySQL_DDL(不定时更新)

    1. //1.创建数据库,并指定字符集为utf8 create database rocker_oa default character set utf8; //2.创建用户,并指定密码为‘root’ ...

  9. 阿里巴巴为什么不用 ZooKeeper 做服务发现?

    阿里巴巴为什么不用 ZooKeeper 做服务发现? http://jm.taobao.org/2018/06/13/%E5%81%9A%E6%9C%8D%E5%8A%A1%E5%8F%91%E7%8 ...

  10. android 简单的画图片

    layout: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns: ...