이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |