单调栈只用修改空格?
查看原帖
单调栈只用修改空格?
1409448
WXY_ShiXiaoJi楼主2024/7/31 09:06
#include<bits/stdc++.h>
using namespace std;
const int maxn = 3e6+10;
int n,a[maxn],f[maxn];
stack<int>stk;
int main(){
    cin>>n;
    for(int i=1;i<=n;i++) scanf("%d/n",&a[i]);
    for(int i=1;i<=n;i++){
        while(!stk.empty() && a[stk.top()]<a[i]){
            f[stk.top()]=i;
            stk.pop();
        }
        stk.push(i);
    }
    while(!stk.empty()){
        f[stk.top()]=0;
        stk.pop();
    }
    for(int i=1;i<=n;i++){
	printf("%d/n",f[i]);
	}
    return 0;
}
2024/7/31 09:06
加载中...