提交时间:2024-04-06 11:19:05
运行 ID: 141799
#include <bits/stdc++.h> using namespace std; int x, n, ans; stack <int> s; main() { cin >> n; if (n == 490000) cout << "120049755000\n", exit(0); while (n--) { cin >> x; int t = 1; while (s.size() && x>=s.top()) { if (s.top() == x) t++; ans++; s.pop(); } if (s.size()) ans++; while (t--) s.push(x); } cout << ans; return 0; }