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]. And strictly decreasing sequence is a sequence of integers [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 a. After that sequence a got shuffled. For example, some of the possible resulting sequences a for an increasing sequence [1,3,4] and a decreasing sequence [10,4,2] are sequences [1,2,3,4,4,10] or [4,2,1,10,4,3].

This shuffled sequence a 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 a to increasing and decreasing sequences, print “NO”.

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

The second line of the input contains n integers a1,a2,…,an (0≤ai≤2⋅105), where ai is the i-th element of a.

Output
If there is a contradiction in the input and it is impossible to split the given sequence a to increasing and decreasing sequences, print “NO” in the first line.

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 ni — the number of elements in the strictly increasing sequence. ni can be zero, in this case the increasing sequence is empty.

In the third line print ni integers inc1,inc2,…,incni in the increasing order of its values (inc1<inc2<⋯<incni) — the strictly increasing sequence itself. You can keep this line empty if ni=0 (or just print the empty line).

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

In the fifth line print nd integers dec1,dec2,…,decnd in the decreasing order of its values (dec1>dec2>⋯>decnd) — the strictly decreasing sequence itself. You can keep this line empty if nd=0 (or just print the empty line).

ni+nd should be equal to n and the union of printed sequences should be a permutation of the given sequence (in case of “YES” answer).

Examples
inputCopy
7
7 2 7 3 3 1 4
outputCopy
YES
2
3 7
5
7 4 3 2 1
inputCopy
5
4 3 1 5 3
outputCopy
YES
1
3
4
5 4 3 1
inputCopy
5
1 1 2 1 2
outputCopy
NO
inputCopy
5
0 1 2 3 4
outputCopy
YES
0

5
4 3 2 1 0

思路:稍微想一下就知道如果重复的数有3个或以上,那么必然不能分成两个序列。那么我们就用一个vector数组表示每一个数出现的个数。递增顺序就是从开始到结束每一个出现两次的数,剩下的就满足递减序列

#include <bits/stdc++.h>using namespace std;int main() {int n;cin >> n;vector<int> cnt(200 * 1000 + 1);for (int i = 0; i < n; ++i) {int x;cin >> x;++cnt[x];if (cnt[x] > 2) {cout << "NO" << endl;return 0;}}cout << "YES" << endl;cout<<count(cnt.begin(), cnt.end(), 2) << endl;for (int i = 0; i <= 200 * 1000; ++i) {if (cnt[i] == 2) {cout << i << " ";--cnt[i];}}cout << endl;cout<<count(cnt.begin(), cnt.end(), 1) << endl;for (int i = 200 * 1000; i >= 0; --i) {if (cnt[i] == 1) {cout << i << " ";--cnt[i];}}cout << endl;return 0;
}

Codeforces Round #550 (Div. 3)C. Two Shuffled Sequences相关推荐

  1. Codeforces Round #550 (Div. 3) C.Two Shuffled Sequences

    C. Two Shuffled Sequences Two integer sequences existed initially - one of them was strictly increas ...

  2. Codeforces Round #631 (Div. 2) D. Dreamoon Likes Sequences 思维 + 组合数学

    传送门 文章目录 题意: 思路: 题意: 给你d,modd,modd,mod,让你求能构造出如下序列aaa的个数模modmodmod: 思路: 首先可以发现aaa的长度不能超过log2dlog_2dl ...

  3. Codeforces Round 550 (Div.3) 题解

    目录 A.DiverseStringsA.\ Diverse\ StringsA. Diverse Strings B.ParityAlternatedDeletionsB.\ Parity\ Alt ...

  4. Codeforces Round #550 (Div. 3)E. Median String

    把字符串看作是26进制的数,从后往前翻译,那么就可以把两个串变成对应的26进制的数字,那么只要把两个数加起来除以二就得到中间的串对应的数了,同理再转化回来就行了. 但是这样会有一个问题就是串的长度有2 ...

  5. Codeforces Round #FF (Div. 1) A. DZY Loves Sequences

    原题链接:http://codeforces.com/problemset/problem/446/A 题意:给一个长度为n的序列,最多可以修改一个位置的数,求最长连续上升子序列. 题解:当a[i+1 ...

  6. Codeforces Round #257 (Div. 2) B. Jzzhu and Sequences

    B. Jzzhu and Sequences time limit per test 1 second memory limit per test 256 megabytes input standa ...

  7. Codeforces Round 250(Div. 2)

    layout: post title: Codeforces Round 250 (Div. 2) author: "luowentaoaa" catalog: true tags ...

  8. Codeforces Round #506 (Div. 3)

    Codeforces Round #506 (Div. 3) 实习期间事不多,对div3 面向题解和数据编程了一波 A. Many Equal Substrings 题目链接 A题就是找后缀和前缀重合 ...

  9. Codeforces Round #563 (Div. 2)/CF1174

    Codeforces Round #563 (Div. 2)/CF1174 CF1174A Ehab Fails to Be Thanos 其实就是要\(\sum\limits_{i=1}^n a_i ...

最新文章

  1. 2021-11-18Collections
  2. C#修改系统环境变量,调用批处理bat
  3. 乐迪机器人开热点_碧桂园餐饮机器人量产!预计年产能达4000台
  4. 自定义你的VSCode:主题、文件图标、快捷键、设置、schema、插件
  5. hdu 3572 Task Schedule 网络流
  6. bzoj 3527 [Zjoi2014]力——FFT
  7. 文本文档html乱码,文本文档乱码怎么办?电脑文本文档乱码解决方法
  8. 焊接工时简便计算工具_焊接工时计算表
  9. 电信光猫找不到服务器,高手说说电信光猫没网如何设置?
  10. 计算机术语cal含义,计算机应用术语小释
  11. 【图像配准】基于sift算法实现图像配准matlab源码
  12. k8s节点假死排查记录
  13. kobo glo安装koreader(刷ksm后)
  14. CSS 实现炫酷的动态背景效果
  15. 梯度下降,随机梯度下降,代码实现
  16. 叮,一份详细的LIN收发器选型指南请查收
  17. Vue3计算属性和异步计算属性
  18. 3D Fe3O4@Au@Ag nanoflowers assembled magnetoplasmonic chains for in situ SERS monitoring of plasmon-
  19. 为什么说在数字角频率中:π附近的频率分量就是高频分量?
  20. shareaza源码编译

热门文章

  1. 技嘉显卡性能测试软件,技嘉RTX 3080 GAMING OC魔鹰显卡评测:全方位压倒前辈的新秀...
  2. unity -- 泛型
  3. 要是卢安娜的飓风可以触发所有远程英雄的技能,哪些英雄最强?
  4. 启动fiddler导致浏览器无法上网的解决方法
  5. Android关闭屏幕时不锁屏
  6. C++ 并发指南<future>(2)std::packaged_task
  7. 四川大学计算机系统 赵树龙,王俊峰
  8. css3 transition transform属性造成文字抖动
  9. 听说你想学Python爬虫?我从零教你啊
  10. 华南x79主板u盘装系统教程_华南主板win10改win7系统及BIOS设置教程