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;
#define int long long
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
const int N = 3e5 + 5;
int n,a[N],bit[N],f[N];
void compress() {
vector<pii>vec;
for (int i = 1; i <= n; i++) vec.push_back(mp(a[i],i));
sort(vec.begin(),vec.end());
a[vec[0].se] = 1;
for (int i = 1; i < n; i++)
if (vec[i].fi == vec[i - 1].fi) a[vec[i].se] = a[vec[i - 1].se];
else a[vec[i].se] = i + 1;
}
void update(int i,int x) {
for (; i < N; i += i & (-i)) bit[i] += x;
}
int get(int i) {
int ans = 0;
for (; i > 0; i -= i & (-i)) ans += bit[i];
return ans;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
compress();
for (int i = 1; i <= n; i++) {
f[i] = get(a[i] - 1);
update(a[i],1);
}
memset(bit,0,sizeof(bit));
int ans = 0;
for (int i = n; i > 0; i--) {
ans += get(a[i] - 1) * f[i];
update(a[i],1);
}
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... |