CodeForces 474B

Time Limit:1000MS Memory Limit:262144KB   64bit IO Format:%I64d & %I64u

Description

It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.

Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with numbers a1 + 1 to a1 + a2 and so on. See the example for a better understanding.

Mole can't eat all the worms (Marmot brought a lot) and, as we all know, Mole is blind, so Marmot tells him the labels of the best juicy worms. Marmot will only give Mole a worm if Mole says correctly in which pile this worm is contained.

Poor Mole asks for your help. For all juicy worms said by Marmot, tell Mole the correct answers.

Input

The first line contains a single integer n (1 ≤ n ≤ 105), the number of piles.

The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 103a1 + a2 + ... + an ≤ 106), where ai is the number of worms in the i-th pile.

The third line contains single integer m (1 ≤ m ≤ 105), the number of juicy worms said by Marmot.

The fourth line contains m integers q1, q2, ..., qm (1 ≤ qi ≤ a1 + a2 + ... + an), the labels of the juicy worms.

Output

Print m lines to the standard output. The i-th line should contain an integer, representing the number of the pile where the worm labeled with the number qi is.

Sample Input

Input

5
2 7 3 4 9
3
1 25 11

Output

1
5
3

Hint

For the sample
input:

  • The worms with labels from [1, 2] are in the first pile.
  • The worms with labels from [3, 9] are in the second pile.
  • The worms with labels from [10, 12] are in the third pile.
  • The worms with labels from [13, 16] are in the fourth pile.
  • The worms with labels from [17, 25] are in the fifth pile.
  • 题解:这道题如果只是读题很难完全懂,可以结合输入案例,就是第一行数据为5是行数,第二行数据为2,7,3,4,9,意思为排列的第一行有2个数,第二行有7个,以此类推,到第5行,第三行数据是输入要判断的数字的个数,第四行数据是输入要判断的数字,判断其所在行数。
  • 如下所示:
  • 1 2
  • 3 4 5 6 7 8 9
  • 10 11 12
  • 13 14 15 16 17
  • 18 19 20 21 22 23 24 25
  • 要判断案例中1,25 11所在的行数,首先可以建立一个数组,依次排列,把每一行都标记,第一行标记为1,以此类推,当输入一个数q时,输出a【q】,就可以得到所在的行数。
  • 标记时要注意其范围,标记完一行要进行+1,才可到达第二行。
#include<iostream>
using namespace std;
int a[];
int main()
{
int q,s,n,i,t,tot,f=;
while(cin>>n)
{
tot=;
for(int j=; j<=n; j++)
{
cin>>t;
for(i=tot; i<t+tot; i++)
a[i]=f;
f++;//每标记一次,f++,到达下一行
tot=i;
} cin>>q; for(i=; i<=q; i++)
{
cin>>s;
cout<<a[s]<<endl;//输入数字q,输出a【q】,得到的就是q所在的行 }
} return ;
}

CodeForces 474B(标记用法)的更多相关文章

  1. Codeforces 474B Worms 二分法(水

    主题链接:http://codeforces.com/contest/474/problem/B #include <iostream> #include <cmath> #i ...

  2. 版本控制之五:SVN trunk(主线) branch(分支) tag(标记) 用法详解和详细操作步骤(转)

    使用场景: 假如你的项目(这里指的是手机客户端项目)的某个版本(例如1.0版本)已经完成开发.测试并已经上线了,接下来接到新的需求,新需求的开发需要修改多个文件中的代码,当需求已经开始开发一段时间的时 ...

  3. SVN trunk(主线) branch(分支) tag(标记) 用法详解和详细操作步骤

    使用场景: 假如你的项目(这里指的是手机客户端项目)的某个版本(例如1.0版本)已经完成开发.测试并已经上线了,接下来接到新的需求,新需求的开发需要修改多个文件中的代码,当需求已经开始开发一段时间的时 ...

  4. CodeForces 474B E(Contest #1)

    题意: 给你一个数n,代表n段区间,接下来有n个数(a1,a2,...an)代表每段区间的长度,第一段区间为[1,a1],第二段区间为[a1+1,a1+a2],...第i段区间为[ai-1+1,ai- ...

  5. svn分支使用 SVN trunk(主线) branch(分支) tag(标记) 用法详解和详细操作步骤

    比较好的介绍了分支的创建和使用. 转:http://blog.csdn.net/vbirdbest/article/details/51122637

  6. CodeForces 474B Worms (水题,二分)

    题意:给定 n 堆数,然后有 m 个话询问,问你在哪一堆里. 析:这个题是一个二分题,但是有一个函数,可以代替写二分,lower_bound. 代码如下: #include<bits/stdc+ ...

  7. Codeforces 909 substr用法 思维合并线段目标最少 Py语句逆推DP vecrtor缩点删不同颜色点模拟 拓扑排序处理任务

    A str.substr(i,j) 从str[i]开始起取j个字符作为返回的字符串 /* Huyyt */ #include <bits/stdc++.h> using namespace ...

  8. Codeforces 474B. Worms

    It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mo ...

  9. WPF扩展标记

    标记扩展和 WPF XAML,标记扩展是 XAML 语言以及 XAML 服务的 .NET 实现的常规功能 XAML 处理器和标记扩展 XAML 分析器可将特性值解释为可转换成基元的文本字符串,或可通过 ...

随机推荐

  1. vijosP1603迷宫

    vijosP1603迷宫 链接:https://vijos.org/p/1603 [思路] 参考Matrix67的文章: [代码] #include<cstdio> #include< ...

  2. CLOSE-UP FORMALWEAR_意大利进口_2015秋冬_男装发布会_西装图片系列_男装西装设计资料_WeArTrends时尚资讯网_国内最专业的服装设计资讯网站

    CLOSE-UP FORMALWEAR_意大利进口_2015秋冬_男装发布会_西装图片系列_男装西装设计资料_WeArTrends时尚资讯网_国内最专业的服装设计资讯网站 CLOSE-UP FORMA ...

  3. 用过coreData或者sqlite吗?读写是分线程的吗?

    文/natewang(简书作者)原文链接:http://www.jianshu.com/p/cb8dc61b12fa著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”. 如果不是要求特别高, ...

  4. Thinkphp分页时查询条件保存方法

    web应用中经常要根据用户提交的查询条件进行过滤,再以列表方式显示在浏览器上.如果这种查询是多种条件的组合,并要进行分页显示,则如何在分页导航中保持查询条件,是必须解决的问题. 在Thinkphp中, ...

  5. sqlserver使用户只能在某个架构下建立表和存储过程

    1.首先,建立一个用户之后,默认的架构是dbo,默认的角色是public.这种情况下,这个用户将看不到dbo以及其他架构下的对象.除非单独进行授权.   2.新建一个架构test,然后使得这个架构的所 ...

  6. php数组和字符串转换

    PHP 中由于数组和字符串这两种变量类型是如此常用,以至于 PHP 具有两个函数,可以在字符串和数组之间互相进行转换. $array=explode(separator,$string); $stri ...

  7. Lucene 4.10.2开发示例

    这里面用的是比较新的Lucene4.10.2 做的一个实例.(lucene的索引不能太大,要不然效率会很低.大于1G的时候就必须考虑分布索引的问题) 先介绍一下Lucene的几个参数意义: Index ...

  8. Discuz X2.5 用户名包含被系统屏蔽的字符[解决方法]

    /uc_client/data/cache/badwords.php文件里的内容 删除并用 utf-8格式保存

  9. Invocation of init method failed; nested exception is org.hibernate.HibernateException: could not instantiate RegionFactory [org.hibernate.cache.impl

    严重: Exception sending context initialized event to listener instance of class org.springframework.we ...

  10. CF 295E Yaroslav and Points(Splay)

    题目大意: 两个操作 1 id op  把id的位置+op 2 id op  查询在[id.op]之间的全部的数的差 思路: 关键是pushup函数. 自己退一下会发现.跟区间的总和,区间的节点个数有 ...