C

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][x1y2>⋯>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 increasingsequence. 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

In the fourth line print ndnd — the number of elements in the strictly decreasingsequence. 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).

A.Diverse Strings+B.Parity Alternated Deletions+C. Two Shuffled Sequences+D. Equalize Them All - 菜鸡成长史 - CSDN博客

Two Shuffled Sequences - 轻舟载君不载愁 - CSDN博客


您将得到一个由nn整数组成的数组aa。您可以执行以下操作任意次数(可能为零):选择一对指数(i,j)(i,j),使i−j=1 i−j=1(指数i i和j j相邻),并设置a i:=a i+a i−a j a i:=a i+a i−a j选择一对指数(i,j)(i,j),使i−j=1 i−j=1(指数i i和j j相邻),并设置a i:=a i−a i−a j a i:=a i−a i−a j。数值x x表示x x的绝对值。例如,4=4 4=4,−3=3−3=3。您的任务是找到获取相等元素数组所需的最小操作数,并打印操作顺序。它保证您总是可以使用这些操作获得相等元素的数组。注意,每次操作后,当前数组的每个元素的绝对值不应超过10181018。输入输入的第一行包含一个整数n n(1≤n≤2 1051≤n≤2 105)——aa中的元素数。输入的第二行包含nn整数a1,a2,…,an a1,a2,…,an(0≤ai≤2 1050≤ai≤2 105),其中ai ai是aa的第二个元素。产量在第一行中,打印一个整数kk——获得相等元素数组所需的最小操作数。在下一个KK行中,打印操作本身。pp th操作应打印为整数的三倍(tp,ip,jp)(tp,ip,jp),其中tp tp是11或22(11表示执行第一种类型的操作,22表示执行第二种类型的操作),ip ip和jjp是数组相邻元素的索引,这样1≤ip,jp≤n1≤ip,jp≤n,ip−jp|=1 ip−jp=1.请参阅示例以获得更好的理解。注意,每次操作后,当前数组的每个元素的绝对值不应超过10181018。如果有许多可能的答案,您可以打印任何答案。

大意就是给你一个数组,问能否让每个元素进入递增或递减序列,最后形成一个严格递减和递增的序列。

我的理解:

就是给一个序列,如有三次重复数字,则输出No

如不重复,则要分成递增,递减数组,然后原序列中如果没有重复(只重复两次)就全给递减序列,如果有重复,重复的递增给递增序列。



网上找的并理解的代码
#include<stdio.h>

#include<stdlib.h>

#include<string.h>

#include<algorithm>

#include<iostream>

using namespace std;

int a[200005];//用来存合成序列

int b[200005];//用来存递增序列

int c[200005];//用来存递减序列

int main(){

int n;

int i;

while(scanf("%d",&n)!=EOF){

int count1=0;//用来存递减序列的个数

int count2=0;//用来存递增序列的个数

int flag=0;//用来判断数组中是否有三个相同的数

int w=0;//数组c的下标

int v=0;//数组b的下标

for(i=0;i<n;i++){

scanf("%d",&a[i]);

}

sort(a,a+n); //sort排序:低到高

if(n==1){       

printf("YES\n");     

printf("0\n");

printf("\n");

printf("1\n");

printf("%d\n",a[0]);

continue;

}

for(i=0;i<n-2;i++){

if(a[i]==a[i+1]){

if(a[i]==a[i+2]){//三个相同数的条件判断

flag=1;

break;

}

}

}

if(flag==1){

printf("NO\n");//三个相同直接输出No

continue;

}

else{

printf("YES\n");

}

for(i=0;i<n-1;i++){

if(a[i]!=a[i+1]){//无重复数字的情况

c[w]=a[i];//递减序列

count1++;

w++;

if(i==n-2){  //序列最后一个数字,不需要再加w

c[w]=a[i+1];

count1++;

}

}

else{          //有两个重复数字

c[w]=a[i];

b[v]=a[i+1];//一个放到递减一个到递增,递减先手

i++;

count1++;

count2++;

w++;

v++;

if(i==n-2){

c[w]=a[i+1];

count1++;

}

}

}

if(count2==0){          //无递增数列

printf("0\n");

printf("\n");

}

else{                  //有递增数列 ,输出

printf("%d\n",count2);

for(i=0;i<count2-1;i++)

printf("%d ",b[i]);

printf("%d\n",b[count2-1]);

}

//输出: (递减序列)

printf("%d\n",count1);

for(i=count1-1;i>0;i--)

printf("%d ",c[i]);

printf("%d\n",c[0]);

}

return 0;

}


大佬的代码:可能我修炼还不够吧

#include <bits/stdc++.h>

using namespace std;

const int maxn = 200000+5;

int main()

{

    int n; scanf("%d",&n);

    int vis[maxn]={0},a[maxn];

    int f=1;

    for(int i=0;i<n;i++){

        scanf("%d",&a[i]);

        vis[a[i]]++;

        if(vis[a[i]]>2) f=0;

    }

    if(f){

        puts("YES");

        sort(a,a+n);

        vector <int> v1,v2;

        v2.push_back(a[0]);

        for(int i=1;i<n;i++)

            if(a[i]==a[i-1]) v1.push_back(a[i]);

            else v2.push_back(a[i]);

        printf("%d\n",v1.size());

        for(int i=0;i<v1.size();i++)

            printf(i<v1.size()-1?"%d ":"%d",v1[i]);

        puts("");

        printf("%d\n",v2.size());

        for(int i=v2.size()-1;i>=0;i--)

            printf(i>0?"%d ":"%d\n",v2[i]);

    }

    else puts("NO");

    return 0;

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 217,734评论 6 505
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,931评论 3 394
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 164,133评论 0 354
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,532评论 1 293
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,585评论 6 392
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,462评论 1 302
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,262评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,153评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,587评论 1 314
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,792评论 3 336
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,919评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,635评论 5 345
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,237评论 3 329
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,855评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,983评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,048评论 3 370
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,864评论 2 354

推荐阅读更多精彩内容

  • 在C语言中,五种基本数据类型存储空间长度的排列顺序是: A)char B)char=int<=float C)ch...
    夏天再来阅读 3,342评论 0 2
  • 第1章 第一个C程序第2章 C语言基础第3章 变量和数据类型第4章 顺序结构程序设计第5章 条件结构程序设计第6章...
    小狮子365阅读 10,651评论 3 71
  • C语言的学习要从基础开始,这里是100个经典的算法-1C语言的学习要从基础开始,这里是100个经典的 算法 题目:...
    Poison_19ce阅读 1,138评论 0 0
  • 指针是C语言中广泛使用的一种数据类型。 运用指针编程是C语言最主要的风格之一。利用指针变量可以表示各种数据结构; ...
    朱森阅读 3,444评论 3 44
  • 2008年6月1日,正式实施。在方案没出太以前,各大媒体炒得沸沸扬扬,我在想限塑令给我带来哪些不便的同...
    韩小小鱼阅读 875评论 0 0