浙江省赛 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 ...
随机推荐
- Leetcode167-Two Sum II Input array is sorted-Easy
Given an array of integers that is already sorted in ascending order, find two numbers such that the ...
- hdu 5120 Intersection 两个圆的面积交
Intersection Time Limit: 4000/4000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others) P ...
- C++图形开发相关
1. WxWidgets 2. GTK+ 3. U++ Framework 4. QT
- Django 国际化和本地化
所谓的国际化,是指使用不同语言的用户在访问同一个网站页面时能够看到符合其自身语言的文本页面. 国际化的基本原理是: 浏览器通过LANGUAGE_CODE在HTTP请求头中告诉网站后台服务器用户所需要的 ...
- Python Scrapy 爬取煎蛋网妹子图实例(二)
上篇已经介绍了 图片的爬取,后来觉得不太好,每次爬取的图片 都在一个文件下,不方便区分,且数据库中没有爬取的时间标识,不方便后续查看 数据时何时爬取的,所以这里进行了局部修改 修改一:修改爬虫执行方式 ...
- 第 6 章 存储 - 044 - volume 生命周期管理
volume 生命周期管理 1)备份 因为 volume 实际上是 host 文件系统中的目录和文件,所以 volume 的备份实际上是对文件系统的备份 例如:本地的Registry,所有镜像都存在/ ...
- 数据结构(C语言版)-第8章 排序
8.1 概述 1. 什么是排序? 将一组杂乱无章的数据按一定规律顺次排列起来. 2. 排序的目的是什么? ——便于查找! 3. 什么叫内部排序?什么叫外部排序? 若待排序记录都在内存中,称为内部排序 ...
- java8新特性: lambda表达式:直接获得某个list/array/对象里面的字段集合
java8新特性: lambda表达式:直接获得某个list/array/对象里面的字段集合 比如,我有一张表: entity Category.java service CategoryServic ...
- 雷林鹏分享:C# 结构(Struct)
C# 结构(Struct) 在 C# 中,结构是值类型数据结构.它使得一个单一变量可以存储各种数据类型的相关数据.struct 关键字用于创建结构. 结构是用来代表一个记录.假设您想跟踪图书馆中书的动 ...
- gem "ransack"(4000✨) 简单介绍
Object-based searching:演示. git: https://github.com/activerecord-hackery/ransack Gorails视频和我的博客记录:ht ...