码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 5288 OO’s Sequence(多校第一场1001)

时间:2015-07-22 13:25:43      阅读:130      评论:0      收藏:0      [点我收藏+]

标签:

OO’s Sequence

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 900    Accepted Submission(s): 339


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=1nj=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)
 

Output
For each tests: ouput a line contain a number ans.
 

Sample Input
5 1 2 3 4 5
 

Sample Output
23
 

Author
FZUACM
 

Source





#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

using namespace std;

int L[100100],R[100010];
int n;
int a[100010];
int visit[100100];

void updatalr()
{
    memset(visit,0,sizeof(visit));
    for(int i=1;i<=n;i++)
    {
        int maxx = 0;
        int t = sqrt(a[i]);
        for(int j=t;j>=1;j--)
        {
            if(a[i]%j == 0)
            {
                maxx = max(maxx,visit[j]);
                maxx = max(maxx,visit[a[i]/j]);
            }
        }
        L[i] = maxx;
        visit[a[i]] = i;
    }

   for(int i=0;i<100001;i++)
   {
       visit[i] = n + 1;
   }
    for(int i=n;i>=1;i--)
    {
        int minn = n+1;
        int t = sqrt(a[i]);
        for(int j=t;j>=1;j--)
        {
            if(a[i]%j == 0)
            {
                minn = min(minn,visit[j]);
                minn = min(minn,visit[a[i]/j]);
            }
        }
        R[i] = minn;
        visit[a[i]] = i;
    }
}

int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        __int64 sum = 0;
        memset(visit,0,sizeof(visit));
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
        }
        updatalr();
        for(int i=1;i<=n;i++)
        {
            __int64 LL = (__int64)(i - L[i]);
            __int64 RR = (__int64)(R[i] - i);
            sum = (sum + (LL*RR))%1000000007;
        }
        printf("%I64d\n",sum);
    }
    return 0;
}


 

版权声明:本文为博主原创文章,未经博主允许不得转载。

HDU 5288 OO’s Sequence(多校第一场1001)

标签:

原文地址:http://blog.csdn.net/yeguxin/article/details/46998903

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!