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 ...
随机推荐
- go mode
https://github.com/dominikh/go-mode.el http://blog.altoros.com/golang-part-1-main-concepts-and-proje ...
- HDU 1010 Tempter of the Bone DFS(奇偶剪枝优化)
需要剪枝否则会超时,然后就是基本的深搜了 #include<cstdio> #include<stdio.h> #include<cstdlib> #include ...
- linux系统定时重启tomcat
#touch auto-start.sh [root@Linux opt]# echo $LANGen_US.UTF-8 #vim auto-start.sh #!/bin/sh export LAN ...
- hdu 1728 逃离迷宫 (BFS)
逃离迷宫 Time Limit : 1000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Submissi ...
- 滑轮关节(b2PulleyJoint)
package{ import Box2D.Collision.b2AABB; import Box2D.Collision.b2RayCastInput; import Box2D.Collisio ...
- 修改document.domain的注意事项(转)
有时候,需要修改document.domain. 典型的情形:http://a.xxx.com/A.htm 的主页面有一个<iframe src="http://b.xxx.com/B ...
- TCP/IP模型各个层次的功能和协议
层次名称 功 能 协 议 应用层 (Application Layer) 负责实现一切与应用程序相关的功能,对应OSI参考模型的上三层 FTP(文件传输协议) HTTP(超文本传输协议 ...
- 【嵌入式linux】(第三步):安装串口终端 (ubuntu安装minicom串口终端)
1.前言 我使用的是USB转串口,芯片是PL2303,貌似ubuntu自带了PL2303的USB驱动,可以直接使用,其它的USB转串口的没试过. 2.minicom安装 在终端中输入 : sudo a ...
- BAT54C 二极管是如何工作的?
这是一个多电源供电的电路:Vcc是正常供电电源(如5V,由市电变换得到),电压大于(Vcc1-Vf),正常供电时二极管不导通:Vcc1是电池供电电源,当Vcc撤掉时,DD1(上边的二极管)导通,由Vc ...
- 连接Oracle数据库的Hibernate配置文件
连接Oracle数据库的Hibernate配置文件连接Oracle的Hibernate配置文件有两种格式,一种是xml格式的,另一种是Java属性文件格式的.下面分别给出这两种格式配置文件的代码. 1 ...