Codeforces Gym 100571A A. Cursed Query 离线
A. Cursed Query
Time Limit: 20 Sec
Memory Limit: 256 MB
题目连接
http://codeforces.com/gym/100571/problem/A
Description
De Prezer loves movies and series. He has watched the Troy for like 100 times and also he is a big fan of Supernatural series.So, he did some researches and found a cursed object which had n lights on it and initially all of them were turned off.Because of his love to theTroy, he called that object Troy.
He looked and saw a note on it in Khikulish (language of people of Khikuland): "Ma in hame rah umadim, hala migi ... ? ... Mage man De Prezer am k mikhay mano ... ? .... Man se sale ... To boro .... beshur manam miram ... o mishuram".
He doesn't know Khikulish, so just ignored the note and tested the Troy.
He realized that the light number i stays turned on for exactly ai seconds, and then it turns itself off (if it is turned on, in time t, in timet + ai - 1 it will be turned on, but on time t + ai it won't be) and the next light will be turned on (if i < n, next light is the light number i + 1, otherwise it is light with number 1).
For example if n = 2 and we turn on the first light in time 0, it will be turned on in hole interval [0, a1) and in hole interval [a1, a1 + a2)the second light will be turned on and so on.
In time 0 he turns on the light number 1.
De Prezer also loves query.So he gives you q queries.In each query he will give you integer t (the time a revengeful ghost attacked him) and you should print the number of the light that is turned on, in time t.
Input
The first line of input contains two integers n and q.
The second line contains n space separated integers, a1, a2, ..., an .
The next q lines, each line contains a single integer t .
1 ≤ n, q ≤ 105
1 ≤ ai ≤ 109
1 ≤ t ≤ 1018
Output
For each query, print the answer in one line.
Sample Input
5 7
1 2 3 4 5
1
2
3
7
14
15
16
Sample Output
2
2
3
4
5
1
2
HINT
题意
给你一些灯,第一个灯会在[0,a1)的时候亮,第二栈灯会在[a1,a1+a2)的时候亮,然后哒哒哒,循环
有Q个询问,问你在t秒时,是哪栈灯在亮
题解:
我是离线做的,但是感觉二分也可以
代码
- #include <cstdio>
- #include <cmath>
- #include <cstring>
- #include <ctime>
- #include <iostream>
- #include <algorithm>
- #include <set>
- #include <vector>
- #include <sstream>
- #include <queue>
- #include <typeinfo>
- #include <fstream>
- #include <map>
- #include <stack>
- typedef long long ll;
- using namespace std;
- //freopen("D.in","r",stdin);
- //freopen("D.out","w",stdout);
- #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
- #define test freopen("test.txt","r",stdin)
- const int maxn=;
- #define mod 1000000007
- #define eps 1e-9
- const int inf=0x3f3f3f3f;
- const ll infll = 0x3f3f3f3f3f3f3f3fLL;
- inline ll read()
- {
- ll x=,f=;char ch=getchar();
- while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
- while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
- return x*f;
- }
- //*************************************************************************************
- ll a[maxn];
- ll sum[maxn];
- struct node
- {
- ll x,y,z;
- };
- node query[maxn];
- bool cmp(node a,node b)
- {
- return a.x<b.x;
- }
- bool cmp1(node a,node b)
- {
- return a.y<b.y;
- }
- int main()
- {
- ll n,q;
- n=read(),q=read();
- for(int i=;i<=n;i++)
- a[i]=read();
- for(int i=;i<=n;i++)
- sum[i]+=a[i]+sum[i-];
- for(int i=;i<=q;i++)
- {
- query[i].x=read();
- query[i].x%=sum[n];
- query[i].y=i;
- }
- sort(query+,query++q,cmp);
- int j=;
- for(int i=;i<=q;i++)
- {
- while(sum[j]<=query[i].x&&j<n)
- j++;
- query[i].z=j;
- }
- sort(query+,query++q,cmp1);
- for(int i=;i<=q;i++)
- printf("%d\n",query[i].z);
- }
Codeforces Gym 100571A A. Cursed Query 离线的更多相关文章
- Codeforces Gym 100570 E. Palindrome Query Manacher
E. Palindrome QueryTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100570/pro ...
- Codeforces Hello2015第一题Cursed Query
英文题面: De Prezer loves movies and series. He has watched the Troy for like 100 times and also he is a ...
- Codeforces Gym 101252D&&floyd判圈算法学习笔记
一句话题意:x0=1,xi+1=(Axi+xi%B)%C,如果x序列中存在最早的两个相同的元素,输出第二次出现的位置,若在2e7内无解则输出-1. 题解:都不到100天就AFO了才来学这floyd判圈 ...
- Codeforces Gym 101190M Mole Tunnels - 费用流
题目传送门 传送门 题目大意 $m$只鼹鼠有$n$个巢穴,$n - 1$条长度为$1$的通道将它们连通且第$i(i > 1)$个巢穴与第$\left\lfloor \frac{i}{2}\rig ...
- Codeforces Gym 101623A - 动态规划
题目传送门 传送门 题目大意 给定一个长度为$n$的序列,要求划分成最少的段数,然后将这些段排序使得新序列单调不减. 考虑将相邻的相等的数缩成一个数. 假设没有分成了$n$段,考虑最少能够减少多少划分 ...
- 【Codeforces Gym 100725K】Key Insertion
Codeforces Gym 100725K 题意:给定一个初始全0的序列,然后给\(n\)个查询,每一次调用\(Insert(L_i,i)\),其中\(Insert(L,K)\)表示在第L位插入K, ...
- Codeforces gym 101343 J.Husam and the Broken Present 2【状压dp】
2017 JUST Programming Contest 2.0 题目链接:Codeforces gym 101343 J.Husam and the Broken Present 2 J. Hu ...
- codeforces gym 100553I
codeforces gym 100553I solution 令a[i]表示位置i的船的编号 研究可以发现,应是从中间开始,往两边跳.... 于是就是一个点往两边的最长下降子序列之和减一 魔改树状数 ...
- CodeForces Gym 100213F Counterfeit Money
CodeForces Gym题目页面传送门 有\(1\)个\(n1\times m1\)的字符矩阵\(a\)和\(1\)个\(n2\times m2\)的字符矩阵\(b\),求\(a,b\)的最大公共 ...
随机推荐
- 【转】使用 Auto Layout 的典型痛点和技巧
layoutIfNeeded()强制立刻更新布局 原文网址:http://www.jianshu.com/p/0f031606e5f2 官方文档:Auto Layout Guide 加上去年WWDC上 ...
- Oracle存储过程实现返回多个结果集 在构造函数方法中使用 dataset
原文 Oracle存储过程实现返回多个结果集 在构造函数方法中使用 dataset DataSet相当你用的数据库: DataTable相当于你的表.一个 DataSet 可以包含多个 DataTab ...
- codeforces 675C Money Transfers map
上面是官方题解,写的很好,然后就A了,就是找到前缀和相等的最多区间,这样就可以减去更多的1 然后肯定很多人肯定很奇怪为什么从1开始数,其实从2开始也一样,因为是个环,从哪里开始记录前缀和都一样 我们的 ...
- CSS_网站配色参考方案
http://www.cnblogs.com/QLeelulu/archive/2008/04/04/1136974.html Shiny silver [#EEEEEE] Reddi ...
- Maven解决Missing artifact com.sun:tools:jar:1.5.0错误
<dependency> <groupId>com.sun</groupId> <artifactId>tools</artifactId> ...
- Spark视频 王家林 Spark公开课大讲坛第二期: Spark的Shark和SparkSQL
王家林 Spark公开课大讲坛第一期:Spark把云计算大数据速度提高100倍以上 http://edu.51cto.com/lesson/id-30816.html Spark实战高手之路 系列书籍 ...
- [转]SQL中char、varchar、nvarchar的区别
char char是定长的,也就是当你输入的字符小于你指定的数目时,char(8),你输入的字符小于8时,它会再后面补空值.当你输入的字符大于指定的数时,它会截取超出的字符. nvarcha ...
- 在linux上用dd命令实现ghost功能
ghost和g4l 安装操作系统,速度太慢,整个过程太冗长乏味了. 安装过程中,需要回答若干问题,系统需要安装无数个软件,创建和写入无数的文件.因为涉及到大量的文件定位和读写,速度一定是快不起来的. ...
- Create a commit using pygit2
Create a commit using pygit2 Create a commit using pygit2 2015-04-06 10:41 user1479699 imported from ...
- Spring MVC BeanNameUrlHandlerMapping example
In Spring MVC, BeanNameUrlHandlerMapping is the default handler mapping mechanism, which maps URL re ...