浙江省赛 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 ...
随机推荐
- 51nod 1275 连续字段的差异(单调队列)
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1275 题意: 思路: 固定某个端点,然后去寻找满足能满足要求的最大区间, ...
- MySQL数据库自动备份
1.vi /home/wangcn/auto_log.sh#!/bin/bash #Shell Command For Backup MySQL Database Everyday Automatic ...
- pipenv安装.whl
windows下很多库安装不方便,主要是编译C之类的. 之前这样做: 1去https://www.lfd.uci.edu/~gohlke/pythonlibs/ 下载各种版本编译好的.whl 2 pi ...
- LeetCode第[20]题(Java):Valid Parentheses
题目:有效的括号序列 难度:Easy 题目内容: Given a string containing just the characters '(', ')', '{', '}', '[' and ' ...
- Linux 安装SSH
●centOS/redhat安装SSH 查询openssh server服务状态:systemctl status sshd 安装sshd命令: yum install openssh-server ...
- [C#]获取指定文件夹下的所有文件名(递归)
典型的递归方法: //定义一个list集合 List<String> list = new List<String>(); public void director(strin ...
- Memcached遇到的问题及解决办法
1. memcached make: *** No targets specified and no makefile found. Stop. 其实是因为在安装libevent时增加了版本号导致的, ...
- Solaris 10 disable ipv6
亲测有效:) http://thegeekdiary.com/how-to-remove-ipv6-in-solaris-11/
- Backup and Recovery Types
Physical(Raw) and Logical Backup: 1.Physical backups consist of raw copies of the directories and fi ...
- 常见的ORACLE语句
基本 --新建表: create table table1( id varchar(300) primary key, name varchar(200) not null); --插入数据 inse ...