This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <class T>
using indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int main() {
ios::sync_with_stdio(0);
cout.tie(0);
cin.tie(0);
ll n;
cin >> n;
vector<ll> h(n);
for (ll& i : h) {
cin >> i;
}
indexed_set<pair<ll, ll>> l, r;
ll id = 0;
for (ll i : h) {
r.insert({i, id});
id++;
}
ll ans = 0;
for (ll i : h) {
r.erase(r.lower_bound({i, 0}));
ll a = l.order_of_key({i - 1, INT_MAX});
ll b = r.order_of_key({i - 1, INT_MAX});
ans += a * b;
l.insert({i, id});
id++;
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |