求助#8超时了,1.03s
查看原帖
求助#8超时了,1.03s
1497053
Featherwit022楼主2024/12/25 09:01
#include<iostream>
#include<stack>
using namespace std;
const int MAX=3e6+5;
int arr[MAX],n;
struct element{
	int index;
	int value;
}x;
int main(){	
	stack<element >Stack;
	stack<element >temp;
	cin>>n;
	for(int i=1;i<=n;++i){
		cin>>x.value;
		x.index=i;
		while(!Stack.empty()&&Stack.top().value<x.value){
				temp.push(Stack.top());
				if(!arr[Stack.top().index]){
					arr[Stack.top().index]=x.index;
				}
				Stack.pop();
		}
		Stack.push(x);
		while(!temp.empty()){
			Stack.push(temp.top());
			temp.pop();
		}
	}
	
	for(int i=1;i<=n;++i){
		cout<<arr[i]<<' ';
	}
	
	return 0;
} 
2024/12/25 09:01
加载中...