代码如下
#include<bits/stdc++.h>
using namespace std;
int n,c[3000005];
struct u{
int xx;
int yy;
};
u a[3000005];
stack<u > p;
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i].xx;
a[i].yy=i;
}
for(int i=1;i<=n;i++){
while(!p.empty()&&p.top().xx<=a[i].xx){
c[p.top().yy]=i;
p.pop();
}
p.push(a[i]);
}
for(int i=1;i<=n;i++) cout<<c[i]<<' ';
return 0;
}
感谢大佬救济蒟蒻