日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Beauty Of Unimodal Sequence(HDU-6592)

發(fā)布時間:2025/3/17 编程问答 15 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Beauty Of Unimodal Sequence(HDU-6592) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

Problem Description

You are given an array of?n?integers?a1,a2,...,an. We define that a sequence?p1,p2,...,pk(k∈[1,n])?is beautiful if and only if these conditions are met:

  • ?1≤p1<p2<?<pk≤n.
  • ?There exists?t(t∈[1,k])?satisfying?ap1<ap2<?<apt?and?apt>apt+1>?>apk.

You need to find all the longest beautiful sequences, and output the lexicographically smallest one and the lexicographically largest one in them.
Check the examples below for better understanding.

Input

There are multiple test cases.
Each case starts with a line containing a positive integer?n(n≤3×105).
The second line contains?n?integers?a1,a2,...,an(1≤ai≤109).
It is guaranteed that the sum of?Ns in all test cases is no larger than?106.

Output

For each test case, output two lines, the first of which depicts the lexicographically smallest one in longest beautiful sequences and the second of which depicts the lexicographically largest one in longest beautiful sequences.

Sample Input

7
1 4 2 5 7 4 6
3
1 2 3
3
3 2 1

Sample Output

1 2 4 5 6
1 3 4 5 7
1 2 3
1 2 3
1 2 3
1 2 3

題意:t 組數(shù)據(jù),每組給出一個長度為 n 的序列 a,求序列 a 的最長的字典序最小的單峰子序列、最大的單峰子序列

思路:

由于要求一個單峰子序列,那么可以正反各求一遍最長上升子序列 LIS,然后進(jìn)行模擬來尋找單峰子序列

求字典序最小時,首先找到第一個峰,然后利用單調(diào)棧從后向前找遞減的序列中下標(biāo)較小的,再向后找嚴(yán)格遞減的

求字典序最大時,首先找到最大的一個峰,然后從后向前依次找嚴(yán)格遞減的,再向后找 LIS 中下標(biāo)大的

Source Program

#include<iostream> #include<cstdio> #include<cstdlib> #include<string> #include<cstring> #include<cmath> #include<ctime> #include<algorithm> #include<utility> #include<stack> #include<queue> #include<vector> #include<set> #include<map> #include<unordered_map> #include<bitset> #define PI acos(-1.0) #define INF 0x3f3f3f3f #define LL long long #define Pair pair<LL,LL> LL quickPow(LL a,LL b){ LL res=1; while(b){if(b&1)res*=a; a*=a; b>>=1;} return res; } LL quickModPow(LL a,LL b,LL mod){ LL res=1; a=a%mod; while(b){if(b&1)res=(a*res)%mod; a=(a*a)%mod; b>>=1;} return res; } LL getInv(LL a,LL mod){ return quickModPow(a,mod-2,mod); } LL GCD(LL x,LL y){ return !y?x:GCD(y,x%y); } LL LCM(LL x,LL y){ return x/GCD(x,y)*y; } const double EPS = 1E-10; const int MOD = 998244353; const int N = 500000+5; const int dx[] = {-1,1,0,0,1,-1,1,1}; const int dy[] = {0,0,-1,1,-1,1,-1,1}; using namespace std;int a[N],pos1[N],pos2[N]; int dp[N]; int pos[N]; void getLIS(int n){//正著求一遍LISmemset(dp,INF,sizeof(dp));dp[0]=0;for(int i=1; i<=n; i++) { //正著求一遍LISpos1[i] = lower_bound(dp+1, dp+n+1, a[i])-dp;dp[pos1[i]]=a[i];}//反著求一遍LISmemset(dp,INF,sizeof(dp));dp[0]=0;for(int i=n;i>0;i--){pos2[i]=lower_bound(dp+1, dp+n+1, a[i])-dp;dp[pos2[i]]=a[i];} } vector<int> getSmallLEX(int n){int index=1;//記錄下標(biāo)int maxx=pos1[1]+pos2[1];for(int i=2; i<=n; i++) { //尋找第一個峰if(pos1[i]+pos2[i]>maxx) {maxx=pos1[i]+pos2[i];index=i;}}pos[pos1[index]]=a[index];stack<int> S;for(int i=index-1; i>0; i--) { //利用單調(diào)棧尋找滿足LIS的下標(biāo)if(a[i]>=pos[pos1[i]+1])continue;while(!S.empty()&&pos1[S.top()]<=pos1[i])S.pop();S.push(i);pos[pos1[i]]=a[i];}vector<int> res;while(!S.empty()) { //保存結(jié)果int temp=S.top();S.pop();res.push_back(temp);}res.push_back(index);for(int i=index+1; i<=n; i++) { //從第一個峰向后找遞減的int len=res.size();if(pos2[i]==pos2[res[len-1]]-1 && a[i]<a[res[len-1]])res.push_back(i);}return res; } vector<int> getLargeLEX(int n){int index=1;int maxx=pos1[1]+pos2[1];for(int i=2; i<=n; i++) { //找最后一個峰if(pos1[i]+pos2[i]>=maxx){maxx=pos1[i]+pos2[i];index=i;}}memset(pos, INF, sizeof(pos));stack<int> S;S.push(index);for(int i=index-1; i>0 ;i--) {//從前向后找遞減的if(pos1[i]==pos1[S.top()]-1 && a[i]<a[S.top()])S.push(i);}vector<int> res;while(!S.empty()){int temp=S.top();S.pop();res.push_back(temp);}for(int i=index+1; i<=n ;i++){if(a[i]>=pos[pos2[i]+1])continue;while(res.size()>=0 && pos2[i]>=pos2[res[res.size()-1]])res.pop_back();res.push_back(i);pos[pos2[i]]=a[i];}return res; } int main(){int n;while (scanf("%d",&n)!=EOF) {for(int i=1;i<=n;i++)scanf("%d",&a[i]);getLIS(n);vector<int> small=getSmallLEX(n);vector<int> large=getLargeLEX(n);int len=small.size();for(int i=0; i<len-1; i++)printf("%d ",small[i]);printf("%d\n",small[len-1]);for(int i=0; i<len-1; i++)printf("%d ",large[i]);printf("%d\n",large[len-1]);}return 0; }

?

總結(jié)

以上是生活随笔為你收集整理的Beauty Of Unimodal Sequence(HDU-6592)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 国产色无码精品视频国产 | 久久亚洲成人av | 成人在线a | 欧美不卡二区 | 久久青青国产 | 91快色| www奇米影视com | 亚洲激情成人网 | www.波多野结衣.com | 男人的天堂2019 | 亚洲顶级毛片 | 国产成人a亚洲精v品无码 | 少妇人妻偷人精品无码视频新浪 | 九九久久国产精品 | 国产精品亚洲AV色欲三区不卡 | 色黄大色黄女片免费中国 | 久久女 | 国产小视频自拍 | 国产福利在线播放 | 成人av在线网址 | 噜噜噜av| 激情五月婷婷网 | 亚洲综合一区中 | 日韩精品免费一区二区夜夜嗨 | 国产在线观看h | 国产成人精品一区二区在线小狼 | 日本大胆欧美人术艺术 | 青青久在线视频 | 黄色片成人 | 一级片小视频 | 91精品大片 | 国产日本一区二区 | 日韩精品视频在线看 | 日韩中文字幕2019 | 亚洲国产精彩视频 | 一区二区中文字幕在线观看 | 尤物在线观看视频 | 亚洲三级免费观看 | 传媒视频在线观看 | 97爱爱视频 | 在线91视频 | 午夜精品久久久久久久99老熟妇 | 在线观看免费黄色 | 亚洲高清久久久 | 欧美黄色片网站 | 日日夜夜狠狠干 | 亚洲性夜 | 成人欧美一区二区三区在线播放 | av之家在线| 92久久| 欧美黄色高清视频 | av中文字幕免费 | 在线视频你懂得 | 精品视频一区二区在线观看 | 天天看天天操 | 欧美性猛交xxx乱大交3蜜桃 | 三级视频久久 | 少妇的激情 | 久久天堂av | av免费观看网 | 麻豆md0077饥渴少妇 | 久久久精品美女 | 亚洲综合婷婷 | 午夜簧片| 久久久久久一 | 亚洲黄一区 | 97精品久久人人爽人人爽 | 九色论坛 | 高清一区二区三区四区五区 | 一区二区免费在线视频 | 免费在线看黄色 | 人人澡人人澡人人 | 四虎影视免费永久大全 | 免费观看黄色小视频 | 亚洲天堂久| 色老板精品凹凸在线视频观看 | 国产精品国产三级国产在线观看 | 黄色三级三级 | 欧美日韩字幕 | 精品国产一区二区三区四区 | 成人午夜精品无码区 | 亚洲熟妇一区二区三区 | 久久久噜噜噜久久 | 性欧美一区二区三区 | 国产欧美日韩免费 | 欧洲一级黄色片 | 中文字幕电影av | 这里只有精品视频在线观看 | 色网站免费 | 成人深夜在线 | 欧美mv日韩mv国产网站app | 亚洲精品久久久蜜桃 | 欧美一级二级三级视频 | 超碰色偷偷 | 天天色成人网 | 中文字幕视频网站 | 欧美精品在线观看一区二区 | 污视频在线观看免费 | 在线免费观看污视频 |