Codeforces Round #305 (Div. 1) B. Mike and Feet 单调栈
2015-05-27 13:55
274 查看
[b]B. Mike and Feet[/b]
Time Limit: 20 Sec Memory Limit: 256 MB题目连接
http://codeforces.com/contest/547/problem/BDescription
Mike is the president of country What-The-Fatherland. There are n bears living in this country besides Mike. All of them are standing in a line and they are numbered from 1 to n from left to right. i-th bear is exactly ai feet high.A group of bears is a non-empty contiguous segment of the line. The size of a group is the number of bears in that group. The strength of a group is the minimum height of the bear in that group.
Mike is a curious to know for each x such that 1 ≤ x ≤ n the maximum strength among all groups of size x.
[b]Input[/b]
The first line of input contains integer n (1 ≤ n ≤ 2 × 105), the number of bears.
The second line contains n integers separated by space, a1, a2, ..., an (1 ≤ ai ≤ 109), heights of bears.
[b]Output[/b]
Print n integers in one line. For each x from 1 to n, print the maximum strength among all groups of size x.
[b]Sample Input[/b]
10 1 2 3 4 5 4 3 2 1 6
Sample Output
6 4 4 3 3 2 2 1 1 1
HINT
[b]题意 [/b]给你一个堆数,对于(1,n)长度,让你找到线段的最小值的最大值是多少
[b]题解:[/b]
用一个类似单调栈的思想,处理以这个点为最小值可以往左右延伸多少,然后乱搞一下就好了
[b]代码:[/b]
//qscqesze #include <cstdio> #include <cmath> #include <cstring> #include <ctime> #include <iostream> #include <algorithm> #include <set> #include <vector> #include <sstream> #include <queue> #include <typeinfo> #include <fstream> #include <map> #include <stack> typedef long long ll; using namespace std; //freopen("D.in","r",stdin); //freopen("D.out","w",stdout); #define sspeed ios_base::sync_with_stdio(0);cin.tie(0) #define test freopen("test.txt","r",stdin) #define maxn 200001 #define mod 1000000007 #define eps 1e-9 int Num; char CH[20]; //const int inf=0x7fffffff; //нчоч╢С const int inf=0x3f3f3f3f; inline ll read() { ll x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } inline void P(int x) { Num=0;if(!x){putchar('0');puts("");return;} while(x>0)CH[++Num]=x%10,x/=10; while(Num)putchar(CH[Num--]+48); puts(""); } //************************************************************************************** int a[maxn]; int dp[maxn]; int l[maxn]; int r[maxn]; int main() { //test; int n=read(); for(int i=1;i<=n;i++) a[i]=read(); a[0]=-1,a[n+1]=-1; for(int i=1;i<=n;i++) { int j=i-1; while(a[j]>=a[i])j=l[j]; l[i]=j; } for(int i=n;i>=1;i--) { int j=i+1; while(a[j]>=a[i])j=r[j]; r[i]=j; } for(int i=1;i<=n;i++) { int len=r[i]-l[i]-1; dp[len]=max(dp[len],a[i]); } for(int i=n-1;i>=1;i--) dp[i]=max(dp[i+1],dp[i]); for(int i=1;i<=n;i++) cout<<dp[i]<<" "; }
10 1 2 3 4 5 4 3 2 1 6
相关文章推荐
- Codeforces Round #305 (Div. 2)——D单调/路径压缩——Mike and Feet
- Codeforces Round #305 (Div. 2) D. Mike and Feet 单调栈
- Codeforces Round #305 (Div. 1)-B. Mike and Feet(单调栈)
- set+线段树 Codeforces Round #305 (Div. 2) D. Mike and Feet
- Codeforces Round #305 (Div. 1) B. Mike and Feet(并查集)
- CodeForces Round #305 (div1) B. Mike and Feet
- CodeForces Round #305 (div1) B. Mike and Feet (单调栈)
- Codeforces Round #305 (Div. 1) B. Mike and Feet(单调栈)
- Codeforces Round #305 (Div. 1)B - Mike and Feet 线段树
- Codeforces Round #305 (Div. 1) B. Mike and Feet(思路)
- CF Mike and Feet (求连续区间内长度为i的最小值)单调栈
- Codeforces #305 div2 D. Mike and Feet 递推/单调栈
- CF 305 div2 D. Mike and Feet (递推)
- codeforces round305 div2 Mike and Feet 排序+并查集
- Codeforces Round #305 (Div. 2) 548D - Mike and Feet
- Codeforces Round #305 (Div. 2) D.Mike and Feet
- Codeforces Round #305 (Div. 2)D---Mike and Feet(单调栈)
- Codeforces Round #305 (Div. 2) D. Mike and Feet (单调栈)
- Codeforces Round #305 (Div. 1) B. Mike and Feet(单调栈)
- codeforces/#305 Div1/547/B Mike and Feet