https://codeforces.com/problemset/problem/2128/D
题意: 给定长度为n的一个排列,对于1 <= i <= n - 2满足max(a[i], a[i + 1]) > a[i + 2]。求其所有子数组中的最长递减序列长度之和。
先算出所有长度之和,再减去会少的部分。
点击查看代码
```cpp
void solve()
{int n; cin >> n;vector<int> a(n + 1);for(int i = 1; i <= n; i++){cin >> a[i];}int ans = n * (n + 1) * (n + 2) / 6;for(int i = 1; i + 1 <= n; i++){if(a[i] < a[i + 1]) {ans -= i * (n - i);}}cout << ans << "\n";return ;
}
</details>
