C. Two Shuffled Sequences

time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
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 aa. After that sequence aa got shuffled. For example, some of the possible resulting sequences aa for an increasing sequence [1,3,4][1,3,4] and a decreasing sequence [10,4,2][10,4,2] are sequences [1,2,3,4,4,10][1,2,3,4,4,10] or [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 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 nini — the number of elements in the strictly increasing sequence. nini can be zero, in this case the increasing sequence is empty.

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

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 ndnd integers dec1,dec2,…,decnddec1,dec2,…,decnd in the decreasing order of its values (dec1>dec2>⋯>decnddec1>dec2>⋯>decnd) — the strictly decreasing sequence itself. You can keep this line empty if nd=0nd=0 (or just print the empty line).

ni+ndni+nd should be equal to nn 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

思路&过程

先排序,然后有重复的话就升序丢一个降序丢一个,如果连着三个一样就不符合。
一开始WA了,之后发现是有个地方数组下标越界了,然后如果遇到0这种极端情况就会出问题。

#include<iostream>
#include<algorithm>
using namespace std;int main()
{int n,m,i,j,k,p,q;bool t;static int a[200010],b[200010],c[200010];cin>>n;for(i=0;i<n;i++){cin>>a[i];}sort(a,a+n);i=0;p=0;q=0;t=true;while((i<n)&&(t)){if((i<n-2)&&(a[i]==a[i+1])&&(a[i+1]==a[i+2])){cout<<"NO"<<endl;t=false;   }if((a[i]==a[i+1])&&(i+1<n)){p=p+1;q=q+1;b[p]=a[i];c[q]=a[i];i=i+2;} else{q=q+1;c[q]=a[i];i=i+1;}}if (t){cout<<"YES"<<endl;cout<<p<<endl;for(i=1;i<=p;i++) cout<<b[i]<<" ";cout<<endl;cout<<q<<endl;for(i=q;i>=1;i--) cout<<c[i]<<" ";}return 0;
}在这里插入代码片

DAY1 Two Shuffled Sequences相关推荐

  1. Two Shuffled Sequences

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

  2. C. Two Shuffled Sequences

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

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

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

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

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

  5. Codeforces1144C(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. java arraylist优点_Java中各种集合的特点总结
  2. 最人性化的在线作图工具
  3. bool查询原理 es_ES系列之原理copy_to用好了这么香
  4. [vue] 怎么捕获组件vue的错误信息?
  5. Windows跟Linux的不同处理
  6. 物联网碰到云计算会怎么样?
  7. 知识图谱入门 , 知识抽取
  8. php mysql link_php与mysql连接
  9. mysql backup 使用_mysqlbackup (官方使用)
  10. xp系统能不能安装mysql_XP系统如何安装SQL2005?XP系统安装SQL2005图文教程
  11. 第一课----色彩构成与色彩模式
  12. IDEA 导出java文档
  13. Unity Fingers Gesture手势插件教程(新)
  14. 【saltstack】认证失败,无法生成minion_master.pub问题处理总结
  15. FireFox-background
  16. springboot启动时自动关闭问题 com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Shutdown initiated...
  17. Android个人信息页面
  18. JavaScript - 从身份证号中获取生日
  19. PDF矢量图片转为EPS格式图片的方法
  20. 支付宝html5接入,app和h5怎样对接支付宝支付接口?

热门文章

  1. iphone计算机的声音怎么办,苹果耳机插电脑上没声音怎么办_苹果耳机插win10电脑没声音如何解决-win7之家...
  2. 微信小程序跳转微信内置浏览器
  3. java 内存 监控_Java内存监视
  4. VS2015专业版+opencv3.3环境配置以及出现计算机中丢失 opencv_world300d.dll的问题
  5. PowerBI-逻辑函数-SWITCH
  6. Centos下搭建个人网站
  7. android 4.4以上sd卡,怎样无根绕过Android 4.4(KitKat)外部SD卡限制
  8. 解决springboot警告WARNING: All illegal access operations will be denied in a future release
  9. php 验证手机号码格式
  10. (论文笔记)An Attention Enhanced Graph Convolutional LSTM Network for Skeleton-Based Action Recognition