Problem 2974 --Beauty Of Unimodal Sequence

2974: Beauty Of Unimodal Sequence

"
Time Limit $4$ 秒/Second(s) Memory Limit $512$ 兆字节/Megabyte(s)
提交总数 $2$ 正确数量 $2$
裁判形式 标准裁判/Standard Judge 我的状态 尚未尝试
难度 分类标签
You are given an array of nn integers a1,a2,...,ana1,a2,...,an. We define that a sequence p1,p2,...,pk(k∈[1,n])p1,p2,...,pk(k∈[1,n]) is beautiful if and only if these conditions are met: 

 ∙∙ 1≤p1<p2<⋯<pk≤n.1≤p1<p2<⋯<pk≤n. 

 ∙∙ There exists t(t∈[1,k])t(t∈[1,k]) satisfying ap1<ap2<⋯<aptap1<ap2<⋯<apt and apt>apt+1>⋯>apkapt>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.
There are multiple test cases. 

Each case starts with a line containing a positive integer n(n≤3×105)n(n≤3×105)

The second line contains nn integers a1,a2,...,an(1≤ai≤109)a1,a2,...,an(1≤ai≤109)

It is guaranteed that the sum of NNs in all test cases is no larger than 106106.
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.
7
1 4 2 5 7 4 6
3
1 2 3
3
3 2 1
1 2 4 5 6
1 3 4 5 7
1 2 3
1 2 3
1 2 3
1 2 3

推荐代码 查看2974 所有题解 上传题解视频得图灵币

本题记录 用 户(点击查看用户) 运行号(点击购买题解) 时 间
算法最快[$1259 $ms] 刘成健 480482 2019-10-08 20:32:18
内存最少[$21268 $KB] 淡意的温柔 605349 2020-07-03 15:13:02
第一AC 刘成健 480482 2019-10-08 20:32:18
第一挑战 刘成健 480482 2019-10-08 20:32:18

赛题来源/所属竞赛 2019 Multi-University Training Contest 2 N/A

竞赛编号 竞赛名称 竞赛时间 访问比赛