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;
const int N = 3e5 + 1;
struct FenwickTree{
int d[N];
void update(int x){
for(; x < N; x += x & -x)
d[x]++;
}
int get(int x){
int res = 0;
for(; x > 0; x -= x & -x)
res += d[x];
return res;
}
int getRange(int l, int r){
assert(l <= r);
return get(r) - get(l - 1);
}
} bit;
int n, ind[N];
ll a[N];
void ReadInput(){
cin >> n;
for(int i = 1; i <= n; i++)
cin >> a[i];
}
void Solve(){
for(int i = 1; i <= n; i++)
ind[i] = i;
sort(ind + 1, ind + 1 + n, [&](const int &x, const int &y){
return a[x] < a[y];
});
ll res = 0;
for(int i = 1; i <= n; i++){
int j = i;
while (j < n && a[ind[i]] == a[ind[j + 1]])
j++;
for(int k = i; k <= j; k++)
res += (ll) bit.getRange(1, ind[k]) * bit.getRange(ind[k], n);
for(int k = i; k <= j; k++)
bit.update(ind[k]);
i = j;
}
cout << res;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
ReadInput();
Solve();
return 0;
}
# | 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... |