CodeForces Round 223 Div 2 C Sereja and Prefixes

19 篇文章 0 订阅
14 篇文章 0 订阅

乱搞题..

题目链接 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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值