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;
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
#define int long long
typedef tree<pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> ost;
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
int a[n+1];
for(int i=1; i<=n; i++) cin >> a[i];
ost left, right;
for(int i=3; i<=n; i++) right.insert({a[i],i});
left.insert({a[1],1});
int ans = left.order_of_key({a[2],0}) * right.order_of_key({a[2],0});
for(int i=3; i<n; i++) {
left.insert({a[i-1],i-1});
right.erase({a[i],i});
ans += left.order_of_key({a[i],0}) * right.order_of_key({a[i],0});
}
cout << ans << "\n";
}
# | 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... |