Codeforces1144C(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".
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.
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;
}
思路分析:先将所有数存集合中,然后将集合中数存到个数组中再对数组从大到小排序。然后便利,将集合中已存在元素存到新数组中作为递增序列。
Codeforces1144C(C题)Two Shuffled Sequences的更多相关文章
- codeforces#FF DIV2C题DZY Loves Sequences(DP)
题目地址:http://codeforces.com/contest/447/problem/C C. DZY Loves Sequences time limit per test 1 second ...
- CodeForces Round #550 Div.3
http://codeforces.com/contest/1144 A. Diverse Strings A string is called diverse if it contains cons ...
- CF550 DIV3
A - Diverse Strings CodeForces - 1144A A string is called diverse if it contains consecutive (adjace ...
- [UCSD白板题] Longest Common Subsequence of Three Sequences
Problem Introduction In this problem, your goal is to compute the length of a longest common subsequ ...
- 【刷题】BZOJ 4059 [Cerc2012]Non-boring sequences
Description 我们害怕把这道题题面搞得太无聊了,所以我们决定让这题超短.一个序列被称为是不无聊的,仅当它的每个连续子序列存在一个独一无二的数字,即每个子序列里至少存在一个数字只出现一次.给定 ...
- Bracket Sequences Concatenation Problem CodeForces - 990C(括号匹配水题)
明确一下 一个字符串有x左括号不匹配 和 另一个字符串有x个右括号不匹配 这俩是一定能够匹配的 脑子有点迷 emm... 所以统计就好了 统计x个左括号的有几个,x个右括号的有几个 然后 乘一 ...
- 【atcoder】Two Sequences [arc092 D](思维题)
题目传送门:https://arc092.contest.atcoder.jp/tasks/arc092_b 这场arc好难啊...这场感觉不像正常的arc...其实这道题还可以更早写出来的,但是蒟蒻 ...
- 第31题:LeetCode946. Validate Stack Sequences验证栈的序列
题目 给定 pushed 和 popped 两个序列,只有当它们可能是在最初空栈上进行的推入 push 和弹出 pop 操作序列的结果时,返回 true:否则,返回 false . 示例 1: 输入: ...
- [LeetCode] Repeated DNA Sequences 求重复的DNA序列
All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACG ...
随机推荐
- 用asp.net core结合fastdfs打造分布式文件存储系统
最近被安排开发文件存储微服务,要求是能够通过配置来无缝切换我们公司内部研发的文件存储系统,FastDFS,MongDb GridFS,阿里云OSS,腾讯云OSS等.根据任务紧急度暂时先完成了通过配置来 ...
- unset变量释放内存不起作用
unset()函数只能在变量值占用内存空间超过256字节时才会释放内存空间. 只有当指向该变量的所有变量(如引用变量)都被销毁后,才会释放内存.
- Qt 用户通过对话框选择文件
void class::on_pushButton_clicked() { fileFullPath = QFileDialog::getOpenFileName(this, tr("Sel ...
- [Inno Setup] 退出安装程序的两种方式
1. 完全静默的退出 procedure ExitProcess(exitCode:integer); external 'ExitProcess@kernel32.dll stdcall'; ... ...
- Mac自带编码转换工具iconv
iconv --help Usage: iconv [OPTION...] [-f ENCODING] [-t ENCODING] [INPUTFILE...] or: iconv -l Conver ...
- HTML模版组件
1.介绍 BootStrap (最好看的) css js [x] 学习 BootStrap 规则 jQueryUI (美观一般,偏后台.*) css js [x] 学习 jQueryUI 规则 Eas ...
- Vue 结合 echarts 原生 html5 实现拖拽排版报表系统
前言 不知道各位 coder 有没有碰到过许多重复的业务需求,比如排版相类似的报表,只不过是顺序稍微换了一下,就是一个新的页面,虽然基于模板思想来写的话也能减少不少代码,但是相对的不那么方便,笔者最近 ...
- 通用权限管理系统组件 (GPM - General Permissions Manager)
有的公司开发人员只那么几个,一个人支撑整个公司所有的IT系统实在有点累,不想自己写权限系统了,自己琢磨不也是要花时间和精力,要为此付出多少时间和汗水阿,细细的皱纹不知要多多少呢,重复建设不是白白浪费生 ...
- PHP字符串全排列算法
<?php /** * PHP字符串全排列算法 */ $results = []; $arr = []; function bfs($start) { global $arr; global $ ...
- vue父组件向子组件传对象,不实时更新解决
vue报错:void mutating a prop directly since the value will be overwritten whenever the parent componen ...