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. CountDownLatch/CyclicBarrier/Semaphore

    CountDownLatch 概念 让一些线程阻塞直到另一些线程完成一系列操作才被唤醒 CountDownLatch主要有两个方法,当一个或多个线程调用await方法时,调用线程就会被阻塞.其它线程调 ...

  2. thinkphp5和nginx不得不说的故事

    由于之前学习用的都是apsche,所以对ngnix一窍不通,在这里写给正在学习的同行,希望可以帮助到你们: 如果你不会用apache部署tp5的可以查看我之前发布的文章,里面有提到 phpstudy ...

  3. 徐州赛区网络预赛 D Easy Math

    比赛快结束的适合看了一下D题,发现跟前几天刚刚做过的HDU 5728 PowMod几乎一模一样,当时特兴奋,结果一直到比赛结束都一直WA.回来仔细一琢磨才发现,PowMod这道题保证了n不含平方因子, ...

  4. 【Linux常见命令】ls命令

    ls - list directory contents ls命令用于显示指定工作目录下之内容(列出目前工作目录所含之文件及子目录). 语法:  ls [OPTION]... [FILE]...  l ...

  5. 自定义View之Canvas使用

    自定义View的绘制流程一般都是这样:提前创建好Paint对象,重写onDraw(),把绘制代码卸载ondraw()里面,大致如下: Paint paint = new Paint(); @Overr ...

  6. Ngxin 开启CDN 日志获取不了真实IP的解决办法。

    nginx配置里面在http{ 后加入如下两行代码即可: set_real_ip_from 0.0.0.0/0;real_ip_header X-Forwarded-For; 重启nginx生效. 注 ...

  7. CodeForces - 1245 C - Constanze's Machine

    Codeforces Round #597 (Div. 2) Constanze is the smartest girl in her village but she has bad eyesigh ...

  8. 疯子的算法总结(六) 复杂排序算法 ① 归并排序 merge_sort()

    归并排序采取了分治的思想,每次分别排左半边和右半边,不断递归调用自己,直到只有一个元素递归结束,开始回溯,调用merge函数,合并两个有序序列,再合并的时候每次给末尾追上一个最大int这样就不怕最后一 ...

  9. P5960 差分约束算法模板

    差分约束 差分约束,一般用来解决有\(n\)个未知数,\(m\)个不等式方程的问题,形如: \[\begin{cases} \ x_{a_1}-x_{b_1}\leq y_1\\ \ x_{a_2}- ...

  10. RF(scalar/list/dict变量)

     一.scalar 变量 ${} 定义 scalar 变量 ${} 还用来取值 1.set variable  设置变量 ${name} Set Variable zhangsan log ${nam ...