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 ...
随机推荐
- C-基础:函数返回局部变量
一般的来说,函数是可以返回局部变量的. 局部变量的作用域只在函数内部,在函数返回后,局部变量的内存已经释放了.因此,如果函数返回的是局部变量的值,不涉及地址,程序不会出错.但是如果返回的是局部变量的地 ...
- Piston Pump Manufacturers - Mobile Cartridge Piston Pump: Advantages
The Piston Pump Manufacturers states that the operation of any piston pump is based on the rela ...
- HDU - 5438 Ponds(拓扑排序删点+并查集判断连通分量)
题目: 给出一个无向图,将图中度数小于等于1的点删掉,并删掉与他相连的点,直到不能在删为止,然后判断图中的各个连通分量,如果这个连通分量里边的点的个数是奇数,就把这些点的权值求和. 思路: 先用拓扑排 ...
- sin_addr.s_addr和sin_addr.S_un.S_addr
sin_addr.s_addr和sin_addr.S_un.S_addr 先mark一下,等下写
- openwrt procd分析
procd源码中有很多个main入口,有点懵,不知道procd之外的其他程序是干嘛的.先找资料大概了解了一下procd是什么,然后是守护进程,再然后是openwrt启动流程等等. openwrt启动流 ...
- Go:sync.Once 实现单例模式
代码: package main import ( "fmt" "sync" ) type Singleton struct{} var singleton * ...
- vue-loader 细节
vue-loader 能根据 .vue 文件,导入一个vue组件.我这里从 vue-cli 的构建项目中抽取了vue-loader 一个小例子出来:vuedemo/demo02 vue-loader ...
- hadoop上传文件报错
19/06/06 16:09:26 INFO hdfs.DFSClient: Exception in createBlockOutputStream java.io.IOException: Bad ...
- awk中RS,ORS,FS,OFS区别与联系
学习awk时,一定要记得动手去实践,只有在实践中才能发现问题,以下就我在学习中和实践中的经验,总结一下RS,ORS,FS,OFS的区别和联系. 一.OS和ORS 1.RS是记录分隔符,默认的分隔符是\ ...
- [转]Selenium-Webdriver系列Python版教程(1)————快速开始
elenium的历史,selenium2与WebDriver的关系本文就不讲了,想了解的同学们百度一下就可以Ok. 本系列教程是以Selenium-WebDriver的Python版本,首先从 ...