• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
HaibaraAi
博客园    首页    新随笔    联系   管理    订阅  订阅

Codeforce Round #223 Div2 C

 

Sponsored by
In English По-русски
HaibaraAi | Logout
 
 
 
 
 注意这个二分要mid=(l+r)/2+1;
  • Home
  • Contests
  • Gym
  • Problemset
  • Groups
  • Rating
  • Help

 
 
Codeforces Round #223 (Div. 2)
Finished
Practice
Add to favourites
 
 
→ Practice
 
You are registered for practice. You can solve problems unofficially. Results can be found in the contest status and in the bottom of standings.
 
 
→ Submit?
 
Language:
Choose file:
Be careful: there is 50 points penalty for submission which fails the pretests or resubmission (except failure on the first test, denial of judgement or similar verdicts). "Passed pretests" submission verdict doesn't guarantee that the solution is absolutely correct and it will pass system tests.
 
 
→ Last submissions
 
SubmissionTimeVerdict
5935419 02/10/2014 07:46PM Accepted
 
 
→ Problem tags
 
 
 
 
 
binary search
 
 
 
 
implementation
 
 
 
 
two pointers
No tag edit access
 
 
→ Contest materials
 
  • Announcement
     
  • Tutorial
     
  •  
     
     
  • Problems
  • Submit
  • My submissions
  • Status
  • Hacks
  • Room
  • Standings
  • Custom test
C. Sereja and Prefixes
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 a1, a2, ..., an, then after we apply the described operation, the sequence transforms into a1, a2, ..., an[, a1, a2, ..., al] (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.

Input

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 xi (1 ≤ xi ≤ 105) — the number to add. Type 2 means copying a prefix of length li to the end ci times, in this case the line further contains two integers li, ci (1 ≤ li ≤ 105, 1 ≤ ci ≤ 104), li is the length of the prefix, ci is the number of copyings. It is guaranteed that the length of prefix li 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.

Output

Print the elements that Sereja is interested in, in the order in which their numbers occur in the input.

Sample test(s)
Input
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
Output
1 2 1 2 3 1 2 1 2 3 1 2 1 2 3 4

Codeforces (c) Copyright 2010-2014 Mike Mirzayanov
The only programming contests Web 2.0 platform
Server time: 02/10/2014 07:47PM (p2).
 
 
 
 1 #pragma comment(linker,"/STACK:102400000,102400000")
 2 #include <cstdio>
 3 #include <vector>
 4 #include <cmath>
 5 #include <queue>
 6 #include <cstring>
 7 #include <iostream>
 8 #include <algorithm>
 9 using namespace std;
10 #define INF 0x7fffffff 
11 #define mod 1000000007
12 #define ll long long
13 #define maxn 1000025
14 #define pi acos(-1.0)
15 int n, m;
16 ll a[maxn], b[maxn], c[maxn];
17 ll find(ll x){
18     int l = 0, r = n - 1, mid;
19     while (l < r){
20         mid = ((l + r) >> 1) + 1;
21         if (b[mid]<=x)l = mid;
22         else r = mid-1;
23     } 
24     if (a[l] == -1)return find((x-b[l])%c[l]+1);
25     return a[l];
26 }
27 int main(){
28     ll x, s = 1;
29     int op, cnt;
30     scanf("%d", &n);
31     for (int i = 0; i < n; i++){
32         scanf("%d", &op);
33         if (op == 1){
34             scanf("%I64d", &x);
35             a[i] = x;
36             b[i] = s;
37             s++;
38         }
39         else{
40             scanf("%I64d%d", &x, &cnt);
41             a[i] = -1;
42             b[i] = s;
43             c[i] = x;
44             s += x*cnt;
45         }
46     }
47     scanf("%d", &m);
48     while (m--){
49         scanf("%I64d", &x);
50         printf("%I64d ",find(x));
51     }
52     return 0;
53 }
View Code
posted @ 2014-02-10 23:48  HaibaraAi  阅读(148)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3