乱搞题..
题目链接 http://codeforces.com/problemset/problem/380/A
一个人要做个数字序列,有两种操作,1 是 向后面加个数字 2 是向后面加上从 1 到 l 的复制 C 次的序列
最后有 m 个询问
记录下每个操作所诞生的序列的开始位置
记录下每个操作的信息,放在 node 里面
遇到 类型 1 的节点 直接返回值
遇到 类型 2 的节点就继续查找
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<deque>
#include<set>
#include<vector>
using namespace std;
#define LL long long
#define fst first
#define sec second
#define P pair<LL , LL>
#define MAX 200000
int na;
int np;
struct nod
{
LL l,r;
LL t;
LL time;
LL v;
LL type;
}node[MAX];
LL start[MAX];
int main()
{
int n;
cin >> n;
LL len = 0;
for(int i = 0; i < n; i++)
{
int t;
cin >> t;
if(t == 1)
{
int num;
cin >> num;
start[i] = len + 1;
len ++ ;
node[i].l = len;
node[i].r = len;
node[i].v = num;
node[i].type = 1;
}
else
{
int to,ti;
cin >> to >> ti;
start[i] = len + 1;
node[i].l = len + 1;
len += to * ti;
node[i].r = len;
node[i].t = to;
node[i].time = ti;
node[i].type = 2;
}
}
start[n] = 0x3f3f3f3f;
int m;
cin >> m;
for(int i = 0;i < m; i++)
{
LL q;
cin >> q;
LL j;
while(1)
{
j = upper_bound(start, start + n, q) - start - 1;
if(node[j].type == 2)
{
q = (q - node[j].l + 1) % (node[j].t);
if( q == 0 )
q = node[j].t;
continue;
}
else
{
break;
}
}
cout << node[j].v << " ";
}
return 0;
}