日韩性视频-久久久蜜桃-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)容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 久久久久久电影 | 97精品人妻一区二区三区在线 | 久久久久久网 | 婷婷伊人综合中文字幕 | 免费的一级片 | 亚洲久久在线观看 | 在线视频自拍 | 久久看片网| 日欧美女人| 久久极品视频 | 免费成人av在线播放 | 男女高潮网站 | 久久老司机精品视频 | 最新在线黄色网址 | 日本熟妇成熟毛茸茸 | 有码一区二区三区 | 久久手机免费视频 | 成人自拍视频在线 | 亚洲精品自拍视频 | 电影《两个尼姑》免费播放 | 欧美性生活 | 能直接看的av | 屁屁影院国产第一页 | 国产在线播放网站 | 92国产精品 | 永久免费汤不热视频 | 伊人成人在线视频 | 国产三级一区二区三区 | 特大黑人娇小亚洲女 | 欧亚乱熟女一区二区在线 | 亚洲精品麻豆 | 精品少妇人妻av一区二区三区 | 日韩一区二区三区视频在线 | 成人在线观看国产 | 伊人激情综合 | 美日韩免费视频 | 国产又好看的毛片 | 国产亚洲第一页 | 伊人蕉 | 蜜桃av久久久亚洲精品 | 亚洲国产成人一区二区精品区 | 国产视频1区2区 | missav|免费高清av在线看 | 亚洲国产私拍精品国模在线观看 | 一区二区三区精品免费视频 | 黄色成年视频 | 97看片网| 泰坦尼克号3小时49分的观看方法 | 国精产品一区一区三区免费视频 | 国产精品久久久久久久久毛片 | 91精品国产精品 | 日韩欧美视频一区 | www色日本 | 亚洲免费福利 | 欧美亚洲视频一区 | 夜夜操操操 | 国产不卡一区二区视频 | 日批动态图 | 麻豆av一区二区三区久久 | 午夜资源网 | 成人一区二区三区在线观看 | 日韩三级成人 | 在线视频h | 自拍偷拍校园春色 | 欧美在线观看一区 | 日本精品在线观看 | 一区二区三区国产在线观看 | 91精品在线视频观看 | 98色 | 男女日批网站 | www.com污 | av中文字幕一区二区三区 | 91视频福利| 婷婷狠狠 | 日日综合网 | 在线中文字幕一区 | 蜜乳av一区二区 | 99热这里只有精 | 极品粉嫩小仙女高潮喷水久久 | 无码粉嫩虎白一线天在线观看 | 亚洲av成人无码久久精品老人 | 亚洲无码久久久久 | 97久久久 | 免费看片色 | 看免费黄色片 | 麻豆影视国产在线观看 | 美女作爱网站 | av中文字幕观看 | 中文在线字幕免费观 | 亚洲欧美一区二区三区久久 | 麻豆国产一区二区三区四区 | 成人免费在线视频 | 精品国产av色一区二区深夜久久 | 成人深夜视频在线观看 | 久久精品99国产精品日本 | 中文字幕一区二区三区四区 | 美女在线播放 | 色妞干网| 国产精品久久在线观看 |