HDU 5288(OO’s Sequence-区间互质情况统计)
OO’s Sequence
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 2643 Accepted Submission(s): 925
In each test case:
First line: an integer n(n<=10^5) indicating the size of array
Second line:contain n numbers ai(0<ai<=10000)
5
1 2 3 4 5
23
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<iostream>
#include<cmath>
#include<cctype>
#include<ctime>
#include<vector>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=next[p])
#define Lson (x<<1)
#define Rson ((x<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (1000000007)
#define MAXN (1000000+10)
#define MAXn (1000000+10)
typedef long long ll;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return (a-b+llabs(a-b)/F*F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
int a[MAXn],n;
ll l[MAXN],r[MAXN];
ll al[MAXN],ar[MAXN];
int main()
{
// freopen("A.in","r",stdin);
// freopen(".out","w",stdout); while(scanf("%d",&n)==1)
{
ll ans=0;
For(i,n) scanf("%d",&a[i]);
MEM(l) MEMI(r)
For(i,n)
{
al[i]=0;
int p=a[i];
for(int j=1;(ll)j*j<=(ll)p;j++) {
if (p%j==0) al[i]=max(al[i],max(l[j],l[p/j]));
}
l[a[i]]=i;
} ForD(i,n)
{
ar[i]=n+1;
int p=a[i];
for(int j=1;(ll)j*j<=(ll)p;j++) {
if (p%j==0) ar[i]=min(ar[i],min(r[j],r[p/j]));
}
r[a[i]]=i;
} // For(i,n) cout<<al[i]<<' ';cout<<endl;
// For(i,n) cout<<ar[i]<<' ';cout<<endl;
// For(i,n)
upd(ans,mul(i-al[i],ar[i]-i));
cout<<ans<<endl;
} return 0;
}
HDU 5288(OO’s Sequence-区间互质情况统计)的更多相关文章
- 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 ...
- HDU 5288 OO’s Sequence 水题
OO's Sequence 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5288 Description OO has got a array A ...
- HDU 5288 OO‘s sequence (技巧)
题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=5288 题面: OO's Sequence Time Limit: 4000/2000 MS (Jav ...
- HDU 5288——OO’s Sequence——————【技巧题】
OO’s Sequence Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
- Hdu 5288 OO’s Sequence 2015多小联赛A题
OO's Sequence Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- hdu 5288 OO’s Sequence(2015 Multi-University Training Contest 1)
OO's Sequence Time Limit: 4000/2000 MS (Jav ...
- 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 枚举+二分
Problem Description OO has got a array A of size n ,defined a function f(l,r) represent the number o ...
- 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 ...
随机推荐
- 《3+1团队》【Alpha】Scrum meeting 1
项目 内容 这个作业属于哪个课程 任课教师博客主页链接 这个作业的要求在哪里 作业链接地址 团队名称 3+1团队 团队博客地址 https://home.cnblogs.com/u/3-1group ...
- 前端开发中的 meta 整理
meta是html语言head区的一个辅助性标签.也许你认为这些代码可有可无.其实如果你能够用好meta标签,会给你带来意想不到的效果,meta标签的作用有:搜索引擎优化(SEO),定义页面使用语言, ...
- Css选择器和JQuery基本编程接口
使用JQuery之前,首先从官网下载库文件 http://jquery.com/ jquery-2.1.4.js和jquery-2.1.4.min.js,前者是完整无压缩版本,用于开发调试:后者是压缩 ...
- mysql 报错Authentication method 'caching_sha2_password' is not supported
原文地址:https://blog.csdn.net/u011583336/article/details/80999043 之前工作中用的数据库多是ms sqlserver,偶尔用到mysql都是运 ...
- validate 常用的输入框校验
记录一下angular可以直接用的输入框校验器,外加一个国内手机号码的校验 <!DOCTYPE html> <html> <head> <meta chars ...
- 由Java实现Valid Parentheses
一.题目 Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the ...
- 【HDU 6005】Pandaland(Dijkstra)
Problem Description Mr. Panda lives in Pandaland. There are many cities in Pandaland. Each city can ...
- POJ 2728 Desert King(最优比率生成树, 01分数规划)
题意: 给定n个村子的坐标(x,y)和高度z, 求出修n-1条路连通所有村子, 并且让 修路花费/修路长度 最少的值 两个村子修一条路, 修路花费 = abs(高度差), 修路长度 = 欧氏距离 分析 ...
- LR性能测试问题解决方法
一.Error -27727: Step download timeout (120 seconds)has expired when downloading resource(s). Set the ...
- SQL中varchar和nvarchar的基本介绍及其区别
SQL中varchar和nvarchar的基本介绍及其区别 varchar(n) 长度为 n 个字节的可变长度且非 Unicode 的字符数据.n 必须是一个介于 1 和 8,000 之间的数值.存储 ...