【数论,思路】HDU-5288;多校#1-1001
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的更多相关文章
- hdu 5288||2015多校联合第一场1001题
pid=5288">http://acm.hdu.edu.cn/showproblem.php?pid=5288 Problem Description OO has got a ar ...
- HDU 4696 Answers (2013多校10,1001题 )
Answers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total S ...
- 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 ...
- HDU 4666 Hyperspace (2013多校7 1001题 最远曼哈顿距离)
Hyperspace Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Tota ...
- 多校5 1001 HDU5781 ATM Mechine 记忆化搜索+概率
// 多校5 1001 HDU5781 ATM Mechine // http://acm.hdu.edu.cn/search.php?field=problem&key=2016+Multi ...
- 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 ...
- 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 ...
- 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 (2015多校第一场 二分查找)
OO's Sequence Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- HDU 4655 Cut Pieces(2013多校6 1001题 简单数学题)
Cut Pieces Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)Total ...
随机推荐
- AVD设置屏幕大小
相关资料: 1.http://jingyan.baidu.com/article/fedf0737775d2835ac897700.html
- 【C++专题】static_cast, dynamic_cast, const_cast探讨
首先回顾一下C++类型转换: C++类型转换分为:隐式类型转换和显式类型转换 第1部分. 隐式类型转换 又称为“标准转换”,包括以下几种情况:1) 算术转换(Arithmetic conversion ...
- CUDA常见问题之无法在c文件中调用cu文件中定义的函数
当在C源文件中调用cu文件中定义的函数时,会出现undefined reference的问题,而在C++源文件中调用cu文件中定义的函数时则不会出现这个问题. 出现上述问题的原因是,nvcc编译器采用 ...
- cookie.js 加载顺序问题
今天遇到一个问题,在使用cookie.js时,只有在jquery.js文件后加载整体才有效 有效加载顺序 <head> <script type="text/javascr ...
- java选项及系统属性
java选项 -d32 使用 32 位数据模型 (如果可用) -d64 使用 64 位数据模型 (如果可用) -server 选择 "server" VM 默认 VM 是 serv ...
- java获取照片相关属性
package test; import java.io.File; import java.util.Iterator; import com.drew.imaging.jpeg.JpegMetad ...
- Meta键盘
由于著名的编辑器Emacs中用到Meta键,但如今大多国人所用键盘上实际并无此键,想必多有不明之处,故多方收集资料撰写此文,简要描述了Meta键及相关键盘的发展始末,至于在Emacs上如何使用国人键盘 ...
- 错误内存【读书笔记】C程序中常见的内存操作有关的典型编程错误
题记:写这篇博客要主是加深自己对错误内存的认识和总结实现算法时的一些验经和训教,如果有错误请指出,万分感谢. 对C/C++程序员来讲,内存管理是个不小的挑战,绝对值得慎之又慎,否则让由上万行代码构成的 ...
- Codeforces Round #192 (Div. 1) A. Purification 贪心
A. Purification Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/329/probl ...
- Codeforces Round #326 (Div. 2) C. Duff and Weight Lifting 水题
C. Duff and Weight Lifting Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest ...