• hdu 5288||2015多校联合第一场1001题


    http://acm.hdu.edu.cn/showproblem.php?pid=5288

    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
    /**
    hdu 5288||2015多校联合第一场1001题 
    题目大意:给定一个区间。找出f(i,j)的和
    解题思路:http://blog.sina.com.cn/s/blog_15139f1a10102vnx5.html 和官方题解想的一样
    */
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <vector>
    using namespace std;
    typedef __int64 LL;
    const int MAXN = 1e5+10;
    const LL MOD = 1e9+7;
    int a[MAXN],l,r,n;
    vector<int> f[10010];
    vector<int> vec[10010];
    typedef vector<int>::iterator it;
    
    int main()
    {
        for(int i=1; i<=10000; i++)
            for(int j=1; j*i<=10000; j++)
                f[i*j].push_back(i);
        while(~scanf("%d",&n))
        {
            for(int i=0; i<=10000; i++)
                vec[i].clear();
            for(int i=1; i<=n; i++)
            {
                scanf("%d",&a[i]);
                vec[a[i]].push_back(i);
            }
            LL ans=0;
            for(int i=1; i<=n; i++)
            {
                l=1,r=n;
                for(it j=f[a[i]].begin(); j!=f[a[i]].end(); j++)
                {
                    if(vec[*j].empty())continue;
                    it t=lower_bound(vec[*j].begin(),vec[*j].end(),i);
                    if(t==vec[*j].end())
                    {
                        t--;
                        l=max((*t)+1,l);
                        continue;
                    }
                    if(*t==i)
                    {
                        if(t!=vec[*j].begin())
                        {
                            t--;
                            l=max((*t)+1,l);
                            t++;
                        }
                        if(*t==i)t++;
                        if(t!=vec[*j].end())
                            r=min((*t)-1,r);
                    }
                    else
                    {
                        r=min((*t)-1,r);
                        if(t!=vec[*j].begin())
                        {
                            t--;
                            l=max((*t)+1,l);
                        }
                    }
                }
                ans = (ans + ((long long)(i - l+1) * (r - i+1) % MOD) ) % MOD;
            }
            printf("%I64d
    ",ans);
        }
        return 0;
    }
    


  • 相关阅读:
    TensorFlow Executor解析
    面试复习
    [洛谷]P1880 石子合并问题
    [西建大ACM协会]OJ平台如何使用
    [ACM] 相关OJ及在线运行代码网站
    [MySQL] Win10 安装MySQL5.7.27
    [PTA] PAT(A) 1012 The Best Rank (25 分)
    [PTA] PAT(A) 1011 World Cup Betting (20 分)
    [PTA] PAT(A) 1010 Radix (25 分)
    [PTA] PAT(A) 1009 Product of Polynomials (25 分)
  • 原文地址:https://www.cnblogs.com/zsychanpin/p/7239648.html
Copyright © 2020-2023  润新知