傳送門
Two Merged Sequences
AC代碼
#include<iostream>
#include<queue>
#include<algorithm>
using namespace std;
const int MAXN = 2e5+10;
int a[MAXN];
int up[MAXN], down[MAXN], flag[MAXN];
int high = -1;
int low = 0x3f3f3f;
int len1 = 0, len2 = 0;
int main(){
int n;
cin >> n;
for(int i = 0; i < n; i++){
cin >> a[i];
}
for(int i = 0; i < n; i++){
if(a[i] > high && a[i] < low){
if(a[i+1] > a[i]){
up[++len1] = a[i];
high = a[i];
flag[i] = 0;
}else{
down[++len2] = a[i];
low = a[i];
flag[i] = 1;
}
}
else if(a[i] > high){
up[++len1] = a[i];
high = a[i];
flag[i] = 0;
}else if(a[i] < low){
low = a[i];
down[++len2] = a[i];
flag[i] = 1;
}else{
cout << "NO" << endl;
return 0;
}
}
cout << "YES" << endl;
for(int i = 0; i < n; i++){
cout << flag[i] << " ";
}
cout << endl;
}
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者