[2016-02-05][CF][380A][Sereja and Prefixes]

[2016-02-05][CF][380A][Sereja and Prefixes]

CodeForces - 380A

Sereja and Prefixes

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

Submit Status

Description

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 intoa1,?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 integersli,?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 Input

Input

61 11 22 2 11 32 5 21 4161 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
  • 时间:2016-01-27 14:20:06 星期三
  • 题目编号:CF 380A
  • 题目大意:
  • 分析:
  • 方法:
  • 解题过程遇到问题:后面读取 pos 的时候,会爆掉int!!!

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

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

#include <vector>

#include <list>

#include <map>

#include <set>

#include <deque>

#include <queue>

#include <stack>

#include <bitset>

#include <algorithm>

#include <functional>

#include <numeric>

#include <utility>

#include <sstream>

#include <iostream>

#include <iomanip>

#include <cstdio>

#include <cmath>

#include <cstdlib>

#include <cctype>

#include <string>

#include <cstring>

#include <cstdio>

#include <cmath>

#include <cstdlib>

#include <ctime>

using namespace std;

typedef long long LL;

#define CLR(x,y) memset((x),(y),sizeof((x)))

#define getint(x) int (x);scanf("%d",&(x))

#define get2int(x,y) int (x),(y);scanf("%d%d",&(x),&(y))

#define get3int(x,y,z) int (x),(y),(z);scanf("%d%d%d",&(x),&(y),&(z))

#define getll(x) LL (x);scanf("%I64d",&(x))

#define get2ll(x,y) LL (x),(y);scanf("%I64d%I64d",&(x),&(y))

#define get3ll(x,y,z) LL (x),(y),(z);scanf("%I64d%I64d%I64d",&(x),&(y),&(z))

#define getdb(x) double (x);scanf("%lf",&(x))

#define get2db(x,y) double (x),(y);scanf("%lf%lf",&(x),&(y))

#define get3db(x,y,z) double (x),(y),(z);scanf("%lf%lf%lf",&(x),&(y),&(z))

#define getint2(x) scanf("%d",&(x))

#define get2int2(x,y) scanf("%d%d",&(x),&(y))

#define get3int2(x,y,z) scanf("%d%d%d",&(x),&(y),&(z))

#define getll2(x) scanf("%I64d",&(x))

#define get2ll2(x,y) scanf("%I64d%I64d",&(x),&(y))

#define get3ll2(x,y,z) scanf("%I64d%I64d%I64d",&(x),&(y),&(z))

#define getdb2(x) scanf("%lf",&(x))

#define get2db2(x,y) scanf("%lf%lf",&(x),&(y))

#define get3db2(x,y,z) scanf("%lf%lf%lf",&(x),&(y),&(z))

#define getstr(str) scanf("%s",str)

#define get2str(str1,str2) scanf("%s",str1,str2)

#define FOR(x,y,z) for(int (x)=(y);(x)<(z);(x)++)

#define FORD(x,y,z) for(int (x)=(y);(x)>=(z);(x)--)

#define FOR2(x,y,z) for((x)=(y);(x)<(z);(x)++)

#define FORD2(x,y,z) for((x)=(y);(x)>=(z);(x)--)

const int maxm = 1e5 + 100;

const int maxn = 1e5 + 100;

int x[maxm];//保存第i个语句增加的字符

LL len[maxm];//保存第i个指令前,的长度

int op[maxm];//保存 第 i 句的指令

int l[maxm];//保存第i个指令的时候,对应的l 和 c

int c[maxm];

int main()

{

    getint(m);

    FOR(i,0,m){

        getint2(op[i]);

        if(op[i] == 1){

            getint2(x[i]);

            len[i + 1] = len[i] + 1;

        }

        else {

            get2int2(l[i],c[i]);

            len[i + 1] = len[i] + l[i] * c[i];

        }

    }

    getint(n);

    FOR(i,0,n){

        getll(pos);

        while(1){

            int p = lower_bound(len, len + m + 1,pos) - len - 1;

            if(op[p] == 1){

                printf("%d ",x[p]);

                break;

            }

            pos=(pos-len[p]-1)%l[p]+1;

        }

    }

    return 0;

}

来自为知笔记(Wiz)

时间: 2024-11-05 06:00:24

[2016-02-05][CF][380A][Sereja and Prefixes]的相关文章

CodeForces 380A Sereja and Prefixes

A. 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

2016/02/21 codes

var Class = { create:function(){ var parent = null,properties = $A(arguments); if(Object.isFunction(properties[0])) parent = properties.shift(); function kclass(){ this.initialize.apply(this.arguments); } Object.extend(kclass,Class.Methods); kclass.s

FFMpeg ver 20160219-git-98a0053 滤镜中英文对照 2016.02.21 by 1CM

FFMpeg ver 20160219-git-98a0053 滤镜中英文对照 2016.02.21 by 1CM T.. = Timeline support 支持时间轴 .S. = Slice threading 分段线程 ..C = Command support 支持命令传送 A = Audio input/output 音频 输入/输出 V = Video input/output 视频 输入/输出 N = Dynamic number and/or type of input/out

2016/02/20 codes

<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <title>2016/02/20</title></head><body><div id="mainDiv"> <div id = "content"> <div id = &qu

分布式技术一周技术动态 2016.02.21

分布式系统实践 1. 远程接口设计经验分享 http://mp.weixin.qq.com/s?__biz=MzAwNjQwNzU2NQ%3D%3D&idx=2&mid=402064901&scene=0&sn=0b5f56a97b431ed355b75a9e17f2e754 要点: 分布式系统由于中间存在网络因素, 出错的情况比单机系统要多很多, 那么如何设计一个远程接口呢? 本文很好的解释了设计远程接口需要考虑的问题点. 2. 时序列数据库武斗大会之什么是TSDB ht

2016/02/16 codes

<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <title>2016/02/16 codes</title> <link rel="stylesheet" href="assets/reset.css"> <style> .slideOne{ width:

翻译:Gregory Larsen,2016/02/19(第一版:2014年12月17日)高级T-SQL阶梯1级:使用CROSS JOIN介绍高级T-SQL

原文链接:http://www.sqlservercentral.com/articles/Stairway+Series/119933/ 原文作者:Gregory Larsen,2016/02/19(第一版:2014年12月17日) 系列 本文是"Stairway Series:Stairway to Advanced T-SQL"的一部分 这个阶梯将包含一系列文章,这些文章将在前面两个T-SQL阶梯,T-SQL DML和T-SQL超越基础知识的T-SQL基础上进行扩展. 这个楼梯应

毕设进度2020.02.05

毕设进度2020.02.05 继续建立数据库和基础代码: 新闻数据库 政策数据库 原文地址:https://www.cnblogs.com/liurx/p/12267248.html

2016年05月01.02日【EPM-易通元】最新价位公布

涨了.涨了.又涨了! 我们的「EPM易通元」天天见涨!太给力了!! 2016.05月01.02日今天早晨已涨0.01美金,目前已到0.40美金啦!如果你有1000个易通元,你今天就收益10美金 如果你有10000个易通元,今天就收益100美金 如果你有100000个易通元,你今天就收益1000美金 如果你有1000000个易通元,你今天就收益10000美金. 恭喜买到「EPM易通元」的朋友们,买到即是赚到! 买入210美金到3500美金 :1美金:6.3人民币兑换,举例买入3500美金(人民币2