C. Two Shuffled Sequences

Two integer sequences existed initially — one of them was strictly increasing, and the other 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.

They were merged into one sequence aaaaaa[1,3,4][1,3,4][10,4,2][10,4,2][1,2,3,4,4,10][1,2,3,4,4,10][4,2,1,10,4,3][4,2,1,10,4,3]

This shuffled 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 the other 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 to increasing and decreasing sequences, 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

Otherwise print "YES" in the first line and any two suitable sequences. Note that the empty sequence and the sequence consisting of one element can be considered as increasing or decreasing.

In the second line print nininini

In the third line print niniinc1,inc2,…,incniinc1,inc2,…,incniinc1<inc2<⋯<incniinc1<inc2<⋯<incnini=0ni=0

In the fourth line print ndnd — the number of elements in the strictly decreasing sequence. ndnd can be zero, in this case the decreasing sequence is empty.

In the fifth line print ndnddec1,dec2,…,decnddec1,dec2,…,decnddec1>dec2>⋯>decnddec1>dec2>⋯>decndnd=0nd=0

ni+ndni+ndn

代码:

 #include<iostream>
#include<algorithm>
#include<set>
using namespace std;
int main() {
int zen[],b[],c[];
int n,zhi,count=,jishu2=;
cin>>n;
set<int> a,d;
for(int i=; i<n; i++) {
cin>>zhi;
if(a.count(zhi)) {
c[jishu2++]=zhi;
if(d.count(zhi)) {
cout<<"No";
return ;
}
d.insert(zhi);
}
a.insert(zhi);
b[i]=zhi;
}
for(set<int>::iterator it=a.begin(); it!=a.end(); it++) {
zen[count++]=*it;
}
sort(zen,zen+count,greater<int>());
sort(c,c+jishu2);
cout<<"Yes"<<endl;
cout<<jishu2<<endl;
for(int i=; i<jishu2; i++) {
cout<<c[i]<<" ";
}
cout<<endl;
cout<<count<<endl;
for(int i=; i<count; i++) {
cout<<zen[i]<<" ";
}
cout<<endl;
}

思路分析:先将所有数存集合中,然后将集合中数存到个数组中再对数组从大到小排序。然后便利,将集合中已存在元素存到新数组中作为递增序列。

题目链接:https://codeforces.com/contest/1144/problem/C

Codeforces1144C(C题)Two Shuffled Sequences的更多相关文章

  1. codeforces#FF DIV2C题DZY Loves Sequences(DP)

    题目地址:http://codeforces.com/contest/447/problem/C C. DZY Loves Sequences time limit per test 1 second ...

  2. CodeForces Round #550 Div.3

    http://codeforces.com/contest/1144 A. Diverse Strings A string is called diverse if it contains cons ...

  3. CF550 DIV3

    A - Diverse Strings CodeForces - 1144A A string is called diverse if it contains consecutive (adjace ...

  4. [UCSD白板题] Longest Common Subsequence of Three Sequences

    Problem Introduction In this problem, your goal is to compute the length of a longest common subsequ ...

  5. 【刷题】BZOJ 4059 [Cerc2012]Non-boring sequences

    Description 我们害怕把这道题题面搞得太无聊了,所以我们决定让这题超短.一个序列被称为是不无聊的,仅当它的每个连续子序列存在一个独一无二的数字,即每个子序列里至少存在一个数字只出现一次.给定 ...

  6. Bracket Sequences Concatenation Problem CodeForces - 990C(括号匹配水题)

    明确一下  一个字符串有x左括号不匹配  和 另一个字符串有x个右括号不匹配  这俩是一定能够匹配的 脑子有点迷 emm... 所以统计就好了  统计x个左括号的有几个,x个右括号的有几个 然后 乘一 ...

  7. 【atcoder】Two Sequences [arc092 D](思维题)

    题目传送门:https://arc092.contest.atcoder.jp/tasks/arc092_b 这场arc好难啊...这场感觉不像正常的arc...其实这道题还可以更早写出来的,但是蒟蒻 ...

  8. 第31题:LeetCode946. Validate Stack Sequences验证栈的序列

    题目 给定 pushed 和 popped 两个序列,只有当它们可能是在最初空栈上进行的推入 push 和弹出 pop 操作序列的结果时,返回 true:否则,返回 false . 示例 1: 输入: ...

  9. [LeetCode] Repeated DNA Sequences 求重复的DNA序列

    All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACG ...

随机推荐

  1. C语言如何实现继承及容器

    继承的概念 继承是面向对象软件技术当中的一个概念,与多态.封装共为面向对象的三个基本特征.继承可以使得子类具有父类的属性和方法或者重新定义,追加属性和方法. 面向对象中的重要概念就是类,在我们熟知的编 ...

  2. lua实现游戏抽奖的几种方法

    ^_^内容原创,禁止转载  假设配置如下: local reward_pool = { {weight = , item = {, num = }}, {weight = , item = {, nu ...

  3. 详解PHP中instanceof关键字及instanceof关键字有什么作用

    来源:https://www.jb51.net/article/74409.htm PHP5的另一个新成员是instdnceof关键字.使用这个关键字可以确定一个对象是类的实例.类的子类,还是实现了某 ...

  4. 2019.11.13课堂实验之用Linux下的shell脚本完成两文本交替输出

    有两个文本如下,实际中并不知道两文本各有多少行: 文本1.txt aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ccccccccccccccccccccccccccc ...

  5. 字符串的z型转换

    class Solution(object):     def convert(self, s, numRows):         if numRows==1:             return ...

  6. Inno Setup [Run] Section 双引号嵌套

    https://stackoverflow.com/questions/26257808/inno-setup-how-to-run-a-code-procedure-in-run-section-o ...

  7. CCS进阶——div的宽度和高度是由什么决定的?

    核心知识 文档流/普通流(Normal Flow) 内联元素的宽高(高度是由行高决定的,宽度=内容+border+marging+padding) 块级元素的宽高(高度是内部文档流元素的高度总和,宽度 ...

  8. qemu-img压缩磁盘操作

    2019独角兽企业重金招聘Python工程师标准>>> qemu-img convert -c -f qcow2 -O qcow2 /data/data1.disk /opt/dat ...

  9. C++获取当前系统时间并格式化输出

    C++中与系统时间相关的函数定义在头文件中. 一.time(time_t * )函数 函数定义如下: time_t time (time_t* timer); 获取系统当前日历时间 UTC 1970- ...

  10. POJ2421 Constructing Roads 最小生成树

    修路 时限: 2000MS   内存限制: 65536K 提交总数: 31810   接受: 14215 描述 有N个村庄,编号从1到N,您应该修建一些道路,使每两个村庄可以相互连接.我们说两个村庄A ...