CF380A.Sereja and Prefixes
普及/提高-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Sereja loves number sequences very much. That's why he decided to make himself a new one following a certain algorithm.
Sereja takes a blank piece of paper. Then he starts writing out the sequence in m stages. Each time he either adds a new number to the end of the sequence or takes l first elements of the current sequence and adds them c times to the end. More formally, if we represent the current sequence as _a_1, _a_2, ..., a__n, then after we apply the described operation, the sequence transforms into _a_1, _a_2, ..., a__n[, _a_1, _a_2, ..., a__l] (the block in the square brackets must be repeated c times).
A day has passed and Sereja has completed the sequence. He wonders what are the values of some of its elements. Help Sereja.
Sereja 非常喜欢数列,因此他决定按照某种特定的算法为自己构造一个新的数列。
Sereja 拿出一张空白纸。然后他分 m 个阶段来写出这个数列。在每个阶段中,他要么在当前数列末尾添加一个新数,要么取当前数列的前 l 个元素,并将这 l 个元素重复 c 次后添加到当前数列末尾。更准确地说,若当前数列为 _a_₁, _a_₂, ..., a__n,则执行上述操作后,数列变为
_a_₁, _a_₂, ..., a__n[, _a_₁, _a_₂, ..., a__l](方括号内的块需重复 c 次)。
一天过去了,Sereja 已完成了该数列。他想知道该数列中某些位置上的元素值。请帮助 Sereja。
输入格式
The first line contains integer m (1 ≤ m ≤ 105) — the number of stages to build a sequence.
Next m lines contain the description of the stages in the order they follow. The first number in the line is a type of stage (1 or 2). Type 1 means adding one number to the end of the sequence, in this case the line contains integer x__i (1 ≤ x__i ≤ 105) — the number to add. Type 2 means copying a prefix of length l__i to the end c__i times, in this case the line further contains two integers l__i, c__i (1 ≤ l__i ≤ 105, 1 ≤ c__i ≤ 104), l__i is the length of the prefix, c__i is the number of copyings. It is guaranteed that the length of prefix l__i is never larger than the current length of the sequence.
The next line contains integer n (1 ≤ n ≤ 105) — the number of elements Sereja is interested in. The next line contains the numbers of elements of the final sequence Sereja is interested in. The numbers are given in the strictly increasing order. It is guaranteed that all numbers are strictly larger than zero and do not exceed the length of the resulting sequence. Consider the elements of the final sequence numbered starting from 1 from the beginning to the end of the sequence.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
第一行包含一个整数 m(1≤m≤105)—— 构建序列所需的阶段数。
接下来的 m 行按顺序描述各阶段。每行的第一个数为阶段类型(1 或 2)。类型 1 表示向序列末尾添加一个数;此时该行还包含一个整数 xi(1≤xi≤105),即待添加的数。类型 2 表示将长度为 li 的前缀复制 ci 次并追加到序列末尾;此时该行还包含两个整数 li、ci(1≤li≤105,1≤ci≤104),其中 li 是前缀长度,ci 是复制次数。保证前缀长度 li 不超过当前序列长度。
下一行包含一个整数 n(1≤n≤105)—— Sereja 关心的元素个数。再下一行包含 Sereja 所关心的最终序列中各元素的位置编号,这些编号严格递增给出。保证所有编号均严格大于 0,且不超过最终序列的长度。最终序列的元素位置编号从 1 开始,由序列开头至结尾依次编号。
请注意:在 C++ 中读写 64 位整数时,请勿使用 %lld 说明符。推荐使用 cin、cout 流,或 %I64d 说明符。
输出格式
Print the elements that Sereja is interested in, in the order in which their numbers occur in the input.
按输入中它们编号出现的顺序输出 Sereja 感兴趣的元素。
输入输出样例
输入#1
6 1 1 1 2 2 2 1 1 3 2 5 2 1 4 16 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
输出#1
1 2 1 2 3 1 2 1 2 3 1 2 1 2 3 4
输入解题思路,AI测评打分。不知道怎么写?