Codeforces 1144 G

http://codeforces.com/problemset/problem/1144/G

Two integer sequences existed initially, one of them was strictly increasing, and another one — strictly decreasing.

Strictly increasing sequence is a sequence of integers [x1<x2<⋯<xk][x1<x2<⋯<xk] . And strictly decreasing sequence is a sequence of integers [y1>y2>⋯>yl][y1>y2>⋯>yl] . Note that the empty sequence and the sequence consisting of one element can be considered as increasing or decreasing.

Elements of increasing sequence were inserted between elements of the decreasing one (and, possibly, before its first element and after its last element) without changing the order. For example, sequences [1,3,4][1,3,4] and [10,4,2][10,4,2] can produce the following resulting sequences: [10,1,3,4,2,4][10,1,3,4,2,4] , [1,3,4,10,4,2][1,3,4,10,4,2] . The following sequence cannot be the result of these insertions: [1,10,4,4,3,2][1,10,4,4,3,2] because the order of elements in the increasing sequence was changed.

Let the obtained sequence be aa . This sequence aa is given in the input. Your task is to find any two suitable initial sequences. One of them should be strictly increasing, and another one — strictly decreasing. Note that the empty sequence and the sequence consisting of one element can be considered as increasing or decreasing.

If there is a contradiction in the input and it is impossible to split the given sequence aa into one increasing sequence and one decreasing sequence, print "NO".

Input

The first line of the input contains one integer nn (1≤n≤2⋅1051≤n≤2⋅105 ) — the number of elements in aa .

The second line of the input contains nn integers a1,a2,…,ana1,a2,…,an (0≤ai≤2⋅1050≤ai≤2⋅105 ), where aiai is the ii -th element of aa .

Output

If there is a contradiction in the input and it is impossible to split the given sequence aa into one increasing sequence and one decreasing sequence, print "NO" in the first line.

Otherwise print "YES" in the first line. In the second line, print a sequence of nn integers res1,res2,…,resnres1,res2,…,resn , where resiresi should be either 00 or 11 for each ii from 11 to nn . The ii -th element of this sequence should be 00 if the ii -th element of aa belongs to the increasing sequence, and 11 otherwise. Note that the empty sequence and the sequence consisting of one element can be considered as increasing or decreasing.

Examples

Input

9
5 1 3 6 8 2 9 0 10

Output

YES
1 0 0 0 0 1 0 1 0 

Input

5
1 2 4 0 2

Output

NO

题目大意:给一个序列,让你分成两个序列,一个严格递增,一个严格递减,两个序列的元素个数之和为n,(某一个序列的长度可以为0)但是不能改变原序列的数字位置,如果可以输出"YES", 并输出方案。(懒得翻译了orz)

思路: 其实就是基础贪心吧。 递增序列肯定希望最后一个数最小,递减序列肯定希望最后一个数最大,然而对于ai要么属于递增序列,要么属于递减序列,因此比较ai和a(i+1)的大小,若ai>a(i+1),则把ai放到递减序列尾部,否则放到递增序列尾部。 注意一下不符合题意的判定以及相等元素的判定就好了。 当然,这个贪心只是我们要优先考虑, 如果不能放入我们希望的序列,那么就只能放入另外一个序列了。

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<map>
#include<cstring>
#define INF 0x3f3f3f3f
using namespace std;

int a[200005];
int b[200005];//升序
int c[200005];//降序
int vis[200005];
int re[200005];
int len1,len2;

int main()
{
	int n;
	scanf("%d",&n);
	int flag=0;
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		if(++vis[a[i]]>2)
			flag=1;
	}
	if(flag)
		printf("NO\n");
	else
	{
		flag=0;
		b[len1++]=-1;
		c[len2++]=INF;
		for(int i=0;i<n;i++)
		{
			if(a[i]>=c[len2-1]&&a[i]<=b[len1-1])
			{
				flag=1;
				break;
			}
			if(a[i]==c[len2-1])
				b[len1++]=a[i];
			else if(a[i]==b[len1-1])
			{
				c[len2++]=a[i];
				re[i]=1;
			}
			else if(a[i]>=a[i+1])//尽量放到下降序列中
			{
				if(a[i]<c[len2-1])
				{
					c[len2++]=a[i];
					re[i]=1;
				}
				else
					b[len1++]=a[i];
			}
			else if(a[i]<a[i+1])//尽量放到上升序列中
			{
				if(a[i]>b[len1-1])
					b[len1++]=a[i];
				else
				{
					c[len2++]=a[i];
					re[i]=1;
				}
			}
		}
		if(flag)
			printf("NO\n");
		else
		{
			printf("YES\n");
			for(int i=0;i<n;i++)
				printf("%d ",re[i]);
			printf("\n");
		}
	}
	return 0;
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值