第十五届浙江省赛 F Now Loading!!!
Now Loading!!!
Time Limit: 1 Second Memory Limit: 131072 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
2
3 2
100 1000 10000
100 10
4 5
2323 223 12312 3
1232 324 2 3 5
Sample Output
11366
45619
题解:
对于a^n+1与a^(n+),以a为底取log向上取整后是一样的。
因此可以按区间计算,然后二分查找区间。
注意:先除在求和与先求和在除是不一样的,赛场上没想到
这一点导致这题没过。
代码:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=;
const int mod=1e9;
ll a[maxn];
int b[maxn][];
int main()
{
int T;scanf("%d",&T);
while(T--)
{
int n,m;scanf("%d%d",&n,&m);
ll ma=,ans=;
for(int i=;i<=n;i++)
{
scanf("%lld",&a[i]);
ma=max(ma,a[i]);
}
sort(a+,a+n+);
for(ll i=;i<;i++)
{
for(int j=;j<=n;j++)
b[j][i]=(b[j-][i]+a[j]/i)%mod;
}
for(int i=;i<=m;i++)
{
ll x;scanf("%lld",&x);
bool bb=;ll sum=;
int a1=;
for(ll j=,k=;;k++)
{
if(j<=ma)j=j*x;
else break;
int id=upper_bound(a+a1,a+n+,j)-a-;
sum=(sum+b[id][k]-b[a1-][k])%mod;
if(sum<)sum+=mod;
a1=id+;
}
ans=(ans+i*sum)%mod;
}
printf("%lld\n",ans);
}
return ;
}
第十五届浙江省赛 F Now Loading!!!的更多相关文章
- ZOJ 3781 - Paint the Grid Reloaded - [DFS连通块缩点建图+BFS求深度][第11届浙江省赛F题]
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3781 Time Limit: 2 Seconds Me ...
- Minieye杯第十五届华中科技大学程序设计邀请赛现场同步赛 I Matrix Again
Minieye杯第十五届华中科技大学程序设计邀请赛现场同步赛 I Matrix Again https://ac.nowcoder.com/acm/contest/700/I 时间限制:C/C++ 1 ...
- 第七届河南省赛F.Turing equation(模拟)
10399: F.Turing equation Time Limit: 1 Sec Memory Limit: 128 MB Submit: 151 Solved: 84 [Submit][St ...
- H-Modify Minieye杯第十五届华中科技大学程序设计邀请赛现场赛
题面见 https://ac.nowcoder.com/acm/contest/700#question 题目大意是有n个单词,有k条替换规则(单向替换),每个单词会有一个元音度(单词里元音的个数)和 ...
- Minieye杯第十五届华中科技大学程序设计邀请赛网络赛 部分题目
链接:https://pan.baidu.com/s/12gSzPHEgSNbT5Dl2QqDNpA 提取码:fw39 复制这段内容后打开百度网盘手机App,操作更方便哦 D Grid #inc ...
- 福州大学第十五届程序设计竞赛_重现赛B题迷宫寻宝
Problem B 迷宫寻宝 Accept: 52 Submit: 183Time Limit: 1000 mSec Memory Limit : 32768 KB Problem De ...
- 第十五届四川省省赛 SCU - 4444 Travel
给你一个一共由两种边的完全图 要求你求1到N的最短路 q队列为前沿队列(已探索过且最外围的点) p队列为未探索队列(未探索过的点) depth这个数组的用法并不是代表实际上这个点在第几层 而是防止死 ...
- 北京师范大学第十五届ACM决赛-重现赛J Just A String (kmp算法延伸)
链接:https://ac.nowcoder.com/acm/contest/3/J 来源:牛客网 Just A String 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 2621 ...
- 北京师范大学第十五届ACM决赛-重现赛 B Borrow Classroom (树 ——LCA )
链接:https://ac.nowcoder.com/acm/contest/3/B 来源:牛客网 Borrow Classroom 时间限制:C/C++ 3秒,其他语言6秒 空间限制:C/C++ 2 ...
随机推荐
- Codeforces Round #451 (Div. 2)
水题场.... 结果因为D题看错题意,B题手贱写残了...现场只出了A,C,E A:水题.. #include<bits/stdc++.h> #define fi first #defin ...
- pdb 源码索引符号服务器创建过程
pdb是调试程序必不可少的东西,它保存着一个exe或dll的调试信息,对pdb进行源码索引可以快速找到软件对应该版本的代码,本文以subversion版本控制服务器进行介绍 一.需要安装的软件 win ...
- 【lightoj-1039】A Toy Company(BFS)
The toy company "Babies Toys" has hired you to help develop educational toys. The current ...
- python基础之socket编程(二)
ssh远程执行命令: 思路分析: 客户端给服务端发送命令,服务端返回一个输出结果传给客户端. #coding:utf-8 #买手机 import socket import struct import ...
- TF随笔-4
>>> import tensorflow as tf>>> a=tf.constant([[1,2],[3,4]])>>> b=tf.const ...
- Django应用部署
前言 Apachewsgi 环境搭建 安装Apache 安装mod_wsgi 添加djangowsgi文件 配置etcapache2httpdconf wsgipy配置 跑起来吧 uWSGI 环境搭建 ...
- 你真的对java static了解吗,代码优化可能更加简单
static修饰的成员变量和成员方法独立于该类的任何对象.也就是说,它不依赖类特定的实例,被类的所有实例共享. 只要这个类被加载,Java虚拟机就能根据类名在运行时数据区的方法区内定找到他们.因此,s ...
- 演示使用Metasploit入侵Windows
我使用Kali Linux的IP地址是192.168.0.112:在同一局域网内有一台运行Windows XP(192.168.0.108)的测试电脑. 本文演示怎么使用Metasploit入侵win ...
- 【工作】to-do-list
当你不确定的时候,你就把你所在的工作做好,所在的你不愿意的行业做好,所谓的自由选择,它本身不自由的,不自由过程当中,如何你把它做好,就做人生的一个经历,人生的一个积累.-- 王石 TODO
- STL源码解析之vector自实现
最近仔细阅读了下侯捷老师的<STL源码剖析>的前三章内容:空间配置器.迭代器.traits技术,为了加强理解和掌握,特参照源码自实现Vector,以下对相关重点知识进行说明. 1. vec ...