浙江省赛 ZOJ4029
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的更多相关文章
- ZOJ 3879 Capture the Flag 15年浙江省赛K题
		
每年省赛必有的一道模拟题,描述都是非常的长,题目都是蛮好写的... sigh... 比赛的时候没有写出这道题目 :( 题意:首先输入4个数,n,q,p,c代表有n个队伍,q个服务器,每支队伍的初始分数 ...
 - The 13th Zhejiang Provincial Collegiate Contest(2016年浙江省赛)
		
前4道水题就不说了,其中我做了C题,1Y,小心仔细写代码并且提交之前得确认无误后提交才能减少出错率. 结果后面2题都由波神做掉,学长带我们飞~ 终榜 官方题解 ZOJ 3946 Highway ...
 - ZOJ 3872 Beauty of Array DP 15年浙江省赛D题
		
也是一道比赛时候没有写出来的题目,队友想到了解法不过最后匆匆忙忙没有 A 掉 What a pity... 题意:定义Beauty数是一个序列里所有不相同的数的和,求一个序列所有字序列的Beauty和 ...
 - (2017浙江省赛E)Seven Segment Display
		
Seven Segment Display Time Limit: 2 Seconds Memory Limit: 65536 KB A seven segment display, or ...
 - 浙江省赛 C What Kind of Friends Are You?
		
思路:一开始考虑n个朋友可以有c种可能,根据回答的问题,如果是yes那么可以确定一些朋友的范围,将原本不在这个范围内的删除即可:如果是"no",说明这些朋友都应该被删除,那么最后看 ...
 - 浙江省赛之Singing Everywhere
		
题目:http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5996 方法: 在大佬的指导下完成. 寻找峰值,找到一共k个 ...
 - 2019浙江省赛B zoj4101 Element Swapping(推公式)
		
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=6003 题意 \(数组a通过交换一对数字,得到了b数组,给出x=\sum^n_{ ...
 - 2019浙江省赛K zoj4110 Strings in the Pocket(manachar)
		
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=6012 题意 给你两个串,可以翻转a串的一个区间,问有多少对l,r使得翻转后的a ...
 - 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 ...
 
随机推荐
- Leetcode122-Best Time to Buy and Sell Stock II-Easy
			
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...
 - 恢复Intellij idea删除的文件
			
恢复Intellij idea的删除文件方法: 右键单机项目名称---->Local History---->Show History 可以看到历史操作记录,右键单机想要恢复的文件---- ...
 - mybatis 学习总结笔记Day2
			
在门外听到或看到一门技术,找资料入门,一看,嗯,不错,进门之后,发现,尼玛————,是片海,你是关门而出,还是学习精卫填海. 填海吧,也许只是个小水坑,稍加用点力,就填的7788了. 上一篇随笔中说了 ...
 - Qt532.线程(_beginthread)
			
1.(20180928)环境:Win7x64.Qt5.3.2 MSVC2010 OpenGL.ms2010 2.测试代码: ZC:我记得 之前在 VC6.vs08 上,还要选择 使用的是哪种 运行时线 ...
 - STL_string.ZC
			
1.转成 小写/大写 #include <algorithm>using namespace std; // 转成小写transform(_strAttrNameG.begin(), _s ...
 - [转][smart3d]Smart3D之手动配置 S3C 索引加载全部的OSGB瓦片数据
			
转自:https://blog.csdn.net/u013719339/article/details/77840728/ 一.须知: S3C是Smart3D内部格式,实质上是一个分块模型的索引,可以 ...
 - Vue项目中如何使用Element-UI以及如何使用sass
			
Vue项目中如何使用Element-UI以及如何使用sass 当我们在开发Vue项目的时候通常会选择Element-UI作为我们的UI框架,其官方中文文档地址是http://element.eleme ...
 - Zabbix报警执行远程命令
			
日常Zabbix报警案例中,大多都是报警发送邮件,场景里很少有需要报警后执行一个命令(启动服务.清空磁盘空间.关停服务器);而今天就给大家讲讲最近需要做的事:报警后执行远程命令 刚好zabbix动作中 ...
 - numpy函数
			
a=np.array([1,2,3,4,5,6]) a=a.reshape([2,-1]) # -1:表示3,此处将a数组设置为2行3列 a[1,2]=66 # 把a的6改成66 a=np ...
 - 牛客小白月赛7 B 自杀游戏
			
自杀游戏 思路: sg函数 代码: #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize(4) #include&l ...