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. 【转】 CATransform3D 矩阵变换之立方体旋转实现细节

    原文网址:http://blog.csdn.net/ch_soft/article/details/7351896 第一部分.前几天做动画,使用到了CATransform3D ,由于没有学过计算机图形 ...

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

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

  3. win7和centos双系统安装

    几年之前为了安装xp和linux的双系统曾折腾了好多天,今天为了安装这个win7和centos双系统,也折腾了两天多,哦,我的天,安装个双系统,怎么这么麻烦呢? 没有来得及整理,先铺上草稿,供同志们参 ...

  4. js除法余数

    return (Math.round(rs*100)/100); //保保留小数点后两位数: //如果要保留三位则改为:Math.round(rs*1000)/1000; //如果要保留四位则改为:M ...

  5. [Everyday Mathematics]20150111

    设 $n$ 阶方阵 $A=(\al_1,\cdots,\al_n)$ 非奇异, $B=(0,\al_2,\cdots,\al_n)$. 试证: $BA^{-1}$, $A^{-1}B$ 的秩均为 $n ...

  6. .net-.net试题2

    ylbtech-doc:.net-.net试题2 .net试题2 1.A,.net试题2返回顶部 01.{DotNet题目}下列变量的赋值,正确的是:(  )(选择2项) A )int myInteg ...

  7. PHP学习笔记--文件目录操作(文件上传实例)

    文件操作是每个语言必须有的,不仅仅局限于PHP,这里我们就仅用PHP进行讲解 php的文件高级操作和文件上传实例我放在文章的最后部分.--以后我还会给大家写一个PHP类似于网盘操作的例子 注意:阅读此 ...

  8. map用法详解

    转自:http://www.kuqin.com/cpluspluslib/20071231/3265.html Map是 STL的一个关联容器,它提供一对一(其中第一个可以称为关键字,每个关键字只能在 ...

  9. SQL知识累积

    详细介绍select的文章,展示原始数据.SQL.查询结果,以及在不同数据库下SQL应该如何写. https://en.wikipedia.org/wiki/Select_(SQL) 目录如下: Co ...

  10. C#复习反射

    反射中常用方法: //获取对象类型 One one = new One(); Type t = one.GetType(); //动态加载 Assembly a = Assembly.LoadFile ...