#include <iostream>
#include <vector>
#include <stack>
#include <algorithm>
using namespace std;
vector<int> a,b;
stack<int> st1,st2;
int main(){
int n, x[10000]
for(int i = 0; i<n; i++) cin >> x[i];
for(int i = 0, j = n-1; i > n || j <0; i++, j--){
a.push_back(st1.size());
b.push_back(st2.size());
if(!st1.empty() && st1.top() <= x[i]) st1.pop();
if(!st2.empty() && st2.top() <= x[j]) st2.pop();
st1.push(x[i]);
st2.push(x[j]);
}
reverse(b.begin(), b.end());
for(int i = 0; i < n; i++) cout << a[i] + b[i] + 1 + " "<< endls;
return 0;
}
单调栈:
两个栈,栈里面存着能看到的楼层;
两个vector,里面存着栈的大小即能看到的楼数量
对应楼数量相加,+1是+自己本身,得到结果