zoukankan      html  css  js  c++  java
  • 浙江省赛 ZOJ4029

    Now Loading!!!
    Time Limit: 1 Second      Memory Limit: 131072 KB
    DreamGrid has  integers . DreamGrid also has  queries, and each time he would like to know the value of
    for a given number , where , .
    
    Input
    There are multiple test cases. The first line of input is an integer  indicating the number of test cases. For each test case:
    
    The first line contains two integers  and  () -- the number of integers and the number of queries.
    
    The second line contains  integers  ().
    
    The third line contains  integers  ().
    
    It is guaranteed that neither the sum of all  nor the sum of all  exceeds .
    
    Output
    For each test case, output an integer , where  is the answer for the -th query.
    
    Sample Input
    2
    3 2
    100 1000 10000
    100 10
    4 5
    2323 223 12312 3
    1232 324 2 3 5
    Sample Output
    11366
    45619
    Author: LIN, Xi
    Source: The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple
    Submit    Status

    这题前缀和+二分

    我们发现分母只有1-30;

    我们构造一个sum/i(i-30)

    二分查找 a^(i -1)<p<a^(i)  分母 就是 i 

    你就把a[i]分成30段。

    用flag 去保存位子。

    每一段就是 k[j][flag[j]]-k[j][flag[j-1]]

    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<iostream>
    #include<algorithm>
    using namespace std;
    typedef long long ll;
    const int maxn=500005;
    const int mod=1e9;
    int  a[maxn],p[maxn],k[35][maxn];
    int n,m;
    int main()
    {
        int t,flag[maxn],cnt;
        scanf("%d",&t);
        while(t--)
        {
            scanf("%d %d",&n,&m);
            for(int i=1; i<=n; i++)
                scanf("%d",&a[i]);
            sort(a+1,a+n+1);
            for(int i=1; i<=m; i++)
                scanf("%d",&p[i]);
            for(int i=1; i<=30; i++)
            {
                k[i][0]=0;
                for(int j=1; j<=n; j++)
                {
                    k[i][j]=(k[i][j-1]+(a[j]/i))%mod;
                }
            }
            ll sum=0,ans;
            ll temp;
            for(int i=1; i<=m; i++)
            {
                temp=1;
                cnt=0;
                ans=0;
                while(temp*p[i]<=a[n])
                {
                    temp*=p[i];
                    int l=1,r=n;
                    while(l<=r)
                    {
                        int mid=(l+r)/2;
                        if(a[mid]<=temp)
                            l=mid+1;
                        else
                            r=mid-1;
                    }
                    flag[++cnt]=r;
                }
                if(flag[cnt]<n)
                    flag[++cnt]=n;
                for(int j=1; j<=cnt; j++)
                {
                    ans=(ans+(k[j][flag[j]]-k[j][flag[j-1]]))%mod;
                }
                sum=(sum+ans*i)%mod;
            }
            printf("%lld
    ",(sum+mod)%mod);
        }
        return 0;
    }
  • 相关阅读:
    FreeRTOS之源码 及 移植详解
    FreeRTOS之Tracealyzer for FreeRTOS(FreeRTOS+Trace) 详解(源码解析+移植)
    FreeRTOS之全配置项详解、裁剪(FreeRTOSConfig.h)
    linux下安装oracle中遇到的一些问题
    RedHat Enterprise Linux 6 配置Xmanager ,实现图形界面连接
    Linux ext2/ext3文件系统详解
    对固态硬盘ssd进行4k对齐
    在CentOs6.5安装jdk
    Android的API版本和名称对应关系
    Java反射机制及Method.invoke详解
  • 原文地址:https://www.cnblogs.com/2014slx/p/9007556.html
Copyright © 2011-2022 走看看