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

  1. Codeforces Gym 100570 E. Palindrome Query Manacher

    E. Palindrome QueryTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100570/pro ...

  2. Codeforces Hello2015第一题Cursed Query

    英文题面: De Prezer loves movies and series. He has watched the Troy for like 100 times and also he is a ...

  3. Codeforces Gym 101252D&&floyd判圈算法学习笔记

    一句话题意:x0=1,xi+1=(Axi+xi%B)%C,如果x序列中存在最早的两个相同的元素,输出第二次出现的位置,若在2e7内无解则输出-1. 题解:都不到100天就AFO了才来学这floyd判圈 ...

  4. Codeforces Gym 101190M Mole Tunnels - 费用流

    题目传送门 传送门 题目大意 $m$只鼹鼠有$n$个巢穴,$n - 1$条长度为$1$的通道将它们连通且第$i(i > 1)$个巢穴与第$\left\lfloor \frac{i}{2}\rig ...

  5. Codeforces Gym 101623A - 动态规划

    题目传送门 传送门 题目大意 给定一个长度为$n$的序列,要求划分成最少的段数,然后将这些段排序使得新序列单调不减. 考虑将相邻的相等的数缩成一个数. 假设没有分成了$n$段,考虑最少能够减少多少划分 ...

  6. 【Codeforces Gym 100725K】Key Insertion

    Codeforces Gym 100725K 题意:给定一个初始全0的序列,然后给\(n\)个查询,每一次调用\(Insert(L_i,i)\),其中\(Insert(L,K)\)表示在第L位插入K, ...

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

  8. codeforces gym 100553I

    codeforces gym 100553I solution 令a[i]表示位置i的船的编号 研究可以发现,应是从中间开始,往两边跳.... 于是就是一个点往两边的最长下降子序列之和减一 魔改树状数 ...

  9. CodeForces Gym 100213F Counterfeit Money

    CodeForces Gym题目页面传送门 有\(1\)个\(n1\times m1\)的字符矩阵\(a\)和\(1\)个\(n2\times m2\)的字符矩阵\(b\),求\(a,b\)的最大公共 ...

随机推荐

  1. 数据来自后台非Ajax加载的联动实现方法

    要实现的效果如下,通过一级标签来控制二级标签, 第一步:在Conctroller中获取数据,并且请到modle里面返回 ModelAndView model = new ModelAndView(&q ...

  2. Hadoop中的InputFormat解析

    1.InputFormat InputFormat是Hadoop平台上Mapreduce输入的规范,仅有两个抽象方法. List<InputSplit> getSplits(), 获取由输 ...

  3. memcache分布式部署的原理分析

    下面本文章来给各位同学介绍memcache分布式部署的原理分析,希望此文章对你理解memcache分布式部署会有所帮助哦.   今天在封装memcache操作类库过程中,意识到一直以来对memcach ...

  4. redis配置实例及redis.conf详细说明

    一.配置实例 1.redis修改持久化路径.日志路径.清缓存 redis修改持久化路径和日志路径 vim  redis.conf logfile /data/redis_cache/logs/redi ...

  5. C# Adding Hyperlink to Windows Form z

    When creating a Windows form in C#, we would like to create a hyperlink so that when the user click ...

  6. sensor_HAL分析

    http://blog.csdn.net/new_abc/article/details/8971807 http://blog.csdn.net/cs_lht/article/details/817 ...

  7. hdfs[命令] dfs

    Usage: hadoop fs [generic options] [-appendToFile <localsrc> ... <dst>] [-cat [-ignoreCr ...

  8. 为Hadoop配置Win8.1授时服务器

    启动Windows服务,顺序如下: SSTPS(secure socket tunneling protocol service)服务 Telephony服务 Remote Access Connec ...

  9. Unity3D-数学相关

    1. Transform.rotation:对象在世界坐标系下的旋转:Transform.localRotation:对象在父对象的局部坐标系下的旋转.两个变量的类型均为四元素. (1)得到游戏对象当 ...

  10. Nodejs与Net 和SQL 交互利器Edge.js

    https://github.com/tjanczuk http://www.cnblogs.com/joylee/archive/2013/02/05/msnodesql.html edge.js这 ...