Codeforces Round #223 (Div. 1) A - Sereja and Prefixes

离线。。存储10^5的数就可以了。。。


#include <iostream>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <time.h>
#define maxn 300005
#define maxm 1000005
#define eps 1e-7
#define mod 1000000007
#define INF 0x3f3f3f3f
#define PI (acos(-1.0))
#define lowbit(x) (x&(-x))
#define mp make_pair
#define ls o<<1
#define rs o<<1 | 1
#define lson o<<1, L, mid 
#define rson o<<1 | 1, mid+1, R
#define pii pair<int, int>
#pragma comment(linker, "/STACK:16777216")
typedef long long LL;
typedef unsigned long long ULL;
//typedef int LL;
using namespace std;
LL qpow(LL a, LL b){LL res=1,base=a;while(b){if(b%2)res=res*base;base=base*base;b/=2;}return res;}
LL powmod(LL a, LL b){LL res=1,base=a;while(b){if(b%2)res=res*base%mod;base=base*base%mod;b/=2;}return res;}
//head

struct node
{
	int a, b, op;
}p[maxn];
LL a[maxn];
int q[maxn];
int ans[maxn];
int n, m;

void read()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) {
		scanf("%d", &p[i].op);
		if(p[i].op == 1) scanf("%d", &p[i].a);
		else scanf("%d%d", &p[i].a, &p[i].b);
	}
	scanf("%d", &m);
	for(int i = 1; i <= m; i++) scanf("%I64d", &a[i]);
}

void work()
{
	LL tail = 1, len = 0, t;
	for(int i = 1, j = 1; i <= n && j <= m; i++) {
		if(p[i].op == 1) {
			t = len + 1;
			q[tail++] = p[i].a;
		}
		else {
			t = len + p[i].a * p[i].b;
			LL tt = p[i].b;
			while(tail <= 100000 && tt--) for(int k = 1; k <= p[i].a; k++) q[tail++] = q[k];
		}
		while(j <= m && a[j] > len && a[j] <= t) {
			if(p[i].op == 1) ans[j] = p[i].a;
			else {
				LL tt = (a[j] - len - 1) % p[i].a + 1;
				ans[j] = q[tt];
			}
			j++;
		}
		len = t;
	}
	for(int i = 1; i <= m; i++) printf("%d%c", ans[i], i == m ? '\n' : ' ');
}

int main()
{
	read();
	work();

	return 0;
}

你可能感兴趣的:(codeforces)