ZOJ 3940 Modulo Query
0--M对某个数字取模,相当于把0--M区间进行切割,每次暴力切割一下。结果的算的时候二分一下即可。。。
看了官方题解才会。。。
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std; const int maxn=+;
long long mod=1e9+;
int T,m,sz;
struct X
{
int x;
long long y;
bool operator<(const X&a)const
{
return x < a.x;
}
X(int a,long long b) {x=a,y=b;}
};
long long sum[maxn],cnt[maxn];
int v[maxn]; long long get(int now)
{
long long res=;
int l=,r=sz-;
while(l<=r)
{
int mid=(l+r)/;
if(v[mid]>=now)
{
l=mid+;
res=sum[mid];
}
else r=mid-;
}
return res;
} int main()
{
scanf("%d",&T);
while(T--)
{
int n; scanf("%d%d",&n,&m);
priority_queue<X>q;
q.push(X(m,));
for(int i=;i<=n;i++)
{
int x; scanf("%d",&x);
while()
{
if(q.top().x<x) break;
X head=q.top(); q.pop();
q.push(X(x-, (head.x + ) / x*head.y));
if ((head.x+)%x>=) q.push(X(head.x%x, head.y));
}
} sz=;
v[sz]=q.top().x; cnt[sz]=q.top().y;
q.pop(); sz++; while(!q.empty())
{
X head=q.top(); q.pop();
if(head.x==v[sz-]) cnt[sz-]+=head.y;
else
{
v[sz]=head.x;
cnt[sz]=head.y;
sz++;
}
} sum[]=cnt[];
for(int i=;i<sz;i++) sum[i]=sum[i-]+cnt[i]; int Q; scanf("%d",&Q);
long long ans=;
for(long long i=;i<=Q;i++)
{
int g; scanf("%d",&g);
ans=(ans+i*get(g)%mod)%mod;
} printf("%lld\n",ans%mod);
}
return ;
}
ZOJ 3940 Modulo Query的更多相关文章
- ZOJ 3940 Modulo Query(YY+二分)
Modulo Query Time Limit: 2 Seconds Memory Limit: 65536 KB One day, Peter came across a function ...
- ZOJ 3940 Modulo Query (2016年浙江省赛E题,区间折叠 + map运用)
题目链接 2016 ZJCPC Problem E 考虑一个开区间$[0, x)$对$a_{i}$取模的过程. $[0, x)$中小于$a_{i}$的部分不变,大于等于$a_{i}$的部分被切下来变 ...
- ZOJ 3911 Prime Query ZOJ Monthly, October 2015 - I
Prime Query Time Limit: 1 Second Memory Limit: 196608 KB You are given a simple task. Given a s ...
- ZOJ 3911 Prime Query(线段树)
Prime Query Time Limit: 1 Second Memory Limit: 196608 KB You are given a simple task. Given a s ...
- ZOJ 5638——Prime Query——————【线段树区间更新,区间查询,单点更新】
Prime Query Time Limit: 1 Second Memory Limit: 196608 KB You are given a simple task. Given a s ...
- 2016.4.23浙江省赛(zoj3936 zoj3938 zoj3940 zoj3944 zoj3946 zoj3947 )
A Apples and Ideas Time Limit: 2 Seconds Memory Limit: 65536 KB "If you have an apple ...
- Prime Query (ZOJ 3911 线段树)
Prime Query Time Limit: 1 Second Memory Limit: 196608 KB You are given a simple task. Given a sequen ...
- 143 - ZOJ Monthly, October 2015 I Prime Query 线段树
Prime Query Time Limit: 1 Second Memory Limit: 196608 KB You are given a simple task. Given a s ...
- ZOJ 3911Prime Query [素数处理 + 线段树]
Time Limit: 5 Seconds Memory Limit: 196608 KBYou are given a simple task. Given a sequence A[i] with ...
随机推荐
- json的引号之伤
最近读他们的jquery解读的源码,由于版本不同,我可能看的是他们解读的1.7的,但是我本身运行的可能是1.9的,所以有些出处,但是中心思想不变,我有疑问的时候,直接debug,让例子自己走一遍,好处 ...
- 使用dom4j解析XML例子
包括三个文件:studentInfo.xml(待解析的xml文件), Dom4jReadExmple.java(解析的主要类), TestDom4jReadExmple.java(测试解析的结果) 代 ...
- GCD is Funny
GCD is Funny Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Pro ...
- Java获取来访者IP
在JSP里,获取客户端的IP地址的方法是:request.getRemoteAddr(),这种方法在大部分情况下都是有效的.但是在通过了Apache,Squid等反向代理软件就不能获取到客户端的真实I ...
- java 文件字节输入流
Example10_4.java import java.io.*; public class Example10_4 { public static void main(String args[]) ...
- 用Visual Studio 2015 编写驱动之前一定要注意的问题!!!
如果你确定要使用Visual Studio 2015 编写驱动,那么在你安装Visual Studio 2015 和WDK之前,一定一定要注意一件事情,那就是确保SDK和WDK版本保持一致,切记切记! ...
- nginx slab内存管理
本来这一篇作为nginx系列的开头是不合适的,不过由于nginx进程框架自己的梳理还没完成,这部分又刚好整理完了,就从这开始吧.这儿谈的是nginx的slab的内存管理方式,这种方式的内存管理在ngi ...
- zencart hosts本地解析
C:\WINDOWS\system32\drivers\etc\hosts 127.0.0.1 www.aberc220.com 别人 192.168.1.64 www.aberc220.com ...
- PAT乙1001
我脑洞大了..... 以为是个找规律..... 原来只是模拟..... 我相信肯定是有规律的..... 但是我就是不愿意了..... #include<cstdio> #include&l ...
- Using Sphinx to index CNS database
1, look at the sphinx.person.address.conf to see how to configure the conf file2, index the database ...