洛谷 P1886. 发射站
题目描述
分析
略
代码实现
cpp
#include <bits/stdc++.h>
using namespace std;
int n;
stack<int> st;
int main() {
cin >> n;
long long res = 0;
for (int i = 1; i <= n; i++) {
int h; cin >> h;
while (!st.empty() && st.top() <= h) {
st.pop();
}
res += st.size();
st.push(h);
}
cout << res << endl;
return 0;
}