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 - 菜雞成長(zhǎng)史 - CSDN博客

Two Shuffled Sequences - 輕舟載君不載愁 - CSDN博客


您將得到一個(gè)由nn整數(shù)組成的數(shù)組aa讯榕。您可以執(zhí)行以下操作任意次數(shù)(可能為零):選擇一對(duì)指數(shù)(i骤素,j)(i,j)愚屁,使i?j=1 i?j=1(指數(shù)i i和j j相鄰)济竹,并設(shè)置a i:=a i+a i?a j a i:=a i+a i?a j選擇一對(duì)指數(shù)(i,j)(i霎槐,j)送浊,使i?j=1 i?j=1(指數(shù)i i和j j相鄰),并設(shè)置a i:=a i?a i?a j a i:=a i?a i?a j丘跌。數(shù)值x x表示x x的絕對(duì)值袭景。例如唁桩,4=4 4=4,?3=3?3=3浴讯。您的任務(wù)是找到獲取相等元素?cái)?shù)組所需的最小操作數(shù)朵夏,并打印操作順序。它保證您總是可以使用這些操作獲得相等元素的數(shù)組榆纽。注意仰猖,每次操作后,當(dāng)前數(shù)組的每個(gè)元素的絕對(duì)值不應(yīng)超過(guò)10181018奈籽。輸入輸入的第一行包含一個(gè)整數(shù)n n(1≤n≤2 1051≤n≤2 105)——aa中的元素?cái)?shù)饥侵。輸入的第二行包含nn整數(shù)a1,a2衣屏,…躏升,an a1,a2狼忱,…膨疏,an(0≤ai≤2 1050≤ai≤2 105),其中ai ai是aa的第二個(gè)元素钻弄。產(chǎn)量在第一行中佃却,打印一個(gè)整數(shù)kk——獲得相等元素?cái)?shù)組所需的最小操作數(shù)。在下一個(gè)KK行中窘俺,打印操作本身饲帅。pp th操作應(yīng)打印為整數(shù)的三倍(tp,ip瘤泪,jp)(tp灶泵,ip,jp)对途,其中tp tp是11或22(11表示執(zhí)行第一種類型的操作赦邻,22表示執(zhí)行第二種類型的操作),ip ip和jjp是數(shù)組相鄰元素的索引实檀,這樣1≤ip惶洲,jp≤n1≤ip,jp≤n劲妙,ip?jp|=1 ip?jp=1.請(qǐng)參閱示例以獲得更好的理解。注意儒喊,每次操作后镣奋,當(dāng)前數(shù)組的每個(gè)元素的絕對(duì)值不應(yīng)超過(guò)10181018。如果有許多可能的答案怀愧,您可以打印任何答案侨颈。

大意就是給你一個(gè)數(shù)組余赢,問(wèn)能否讓每個(gè)元素進(jìn)入遞增或遞減序列,最后形成一個(gè)嚴(yán)格遞減和遞增的序列哈垢。

我的理解:

就是給一個(gè)序列妻柒,如有三次重復(fù)數(shù)字,則輸出No

如不重復(fù)耘分,則要分成遞增举塔,遞減數(shù)組,然后原序列中如果沒(méi)有重復(fù)(只重復(fù)兩次)就全給遞減序列求泰,如果有重復(fù)央渣,重復(fù)的遞增給遞增序列。



網(wǎng)上找的并理解的代碼
#include<stdio.h>

#include<stdlib.h>

#include<string.h>

#include<algorithm>

#include<iostream>

using namespace std;

int a[200005];//用來(lái)存合成序列

int b[200005];//用來(lái)存遞增序列

int c[200005];//用來(lái)存遞減序列

int main(){

int n;

int i;

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

int count1=0;//用來(lái)存遞減序列的個(gè)數(shù)

int count2=0;//用來(lái)存遞增序列的個(gè)數(shù)

int flag=0;//用來(lái)判斷數(shù)組中是否有三個(gè)相同的數(shù)

int w=0;//數(shù)組c的下標(biāo)

int v=0;//數(shù)組b的下標(biāo)

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]){//三個(gè)相同數(shù)的條件判斷

flag=1;

break;

}

}

}

if(flag==1){

printf("NO\n");//三個(gè)相同直接輸出No

continue;

}

else{

printf("YES\n");

}

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

if(a[i]!=a[i+1]){//無(wú)重復(fù)數(shù)字的情況

c[w]=a[i];//遞減序列

count1++;

w++;

if(i==n-2){? //序列最后一個(gè)數(shù)字渴频,不需要再加w

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

count1++;

}

}

else{? ? ? ? ? //有兩個(gè)重復(fù)數(shù)字

c[w]=a[i];

b[v]=a[i+1];//一個(gè)放到遞減一個(gè)到遞增芽丹,遞減先手

i++;

count1++;

count2++;

w++;

v++;

if(i==n-2){

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

count1++;

}

}

}

if(count2==0){? ? ? ? ? //無(wú)遞增數(shù)列

printf("0\n");

printf("\n");

}

else{? ? ? ? ? ? ? ? ? //有遞增數(shù)列 ,輸出

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;

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末卜朗,一起剝皮案震驚了整個(gè)濱河市拔第,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌场钉,老刑警劉巖蚊俺,帶你破解...
    沈念sama閱讀 217,734評(píng)論 6 505
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異惹悄,居然都是意外死亡春叫,警方通過(guò)查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,931評(píng)論 3 394
  • 文/潘曉璐 我一進(jìn)店門泣港,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)暂殖,“玉大人,你說(shuō)我怎么就攤上這事当纱∏好浚” “怎么了?”我有些...
    開(kāi)封第一講書(shū)人閱讀 164,133評(píng)論 0 354
  • 文/不壞的土叔 我叫張陵坡氯,是天一觀的道長(zhǎng)晨横。 經(jīng)常有香客問(wèn)我,道長(zhǎng)箫柳,這世上最難降的妖魔是什么手形? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 58,532評(píng)論 1 293
  • 正文 為了忘掉前任,我火速辦了婚禮悯恍,結(jié)果婚禮上库糠,老公的妹妹穿的比我還像新娘。我一直安慰自己涮毫,他們只是感情好瞬欧,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,585評(píng)論 6 392
  • 文/花漫 我一把揭開(kāi)白布贷屎。 她就那樣靜靜地躺著,像睡著了一般艘虎。 火紅的嫁衣襯著肌膚如雪唉侄。 梳的紋絲不亂的頭發(fā)上,一...
    開(kāi)封第一講書(shū)人閱讀 51,462評(píng)論 1 302
  • 那天野建,我揣著相機(jī)與錄音属划,去河邊找鬼。 笑死贬墩,一個(gè)胖子當(dāng)著我的面吹牛榴嗅,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播陶舞,決...
    沈念sama閱讀 40,262評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼嗽测,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了肿孵?” 一聲冷哼從身側(cè)響起唠粥,我...
    開(kāi)封第一講書(shū)人閱讀 39,153評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎停做,沒(méi)想到半個(gè)月后晤愧,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,587評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡蛉腌,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,792評(píng)論 3 336
  • 正文 我和宋清朗相戀三年官份,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片烙丛。...
    茶點(diǎn)故事閱讀 39,919評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡舅巷,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出河咽,到底是詐尸還是另有隱情钠右,我是刑警寧澤,帶...
    沈念sama閱讀 35,635評(píng)論 5 345
  • 正文 年R本政府宣布忘蟹,位于F島的核電站飒房,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏媚值。R本人自食惡果不足惜狠毯,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,237評(píng)論 3 329
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望褥芒。 院中可真熱鬧嚼松,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 31,855評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)少辣。三九已至凌摄,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間漓帅,已是汗流浹背锨亏。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 32,983評(píng)論 1 269
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留忙干,地道東北人器予。 一個(gè)月前我還...
    沈念sama閱讀 48,048評(píng)論 3 370
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像捐迫,于是被迫代替她去往敵國(guó)和親乾翔。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,864評(píng)論 2 354

推薦閱讀更多精彩內(nèi)容

  • 在C語(yǔ)言中,五種基本數(shù)據(jù)類型存儲(chǔ)空間長(zhǎng)度的排列順序是: A)char B)char=int<=float C)ch...
    夏天再來(lái)閱讀 3,342評(píng)論 0 2
  • 第1章 第一個(gè)C程序第2章 C語(yǔ)言基礎(chǔ)第3章 變量和數(shù)據(jù)類型第4章 順序結(jié)構(gòu)程序設(shè)計(jì)第5章 條件結(jié)構(gòu)程序設(shè)計(jì)第6章...
    小獅子365閱讀 10,651評(píng)論 3 71
  • C語(yǔ)言的學(xué)習(xí)要從基礎(chǔ)開(kāi)始,這里是100個(gè)經(jīng)典的算法-1C語(yǔ)言的學(xué)習(xí)要從基礎(chǔ)開(kāi)始赞哗,這里是100個(gè)經(jīng)典的 算法 題目:...
    Poison_19ce閱讀 1,138評(píng)論 0 0
  • 指針是C語(yǔ)言中廣泛使用的一種數(shù)據(jù)類型雷则。 運(yùn)用指針編程是C語(yǔ)言最主要的風(fēng)格之一。利用指針變量可以表示各種數(shù)據(jù)結(jié)構(gòu)肪笋; ...
    朱森閱讀 3,444評(píng)論 3 44
  • 2008年6月1日月劈,正式實(shí)施。在方案沒(méi)出太以前藤乙,各大媒體炒得沸沸揚(yáng)揚(yáng)猜揪,我在想限塑令給我?guī)?lái)哪些不便的同...
    韓小小魚(yú)閱讀 875評(píng)論 0 0