zoukankan      html  css  js  c++  java
  • 51nod1437 迈克步

    傻叉单调栈

    #include<cstdio>
    #include<cstring>
    #include<cctype>
    #include<algorithm>
    using namespace std;
    #define rep(i,s,t) for(int i=s;i<=t;i++)
    #define dwn(i,s,t) for(int i=s;i>=t;i--)
    #define clr(x,c) memset(x,c,sizeof(x))
    int read(){
    	int x=0;char c=getchar();
    	while(!isdigit(c)) c=getchar();
    	while(isdigit(c)) x=x*10+c-'0',c=getchar();
    	return x;
    }
    char sh[15];
    void print(int x){
    	int cnt=0;
    	while(x) sh[++cnt]=x%10,x/=10;
    	dwn(i,cnt,1) putchar(sh[i]+48);
    	putchar(32);
    }
    const int nmax=2e5+5;
    const int inf=0x7f7f7f7f;
    int a[nmax],ans[nmax],l[nmax],r[nmax],q[nmax];
    void maxs(int &a,int b){
    	if(a<b) a=b;
    }
    int main(){
    	int n=read();rep(i,1,n) a[i]=read();
    	l[1]=1;int cur=1;q[1]=1;
    	rep(i,2,n){
    		while(a[q[cur]]>=a[i]&&cur) --cur;
    	    l[i]=q[cur]+1;q[++cur]=i;
    	}
    	r[n]=n;cur=1;q[1]=n;q[0]=n+1;
    	dwn(i,n-1,1){
    		while(a[q[cur]]>=a[i]&&cur) --cur;
    		r[i]=q[cur]-1;q[++cur]=i;
    	}
    	rep(i,1,n) maxs(ans[r[i]-l[i]+1],a[i]);
    	int tmp=0;
    	dwn(i,n,1) maxs(ans[i],tmp),maxs(tmp,ans[i]);
    	rep(i,1,n) print(ans[i]);printf("
    ");
    	return 0;
    }
    

      

    题目来源: CodeForces
    基准时间限制:1 秒 空间限制:131072 KB 分值: 80 难度:5级算法题
     收藏
     关注

    有n只熊。他们站成一排队伍,从左到右依次1到n编号。第i只熊的高度是ai。

    一组熊指的队伍中连续的一个子段。组的大小就是熊的数目。而组的力量就是这一组熊中最小的高度。

    迈克想知道对于所有的组大小为x(1 ≤ x ≤ n)的,最大力量是多少。

    Input
    单组测试数据。
    第一行有一个整数n (1 ≤ n ≤ 2×10^5),表示熊的数目。
    第二行包含n个整数以空格分开,a1, a2, ..., an (1 ≤ ai ≤ 10^9),表示熊的高度。
    Output
    在一行中输出n个整数,对于x从1到n,输出组大小为x的最大力量。
    Input示例
    10
    1 2 3 4 5 4 3 2 1 6
    Output示例
    6 4 4 3 3 2 2 1 1 1
  • 相关阅读:
    POJ 1401 Factorial
    POJ 2407 Relatives(欧拉函数)
    POJ 1730 Perfect Pth Powers(唯一分解定理)
    POJ 2262 Goldbach's Conjecture(Eratosthenes筛法)
    POJ 2551 Ones
    POJ 1163 The Triangle
    POJ 3356 AGTC
    POJ 2192 Zipper
    POJ 1080 Human Gene Functions
    POJ 1159 Palindrome(最长公共子序列)
  • 原文地址:https://www.cnblogs.com/fighting-to-the-end/p/5910741.html
Copyright © 2011-2022 走看看