Codeforces Round #271 (Div. 2)

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?≤?103, a1?+?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 test(s)

input

5
2 7 3 4 9
3
1 25 11

output

1
5
3

题意:给你n个序列的长度,依次连接n个序列,从第一个开始计数。求第m个原本属于那个序列

思路:记录每个数属于那个小序列就行了

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 1e6;

int num[maxn];

int main() {
	int n;
	scanf("%d", &n);
	int cnt = 0;
	int m;
	for (int i = 1; i <= n; i++) {
		scanf("%d", &m);
		for (int j = 0; j < m; j++)
			num[++cnt] = i;
	}
	int q;
	scanf("%d", &q);
	while (q--) {
		scanf("%d", &m);
		printf("%d\n", num[m]);
	}
	return 0;
}
时间: 2024-07-31 14:18:42

Codeforces Round #271 (Div. 2)的相关文章

Codeforces Round #271 (Div. 2) D. Flowers (递推)

题目链接:http://codeforces.com/problemset/problem/474/D 用RW组成字符串,要求w的个数要k个连续出现,R任意,问字符串长度为[a, b]时,字符串的种类有多少. 递推,dp[i]表示长度为i的种类有多少.当i < k的时候 dp[i] = 1 , 当i == k的时候 dp[i] = 2 ,  否则 dp[i] = dp[i - 1] + dp[i - k] . 1 #include <bits/stdc++.h> 2 using name

Codeforces Round #271 (Div. 2) F.Ant colony(线段树 + 统计区间内某数的个数)

F. Ant colony Mole is hungry again. He found one ant colony, consisting of n ants, ordered in a row. Each ant i (1 ≤ i ≤ n) has a strength si. In order to make his dinner more interesting, Mole organizes a version of «Hunger Games» for the ants. He c

Codeforces Round #271 (Div. 2) D.Flowers DP

D. Flowers We saw the little game Marmot made for Mole's lunch. Now it's Marmot's dinner time and, as we all know, Marmot eats flowers. At every dinner he eats some red and white flowers. Therefore a dinner can be represented as a sequence of several

Codeforces Round #271 (Div. 2) A. Keyboard

Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way: qwertyuiop asdfghjkl; zxcvbnm,./ Unfortunately Mole is blind, so sometimes it is problem for him to put his hands acc

Codeforces Round #271 (Div. 2)D(递推,前缀和)

很简单的递推题.d[n]=d[n-1]+d[n-k] 注意每次输入a和b时,如果每次都累加,就做了很多重复性工作,会超时. 所以用预处理前缀和来解决重复累加问题. 最后一个细节坑了我多次: printf("%I64d\n",(s[b]-s[a-1]+mod)%mod); 这句话中加mod万万不能少,因为理论上s[b]-s[a-1]肯定大于0,但是由于两个都是模1000000007以后的结果,那么就不一定了,当s[b]-s[a-1]<0时结果是负的,不是题意中应该输出的结果,所以一

Codeforces Round #271 (Div. 2) D. Flowers (递推 预处理)

We saw the little game Marmot made for Mole's lunch. Now it's Marmot's dinner time and, as we all know, Marmot eats flowers. At every dinner he eats some red and white flowers. Therefore a dinner can be represented as a sequence of several flowers, s

(补题解)Codeforces Round #271 (Div. 2)

前言:最近被线段树+简单递推DP虐的体无完肤!真是弱! A:简单题,照着模拟就可以,题目还特意说不用处理边界 B:二分查找即可,用lower_lound()函数很好用 1 #include<string.h> 2 #include<math.h> 3 #include<algorithm> 4 #include<stdio.h> 5 #include<math.h> 6 #include<string> 7 #include<i

Codeforces Round #279 (Div. 2) ABCD

Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard input/

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i