提交时间:2024-04-07 21:41:12
运行 ID: 142410
#include<iostream> #include<stack> using namespace std; stack <int> s; int main() { int x, n, ans = 0; cin >> n; for(int i = 1; i <= n; i++) { cin >> x; int t = 1; while(s.size() && x >= s.top()) { if (s.top() == x) t++; ans++; s.pop(); } if(s.size()) ans++; for(int j = 1; j <= t; j++) s.push(x); } cout << ans << endl; return 0; }