Now Loading!!!
Time Limit: Second Memory Limit: 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 Sample Output 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=;
const int mod=1e9;
int a[maxn],p[maxn],k[][maxn];
int n,m;
int main()
{
int t,flag[maxn],cnt;
scanf("%d",&t);
while(t--)
{
scanf("%d %d",&n,&m);
for(int i=; i<=n; i++)
scanf("%d",&a[i]);
sort(a+,a+n+);
for(int i=; i<=m; i++)
scanf("%d",&p[i]);
for(int i=; i<=; i++)
{
k[i][]=;
for(int j=; j<=n; j++)
{
k[i][j]=(k[i][j-]+(a[j]/i))%mod;
}
}
ll sum=,ans;
ll temp;
for(int i=; i<=m; i++)
{
temp=;
cnt=;
ans=;
while(temp*p[i]<=a[n])
{
temp*=p[i];
int l=,r=n;
while(l<=r)
{
int mid=(l+r)/;
if(a[mid]<=temp)
l=mid+;
else
r=mid-;
}
flag[++cnt]=r;
}
if(flag[cnt]<n)
flag[++cnt]=n;
for(int j=; j<=cnt; j++)
{
ans=(ans+(k[j][flag[j]]-k[j][flag[j-]]))%mod;
}
sum=(sum+ans*i)%mod;
}
printf("%lld\n",(sum+mod)%mod);
}
return ;
}

浙江省赛 ZOJ4029的更多相关文章

  1. ZOJ 3879 Capture the Flag 15年浙江省赛K题

    每年省赛必有的一道模拟题,描述都是非常的长,题目都是蛮好写的... sigh... 比赛的时候没有写出这道题目 :( 题意:首先输入4个数,n,q,p,c代表有n个队伍,q个服务器,每支队伍的初始分数 ...

  2. The 13th Zhejiang Provincial Collegiate Contest(2016年浙江省赛)

      前4道水题就不说了,其中我做了C题,1Y,小心仔细写代码并且提交之前得确认无误后提交才能减少出错率. 结果后面2题都由波神做掉,学长带我们飞~ 终榜 官方题解   ZOJ 3946 Highway ...

  3. ZOJ 3872 Beauty of Array DP 15年浙江省赛D题

    也是一道比赛时候没有写出来的题目,队友想到了解法不过最后匆匆忙忙没有 A 掉 What a pity... 题意:定义Beauty数是一个序列里所有不相同的数的和,求一个序列所有字序列的Beauty和 ...

  4. (2017浙江省赛E)Seven Segment Display

    Seven Segment Display Time Limit: 2 Seconds      Memory Limit: 65536 KB A seven segment display, or ...

  5. 浙江省赛 C What Kind of Friends Are You?

    思路:一开始考虑n个朋友可以有c种可能,根据回答的问题,如果是yes那么可以确定一些朋友的范围,将原本不在这个范围内的删除即可:如果是"no",说明这些朋友都应该被删除,那么最后看 ...

  6. 浙江省赛之Singing Everywhere

    题目:http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5996 方法: 在大佬的指导下完成. 寻找峰值,找到一共k个 ...

  7. 2019浙江省赛B zoj4101 Element Swapping(推公式)

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=6003 题意 \(数组a通过交换一对数字,得到了b数组,给出x=\sum^n_{ ...

  8. 2019浙江省赛K zoj4110 Strings in the Pocket(manachar)

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=6012 题意 给你两个串,可以翻转a串的一个区间,问有多少对l,r使得翻转后的a ...

  9. 140 - The 12th Zhejiang Provincial Collegiate Programming Contest(浙江省赛2015)

      Ace of Aces Time Limit: 2 Seconds      Memory Limit: 65536 KB There is a mysterious organization c ...

随机推荐

  1. 1.Jenkins 在windows下的安装与配置

    1. 安装Jenkins 1.war包安装:启动Jenkins命令,打开cmd至Jenkins安装目录下,运行命令 java -jar jenkins.war 如果改变默认端口,则指定端口例如端口号1 ...

  2. fee photo

    别样网 pexels Gratisography picjumbo lifeofpix foodiesfeed    

  3. 项目Alpha冲刺——代码规范、冲刺任务与计划

    作业要求 这个作业属于哪个课程 软件工程1916-W(福州大学) 这个作业要求在哪里 项目Alpha冲刺 团队名称 基于云的胜利冲锋队 项目名称 云评:高校学生成绩综合评估及可视化分析平台 这个作业的 ...

  4. _itemmod_hidden

    该表中的物品放在背包或银行中中会计算属性 `entry`物品ID `comment` 备注

  5. BZOJ 4826 【HNOI2017】 影魔

    题目链接:影魔 这道题就是去年序列的弱化版啊…… 我们枚举最大值的位置\(i\),找出左边第一个比\(a_i\)大的位置\(l\),右边第一个比\(a_i\)大的位置\(r\),然后我们分开考虑一下\ ...

  6. 数据库无法打开到SQL Server连接

    今天打开数据库,发现连接不上,弹出错误提示: 打开SQLServer Configuration Manager,发现SQL Server状态已经停止,双击启动弹出错误提示: 打开SQL Server ...

  7. Python—合并两个有序列表

    def hb(list1,list2): result = [] while list1 and list2: ] < list2[]: result.append(list1[]) del l ...

  8. 软件测试中Bug的生命周期以及Bug的严重等级

    软件测试中Bug的生命周期以及Bug的严重等级 我猜你们都会,但能说专业且全面不? 1.首先当测试人员接到一个项目或产品准备测试的时候,测试人员会根据测试用例一步步的来执行用例进行简单的功能测试.当测 ...

  9. CentOS6.5下搭建ftp服务器(三种认证模式:匿名用户、本地用户、虚拟用户)

    CentOS 6.5下搭建ftp服务器 vsftpd(very secure ftp daemon,非常安全的FTP守护进程)是一款运行在Linux操作系统上的FTP服务程序,不仅完全开源而且免费,此 ...

  10. module.exports小程序模块化,require

    小程序模块化 可以将一些公共的代码抽离成为一个单独的 js 文件,作为一个模块.模块只有通过 module.exports 或者 exports 才能对外暴露接口. tips:exports 是 mo ...