Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
142713 | 谢思涵 | 音乐会 | C++ | 运行超时 | 90 | 1973 MS | 4248 KB | 546 | 2024-04-08 21:35:47 |
#include <cstdio> #include <stack> #define ll long long using namespace std; stack <ll> s; ll a[500100]; int main() { ll n, ans = 0; scanf("%lld", &n); for(ll i = 1; i <= n; i++) scanf("%lld", &a[i]); for(ll i = 1; i <= n; i++) { ll t = 1, x = a[i]; while(s.size() && x >= s.top()) { if (s.top() == x) t++; ans++; s.pop(); } if(s.size()) ans++; for(ll j = 1; j <= t; j++) s.push(x); } printf("%lld\n", ans); return 0; }