TLE on#7 求调,玄一关
查看原帖
TLE on#7 求调,玄一关
1690315
DPOI楼主2025/6/14 18:03
#include<bits/stdc++.h>
using namespace std;
int a[3000006];
struct f{
    int num;
    int d;
};
int main(){
    stack<f>s;
    stack<int>s2;
    int n;cin>>n;
    for (int i=1;i<=n;++i)cin>>a[i];
    for (int i=n;i>=1;--i){
        while (!s.empty()&&s.top().d<=a[i])s.pop();
        if (!s.empty())s2.push((s.top().num));
        else s2.push(0);
        s.push({i,a[i]});
    }
    while (!s2.empty()){
        cout<<s2.top()<<" ";
        s2.pop();
    }
    return 0;
}
2025/6/14 18:03
加载中...