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. 也说Autofac在MVC的简单实践:破解在Controller构造函数中的实例化 - winhu

    相信大家对Autofac并不陌生,很多人都在使用.本文只是介绍一下本人在使用时的一点想法总结. 在使用一个框架时,肯定要去它的官网查阅一下.autofac的官网给出了一些经典的使用案例.如注册容器: ...

  2. 【转】STL空间配置器

    STL空间配置器(allocator)在所有容器内部默默工作,负责空间的配置和回收.STL标准为空间配置器定义了标准接口(可见<STL源码剖析>P43).而具体实现细节则由各编译器实现版本 ...

  3. Android 模拟器中sdcard操作

    1.  在模拟器中创建sdcard目录,方法如下: 1. mksdcard命令 用cmd进入SDK的Tools目录,执行mksdcard命令.会出现如下帮助信息 我们可以看到sdcard image支 ...

  4. KVO KVC

    @interface FoodData : NSObject { NSString * foodName; float foodPrice; } @end ////////////////////// ...

  5. JDBC第一天连接池案例

    JDBC,JDBC的工具类JDBC 连接从连接池中拿: 创建连接池的语句: package day01; import java.sql.Connection; import java.sql.Dri ...

  6. Tkinter教程之Entry篇

    本文转载自:http://blog.csdn.net/jcodeer/article/details/1811302 #Tkinter教程之Entry篇#Entry用来输入单行文本'''1.第一个En ...

  7. 怎么利用SQL语句查询数据库中具体某个字段的重复行

    select * from [tablename] group by SeriNohaving count(SeriNo)<>1

  8. Spark SQL概念学习系列之Spark生态之Spark SQL(七)

    具体,见

  9. Yii CModel中rules验证规则

    array( array(‘username’, ‘required’), array(‘username’, ‘length’, ‘min’=>3, ‘max’=>12), array( ...

  10. HIVE删除表数据

    HIVE只有INSERT,没有UPDATE跟DELETE,所以通过其他的语句产生DETELE效果. 在HDFS上或者本地服务器上新建空的文件XXXXX, 然后执行: LOAD DATA LOCAL I ...