A.Rearranging a Sequence---2016筑波区域赛

Rearranging a Sequence

题目链接http://acm.csu.edu.cn:20080/csuoj/problemset/problem?pid=2291

Description

You are given an ordered sequence of integers, (1, 2, 3, . . . , n). Then, a number of requests will be given. Each request specifies an integer in the sequence. You need to move the specified integer to the head of the sequence, leaving the order of the rest untouched. Your task is to find the order of the elements in the sequence after following all the requests successively

Input

The input consists of a single test case of the following form.
n m
e1
.
.
.
em
The integer n is the length of the sequence (1 ≤ n ≤ 200000). The integer m is the number
of requests (1 ≤ m ≤ 100000). The following m lines are the requests, namely e1, . . . , em, one per line. Each request ei (1 ≤ i ≤ m) is an integer between 1 and n, inclusive, designating the element to move. Note that, the integers designate the integers themselves to move, not their positions in the sequence.

Output

Output the sequence after processing all the requests. Its elements are to be output, one per line, in the order in the sequence

Sample Input

10 8
1
4
7
3
4
10
1
3

Sample Output

3
1
10
4
7
2
5
6
8
9


题目大意:你刚开始有1到n个数,现在要将m个数按顺序调到最前面,输出最后的顺序
emmm,签到题,保存一下m个数的顺序然后倒着输出就行了,然后记得标记一下就OK了:

#include <cstdio>
int a[200040],v[200040];
int main()
{
	int n,m;
	scanf ("%d%d",&n,&m);
	for (int i=1; i<=m; i++){
		scanf ("%d",&a[i]);
	}
	for (int i=m; i>=1; i--){
		if (!v[a[i]]) {
			printf ("%d\n",a[i]);
			v[a[i]]=1;
		}
	}
	for (int i=1; i<=n; i++){
		if (!v[i]) {
			printf ("%d\n",i);
			v[i]=1;
		}
	} 
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值