求调wa on #7~#10单调栈思路
查看原帖
求调wa on #7~#10单调栈思路
1104479
zombiell810975楼主2024/5/7 20:57

代码如下

	#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();
				//cout<<i<<' ';
			}
			p.push(a[i]);
		}
		for(int i=1;i<=n;i++) cout<<c[i]<<' ';
		return 0;
	}

感谢大佬救济蒟蒻

2024/5/7 20:57
加载中...