提交时间:2023-12-30 22:02:17
运行 ID: 118570
#include<bits/stdc++.h> #define int long long using namespace std; namespace Fast{ inline int fr(){ register int x = 0,f = 1; static char c = getchar(); while (c < '0' || c > '9'){ if (c == '-'){ f = -1; } c = getchar(); } while (c >= '0' && c <= '9'){ x = (x << 1) + (x << 3) + (c ^ 48); c = getchar(); } return x * f; } inline void fw(int x){ if (x == 0){ putchar('0'); return ; } if (x < 0){ putchar('-'); x = -x; } stack <char> s; while (x){ s.push(x % 10 + 48); x /= 10; } while (!s.empty()){ putchar(s.top()); s.pop(); } } inline void DEBUG(){ puts("awa"); } inline void CCF(){ ios::sync_with_stdio(false); cin.tie(0),cout.tie(0); } } using namespace Fast; int a[10005],cnt,maxn; stack <int> stk; signed main(){ int n = fr(); for (int i = 1;i <= n;i++){ a[i] = fr(); maxn = max(maxn,a[i]); } for (int i = 1;i <= maxn;i++){ int lft = 0; bool flag = false; for (int j = 2;j <= n;j++){ if (a[j] >= i){ flag = true; } if (flag){ if (a[j - 1] > a[j] && a[j] < i){ lft = j; } if (a[j - 1] < a[j] && a[j - 1] < i && lft != 0){ cnt += j - lft; lft = j; } } } //cout<<cnt<<'\n'; } fw(cnt); return 0; }