Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define vi vector<int>
- #define vll vector<long long int>
- ll solve(ll n, vll arr)
- {
- ll res = 0;
- ll sub_max;
- for (ll i = 0; i < n - 2; i++)
- {
- sub_max = arr[i + 1];
- if (arr[i] > arr[i + 1])
- {
- for (ll j = i + 2; j < n; j++)
- {
- if (arr[i] > sub_max && arr[j] > sub_max)
- {
- res++;
- }
- sub_max = max(sub_max, arr[j]);
- }
- }
- }
- return res;
- }
- int main()
- {
- #ifndef ONLINE_JUDGE
- freopen("in.txt", "r", stdin);
- freopen("out.txt", "w", stdout);
- #endif
- std::ios::sync_with_stdio(false);
- ll n;
- cin >> n;
- vll arr;
- ll num;
- for (ll i = 0; i < n; i++)
- {
- cin >> num;
- arr.push_back(num);
- }
- ll res = solve(n, arr);
- cout << res + (n - 1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement