浙江省赛 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 ...
随机推荐
- HDU 4318 Power transmission(最短路)
http://acm.hdu.edu.cn/showproblem.php?pid=4318 题意: 给出运输路线,每条路线运输时都会损失一定百分比的量,给定起点.终点和初始运输量,问最后到达终点时最 ...
- Centos 7下添加新用户并授权
1.创建一个 xiaoyang 用户 [root@VM_81_181_centos ~]# adduser xiaoyang 2.为创建的用户设置密码 [root@VM_81_181_centos ~ ...
- Win10远程桌面可能是由于CredSSP加密Oracle修正
win10更新1083之后,远程桌面就会连接失败,显示如下: 根据微软官方的说法是更改了安全策略: https://support.microsoft.com/zh-cn/help/4093492/c ...
- MVC ---- 去掉HTML过滤
在方法头上添加特效 [ValidateInput(false)] 富文本框提交的内容就可以顺利提交到后台了.
- UIUseImgWindow
using System;using UnityEngine;using UnityEngine.UI;using UnityEditor;using System.Collections;using ...
- 2017"百度之星"程序设计大赛 - 复赛 01,03,05
Arithmetic of Bomb Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- [原][粒子特效][spark]发射器emitter
深入浅出spark粒子特效连接:https://www.cnblogs.com/lyggqm/p/9956344.html group添加emitter的方式: eimtter: 上图是spark源码 ...
- 把查询的数据导出到elsx表 关于流的概念
1.获取到需要导出的数据 因为这个对象是PagedResulDto类型的 所以封装成Table的时候 传pageList.Items就可以了 PagedResultDto<Search ...
- Codeforces 1005 E2 - Median on Segments (General Case Edition)
E2 - Median on Segments (General Case Edition) 思路: 首先我们计算出solve(m):中位数大于等于m的方案数,那么最后答案就是solve(m) - s ...
- lua --- __newindex
-- __newindex 对表进行更新 MyMetatable = {} MyTable = }, {__newindex = MyMetatable}) MyTable.newKey1 = pri ...