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>
#include <bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
#define int long long
template <typename T>
using pbds_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
pbds_set<int> s;
pbds_set<int> t;
int n;
cin >> n;
int arr[n];
cin >> arr[0];
s.insert(arr[0]);
int demon[n];
demon[0] = 0;
int ans = 0;
for (int i = 1; i < n; i++) {
cin >> arr[i];
demon[i] = s.order_of_key(arr[i]);
s.insert(arr[i]);
}
t.insert(arr[n - 1]);
for (int i = n - 2; i >= 0; i--) {
int a = t.order_of_key(arr[i]);
ans += demon[i] * a;
t.insert(arr[i]);
}
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... |