• 个人简介

    using namespace std;
    int n,a[200005],lmin[200005],lmax[200005],rmin[200005],rmax[200005];
    stack<int> stk;
    void clr(){
    while(!stk.empty()) stk.pop();
    cout<<"\n";
    }
    int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++){
    cin>>a[i];
    }
    a[0]=-1;
    for(int i=1;i<=n;i++){
    while(!stk.empty()&&a[i]>=a[stk.top()]){
    stk.pop();
    }
    if(stk.empty()){
    lmax[i]=0;
    }
    else{
    lmax[i]=stk.top();
    }
    stk.push(i);
    }
    for(int i=1;i<=n;i++){
    cout<<a[lmax[i]]<<" ";
    }
    clr();
    for(int i=n;i>=1;i--){
    while(!stk.empty()&&a[i]>=a[stk.top()]){
    stk.pop();
    }
    if(stk.empty()){
    rmax[i]=0;
    }
    else{
    rmax[i]=stk.top();
    }
    stk.push(i);
    }
    for(int i=1;i<=n;i++){
    cout<<a[rmax[i]]<<" ";
    }
    clr();
    for(int i=1;i<=n;i++){
    while(!stk.empty()&&a[i]<=a[stk.top()]){
    stk.pop();
    }
    if(stk.empty()){
    lmin[i]=0;
    }
    else{
    lmin[i]=stk.top();
    }
    stk.push(i);
    }
    for(int i=1;i<=n;i++){
    cout<<a[lmin[i]]<<" ";
    }
    clr();
    for(int i=n;i>=1;i--){
    while(!stk.empty()&&a[i]<=a[stk.top()]){
    stk.pop();
    }
    if(stk.empty()){
    rmin[i]=0;
    }
    else{
    rmin[i]=stk.top();
    }
    stk.push(i);
    }
    for(int i=1;i<=n;i++){
    cout<<a[rmin[i]]<<" ";
    }
    return 0;
    }
    
    
  • 通过的题目

  • 最近活动

    This person is lazy and didn't join any contests or homework.
  • 最近编写的题解

    This person is lazy and didn't write any solutions.

题目标签

系统测试
1