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

代码:

 1 #include<iostream>
 2 #include<algorithm>
 3 #include<set>
 4 using namespace std;
 5 int main() {
 6     int zen[1000000],b[1000000],c[1000000];
 7     int n,zhi,count=0,jishu2=0;
 8     cin>>n;
 9     set<int> a,d;
10     for(int i=0; i<n; i++) {
11         cin>>zhi;
12         if(a.count(zhi)) {
13             c[jishu2++]=zhi;
14             if(d.count(zhi)) {
15                 cout<<"No";
16                 return 0;
17             }
18             d.insert(zhi);
19         }
20         a.insert(zhi);
21         b[i]=zhi;
22     }
23     for(set<int>::iterator it=a.begin(); it!=a.end(); it++) {
24         zen[count++]=*it;
25     }
26     sort(zen,zen+count,greater<int>());
27     sort(c,c+jishu2);
28     cout<<"Yes"<<endl;
29     cout<<jishu2<<endl;
30     for(int i=0; i<jishu2; i++) {
31         cout<<c[i]<<" ";
32     }
33     cout<<endl;
34     cout<<count<<endl;
35     for(int i=0; i<count; i++) {
36         cout<<zen[i]<<" ";
37     }
38     cout<<endl;
39 }

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

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

转载于:https://www.cnblogs.com/yuanhang110/p/11255906.html

Codeforces1144C(C题)Two Shuffled Sequences相关推荐

  1. Two Shuffled Sequences

    C. Two Shuffled Sequences time limit per test2 seconds memory limit per test256 megabytes inputstand ...

  2. DAY1 Two Shuffled Sequences

    C. Two Shuffled Sequences time limit per test2 seconds memory limit per test256 megabytes inputstand ...

  3. C. Two Shuffled Sequences

    Two integer sequences existed initially - one of them was strictly increasing, and the other one - s ...

  4. CodeForces - 1144C Two Shuffled Sequences【优先队列】

    Two Shuffled Sequences 题意: 将给定数组分成两组,其中一组严格递增,另一组严格递减. 题解: 要点在于数组中元素必须是严格递增或递减的,就是说一个元素不能在一个数组中重复出现. ...

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

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

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

    Two integer sequences existed initially - one of them was strictly increasing, and the other one - s ...

  7. 1144C C. Two Shuffled Sequences(优先队列和set的应用)

    Two integer sequences existed initially - one of them was strictly increasing, and the other one - s ...

  8. CodeForces1144 C - Two Shuffled Sequences

    题目: 传送门 思路: 判断是否有一个数重复了三次以上,如果有则不能构成,然后将所给序列从小到大排序,取一个上升的序列,剩下的数从大往小就下降的序列,输出即可 vector<int> v1 ...

  9. CF1144C - Two Shuffled Sequences

    题意:把一个序列分成完全递增和完全递减的两个序列(即不可有相等的两个数),无元素或者只有一个元素也可认为是递增或递减,可行则按要求输出,不可行则输出NO. 题解:看有没有数字重复三次或以上的,若只出现 ...

最新文章

  1. php 图片处理类,分享php多功能图片处理类
  2. 无参数实例化Configuration对象以及addResource无法加载core-site.xml中的内容
  3. ubuntu16.04上安装gstreamer
  4. 英特尔nuc能代替主机吗_终于圆满了!最新款的Intel NUC迷你主机上线
  5. 交错字符串Python解法
  6. 2012智能管道技术创新与应用实践论…
  7. mysql取出qq表情_mysql存储emoji表情报错处理,qq互联mysql存储昵称中带表情的数据时报错。...
  8. 频谱仪测试gsm信号测试软件,怎样用频谱分析仪测试和分析GSM信号
  9. 技巧积累篇--Dashboard使用技巧
  10. Win10设置热点IP
  11. psn注册什么服务器,怎么注册PSN港服账号?PSN港服官网注册教程
  12. 如何调用Sphinx 和api接口
  13. 如何解决笔记本键盘某一个键一直在自动按下
  14. 汽车ELV报废车辆指令测试
  15. 单片机4人抢答器程序C语言,基于单片机的4人抢答器.pdf
  16. *POJ3666.Making the Grade(DP+离散化)
  17. 最佳实践 · 卓岚串口服务器接入 MODBUS 物联网平台
  18. Logon vs Login
  19. U74LV1T08G-SOT353R-TG utc友顺科技
  20. 解决服务器不能复制粘贴的方法

热门文章

  1. 算法学习系列(贪心算法)—多处最优服务次序问题
  2. 计算机网络,概念,发展历史,分类,协议
  3. 我们如何获取信息,组织知识
  4. Java锁与线程的那些“不可描述”的事儿
  5. codeforces 722C Destroying Array
  6. nodeclub迁移至nodebb
  7. node文件通过不同的后缀名解析不同的文件类型
  8. linux用户管理(1)----创建用户(adduser和useradd)和删除用户(userdel)
  9. Mac网络正常但是所有浏览器无法上网问题解决
  10. 翻译程序、编译程序和解释程序的区别和联系