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!!!的更多相关文章

  1. 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 ...

  2. Minieye杯第十五届华中科技大学程序设计邀请赛现场同步赛 I Matrix Again

    Minieye杯第十五届华中科技大学程序设计邀请赛现场同步赛 I Matrix Again https://ac.nowcoder.com/acm/contest/700/I 时间限制:C/C++ 1 ...

  3. 第七届河南省赛F.Turing equation(模拟)

    10399: F.Turing equation Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 151  Solved: 84 [Submit][St ...

  4. H-Modify Minieye杯第十五届华中科技大学程序设计邀请赛现场赛

    题面见 https://ac.nowcoder.com/acm/contest/700#question 题目大意是有n个单词,有k条替换规则(单向替换),每个单词会有一个元音度(单词里元音的个数)和 ...

  5. Minieye杯第十五届华中科技大学程序设计邀请赛网络赛 部分题目

    链接:https://pan.baidu.com/s/12gSzPHEgSNbT5Dl2QqDNpA 提取码:fw39 复制这段内容后打开百度网盘手机App,操作更方便哦 D    Grid #inc ...

  6. 福州大学第十五届程序设计竞赛_重现赛B题迷宫寻宝

    Problem B 迷宫寻宝 Accept: 52    Submit: 183Time Limit: 1000 mSec    Memory Limit : 32768 KB  Problem De ...

  7. 第十五届四川省省赛 SCU - 4444 Travel

    给你一个一共由两种边的完全图 要求你求1到N的最短路 q队列为前沿队列(已探索过且最外围的点)  p队列为未探索队列(未探索过的点) depth这个数组的用法并不是代表实际上这个点在第几层 而是防止死 ...

  8. 北京师范大学第十五届ACM决赛-重现赛J Just A String (kmp算法延伸)

    链接:https://ac.nowcoder.com/acm/contest/3/J 来源:牛客网 Just A String 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 2621 ...

  9. 北京师范大学第十五届ACM决赛-重现赛 B Borrow Classroom (树 ——LCA )

    链接:https://ac.nowcoder.com/acm/contest/3/B 来源:牛客网 Borrow Classroom 时间限制:C/C++ 3秒,其他语言6秒 空间限制:C/C++ 2 ...

随机推荐

  1. python脚本5_求素数

    #求素数 #素数:只能被1和它自己整除 n = int(input('Please input a number >>>')) flag = False for i in range ...

  2. Git GUI 的使用

    下面,我们开始使用Git Gui 如果你想init一个本地的git仓库,到你的代码根目录下,右键选择Git Init Here 这时,你会发现在代码根目录下,生成了一个.git的隐藏属性目录. 再选择 ...

  3. Eclipse中Preference打开后找不到Server项解决方案。

    该解决方案是假设你已经安装好了JDK,tomcat,eclipse,突然在Eclipse的配置时找不到选择菜单栏中的window——preferences-server——runtime enviro ...

  4. 【转】Chrome保存mht网页文件的方法 – 无需任何插件,完美!

    本帖原文地址: http://www.ihacksoft.com/chrome-save-mht.html 昨天晚上想要搞定一个 WordPress 自定义文章类型的问题,吃完晚饭后一直呆在办公室里研 ...

  5. iptables(二)iptables实际操作之规则查询

    如果你是一个新手,在阅读如下文章时,请坚持读到最后,读的过程中可能会有障碍,但是在读完以后,你会发现你已经明白了. 在进行iptables实验时,请务必在测试机上进行. 之前在iptables的概念中 ...

  6. 初识Linux(二)--命令行基本操作

    安装完Ubuntu后,进入系统,呈现在眼前的是Ubuntu的界面,跟windows的差不太多.一般操作系统包含GUI和CLI.GUI就是我们现在看到的,也是windows常用的直接用拖拽,点击等操作对 ...

  7. L126

    Like so many things, it is not what's outside, but what is inside that counts. 许多事物都是如此,外表看起來虽不起眼,但是 ...

  8. jdk1.8 HashMap 实现 数组+链表/红黑树

    转载至 http://www.cnblogs.com/leesf456/p/5242233.html 一.前言 在分析jdk1.8后的HashMap源码时,发现网上好多分析都是基于之前的jdk,而Ja ...

  9. Android 进阶8:进程通信之 Binder 机制浅析

    读完本文你将了解: IBinder Binder Binder 通信机制 Binder 驱动 Service Manager Binder 机制跨进程通信流程 Binder 机制的优点 总结 Than ...

  10. Angular提示文件不是一个有效的模块

    ERROR in src/app/app.component.ts(2,23): error TS2306: File '/home/jerry/angular/todo/src/app/model. ...