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;
}

猜你喜欢

转载自blog.csdn.net/qq_43906000/article/details/89057952