This commit is contained in:
HuangHai
2025-08-30 18:35:01 +08:00
commit 1f397eca87
6258 changed files with 1487241 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=80010;
int a[N];
int res[N];
stack<int> stk;
int n;
LL ans;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
while (!stk.empty() && a[stk.top()] <= a[i]) {
res[stk.top()] = i;
stk.pop();
}
stk.push(i);
}
for (int i = 1; i <= n; i++) {
if (res[i] == 0) ans += n - i;
else ans += res[i] - i - 1;
}
cout << ans;
}