hdu5288 OO’s Sequence 二分 多校联合第一场
来源:互联网 发布:声卡mc录音软件 编辑:程序博客网 时间:2024/05/21 11:06
OO’s Sequence
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 42 Accepted Submission(s): 21
Problem Description
OO has got a array A of size n ,defined a function f(l,r) represent the number of i (l<=i<=r) , that there's no j(l<=j<=r,j<>i) satisfy ai mod aj=0,now OO want to know∑i=1n∑j=inf(i,j) mod (109+7).
Input
There are multiple test cases. Please process till EOF.
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)
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)
Output
For each tests: ouput a line contain a number ans.
Sample Input
51 2 3 4 5
Sample Output
23
对每个区间这种数的个数求和,这种数满足在这个区间内没有数能被它整除,不包括它本身。
因为a最大10000,我的做法是用vector记录下每个数出现的位置,再枚举每个数,看它在多少个区间内满足条件,枚举的过程是求这个数所有的因子,二分这个因子出现在这个数左边最右的位置和这个数右边最左的位置,最后得到这个数能延伸到的最远的左右区间,这个区间内没有数能被这个数整除。如果这个数的位置是i,左区间是l,右区间是r,则对于这个数共有(i-l)*(r-i)种区间满足。
#include<iostream>#include<cstdio>#include<string>#include<cstring>#include<cmath>#include<vector>#include<algorithm>using namespace std;typedef long long LL;const LL INF=0x3f3f3f3f;const LL MAXN=100010;const LL MOD=1e9+7;LL N;LL a[MAXN];vector<LL> V[10010];int main(){ freopen("in.txt","r",stdin); while(scanf("%I64d",&N)!=EOF){ for(LL i=0;i<=10000;i++) V[i].clear(); for(LL i=1;i<=N;i++){ scanf("%I64d",&a[i]); V[a[i]].push_back(i); } for(LL i=0;i<=10000;i++) sort(V[i].begin(),V[i].end()); LL ans=0; for(LL i=1;i<=N;i++){ LL n=a[i]; LL m=sqrt(n)+1; LL l=0,r=N+1; for(LL j=1;j<=m;j++){ if(n%j==0){ if(V[j].size()>0){ LL pos=lower_bound(V[j].begin(),V[j].end(),i)-V[j].begin(),pos2=upper_bound(V[j].begin(),V[j].end(),i)-V[j].begin(); if(pos>0) l=max(l,V[j][pos-1]); if(pos2<V[j].size()) r=min(r,V[j][pos2]); } LL t=n/j; if(V[t].size()>0){ LL t=n/j; LL pos=lower_bound(V[t].begin(),V[t].end(),i)-V[t].begin(),pos2=upper_bound(V[t].begin(),V[t].end(),i)-V[t].begin(); if(pos>0) l=max(l,V[t][pos-1]); if(pos2<V[t].size()) r=min(r,V[t][pos2]); } } } if(l<i&&r>i) ans=(ans+(r-i)*(i-l))%MOD; } printf("%I64d\n",ans); } return 0;}
0 0
- hdu5288 OO’s Sequence 二分 多校联合第一场
- 2015年多校联合训练第一场OO’s Sequence(hdu5288)
- HDU5288 OO’s Sequence 二分
- HDU5288.OO’s Sequence(多校第一题)
- HDU5288 OO’s Sequence
- HDU5288 OO’s Sequence
- hdu5288 OO’s Sequence
- HDU 5288 OO's sequence (2015多校第一场 二分查找)
- hdu5288 多校联合第一场第一题
- 【思路题】【多校第一场】【1001.OO’s Sequence】
- 2015多校第一场 hdu 5288 OO’s Sequence
- 【多校第一场】【筛法改】HDU 5288 OO’s Sequence
- OO’s Sequence(多校第一场A题)
- hdu5288 OO’s Sequence(质因子分解+二分)
- 搜索 - hdu5288 OO’s Sequence
- [杂题] HDU5288: OO’s Sequence
- 2015多校联合第一场hdu5288OO’s Sequence
- hdu5288(2015多校1)OO’s Sequence
- 从哈希到布隆过滤器
- 关于mysql主从复制error_code 1593的小异常BUG
- gcc 命令 http://www.cnblogs.com/ggjucheng/archive/2011/12/14/2287738.html
- 获取手机IP地址
- Linux-git简明教程(一)
- hdu5288 OO’s Sequence 二分 多校联合第一场
- java怎样实现线程的同步
- juke项目
- 10个Redis技巧
- [MFC]传统控件介绍、CButton按钮类
- 字符串匹配——朴素算法
- openmesh中常用的几个文件夹
- Swift学习笔记(一)基础操作
- iOS开发学习之Json解析