不理解为什么60
查看原帖
不理解为什么60
544756
xiaobing楼主2024/7/13 19:09
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=3e6+10,inf=1e9+10;
const ll INF=1e18+10;
int n,k;
stack<int>s;
int a[N];
int ans[N];
int main(){
    // freopen("train.in","r",stdin);
    // freopen("train.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int i=n;i>=1;i--){
        while(!s.empty()&&a[i]>a[s.top()])
            s.pop();
        ans[i]=s.empty()?0:s.top();
        s.push(i);
    }
    for(int i=1;i<=n;i++)
        cout<<ans[i]<<" ";
    return 0;
}
2024/7/13 19:09
加载中...