2015 Multi-University Training Contest 1  1001

 /*
Problem: HDU-5288,多校#1 1001
Tips: 数学。思路
Date: 2015.7.29
题意: 给出含n个元素的数组a,问所有区间中,满足对该区间所有aj(j!=i),都使ai%aj!=0的i的个数;
分析: 对于a[i],找到左右两边离它最近的因子的位置lp[i],rp[i],(没有的话就分别设为0/(n+1)),那么a[i]在仅会在(rp[i]-i)*(i-lp[i])个区间内出现
注意: 求lp, rp的算法,小心超时!
*/ #include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<map>
#include<cstring>
using namespace std;
typedef long long ll;
const int maxn = ;
const int M = ;
const ll MOD = ;
int n, a[maxn]; vector<int> fac[M];
int lp[maxn], rp[maxn], pre[M];
void get_fac() //储存1~10000所有数的因子
{
for(int i = ; i < M; i++)
for(int j = ; j*j <= i; j++)
if(i % j == )
{
if(j * j != i) fac[i].push_back(i / j);
fac[i].push_back(j);
}
} int main()
{
get_fac();
while(~scanf("%d", &n))
{
for(int i = ; i <= n; i++)
scanf("%d", &a[i]); memset(pre, , sizeof(pre));//pre数组记录数字i所在(上一个)位置
for(int i = ; i <= n; i++) //找左边因子位置
{
int u = a[i], pos = ; //pos记录左边最靠近i的因子位置
for(int j = ; j < fac[u].size(); j++)
{
int v = fac[u][j];
pos = max(pos, pre[v]);
}
lp[i] = pos;
pre[u] = i;
} memset(pre, 0x3f, sizeof(pre)); //pre数组记录数字i所在(上一个)位置
for(int i = n; i >= ; i--) //找右边因子位置
{
int u = a[i], pos = n+; //pos记录右边最靠近i的因子位置
for(int j = ; j < fac[u].size(); j++)
{
int v = fac[u][j];
pos = min(pos, pre[v]);
}
rp[i] = pos;
pre[u] = i;
} ll res = ;
for(int i = ; i <= n; i++)
{
res += (ll)((rp[i]-i) * (i-lp[i])) % MOD;
}
printf("%lld\n", res % MOD);
}
return ;
}

【数论,思路】HDU-5288;多校#1-1001的更多相关文章

  1. hdu 5288||2015多校联合第一场1001题

    pid=5288">http://acm.hdu.edu.cn/showproblem.php?pid=5288 Problem Description OO has got a ar ...

  2. HDU 4696 Answers (2013多校10,1001题 )

    Answers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total S ...

  3. HDU 4686 Arc of Dream (2013多校9 1001 题,矩阵)

    Arc of Dream Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Tota ...

  4. HDU 4666 Hyperspace (2013多校7 1001题 最远曼哈顿距离)

    Hyperspace Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Tota ...

  5. 多校5 1001 HDU5781 ATM Mechine 记忆化搜索+概率

    // 多校5 1001 HDU5781 ATM Mechine // http://acm.hdu.edu.cn/search.php?field=problem&key=2016+Multi ...

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

  7. 2015 多校赛 第一场 1001 (hdu 5288)

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

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

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

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

  10. HDU 4655 Cut Pieces(2013多校6 1001题 简单数学题)

    Cut Pieces Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total ...

随机推荐

  1. CodeForces 689C Mike and Chocolate Thieves (二分+数论)

    Mike and Chocolate Thieves 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/G Description ...

  2. CodeForces 682C Alyona and the Tree (树+dfs)

    Alyona and the Tree 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/C Description Alyona ...

  3. ecstore b2b2c 商城页面伪静态代码 及相关注意事项

    一下代码需要添加到 nginx.conf配置文件的server块,阿里云虚拟机一般在conf文件夹下建立vhost文件夹,把server块放进去,然后 在nginx.conf使用include 包含进 ...

  4. jQuery基础学习5——JavaScript方法获取页面中的元素

    给网页中的所有<p>元素添加onclick事件 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN& ...

  5. HDU 3666 THE MATRIX PROBLEM (差分约束)

    题意:给定一个最大400*400的矩阵,每次操作可以将某一行或某一列乘上一个数,问能否通过这样的操作使得矩阵内的每个数都在[L,R]的区间内. 析:再把题意说明白一点就是是否存在ai,bj,使得l&l ...

  6. POJ 3671 Dining Cows (DP,LIS, 暴力)

    题意:给定 n 个数,让你修改最少的数,使得这是一个不下降序列. 析:和3670一思路,就是一个LIS,也可以直接暴力,因为只有两个数,所以可以枚举在哪分界,左边是1,右边是2,更新答案. 代码如下: ...

  7. Javascript高级篇-Function对象

    1.引入 1.1Function是基于原型的对象 2.创建Function对象 2.1 var myFun = new Function("参数一","参数二" ...

  8. oracle ibatis 存储过程 返回游标 嵌套表

    自己解决问题了 问题总结: 1.index by表不能存储在数据库中的type中,故选择嵌套表. 2.ibatis不支持oracle的复合数据类型的返回.(个人理解) 3.替代方案:用返回oracle ...

  9. android知乎小圆圈刷新效果

    前几天看到包括知乎在内的很多应用都使用到了一种小圆圈划动刷新的效果,仔细查了一下,原来是android v7包里面最新的刷新效果.使用起来也是十分简单的. 首先先建立一个activity,在布局文件里 ...

  10. Winform开发框架之权限管理系统

    本文章转载:http://www.cnblogs.com/wuhuacong/archive/2011/05/08/2040620.html 至此,权限管理模块介绍已经完毕,下面给出一个调用例子Dem ...