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;
const int N= 3e5 + 2;
int n, aib[N], st[N], dr[N];
long long a[N], b[N];
void norm () {
for (int i = 1; i <= n; i++)
b[i] = a[i];
sort(b + 1, b + n + 1);
for (int i = 1; i <= n; i++)
a[i] = lower_bound(b + 1, b + n + 1, a[i]) - b;
}
int query (int x) {
int s = 0;
for (int i = x; i; i -= (i & -i))
s += aib[i];
return s;
}
void update (int x) {
for (int i = x; i <= n; i += (i & -i))
aib[i] += 1;
}
int main ()
{
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
norm();
for (int i = 1; i <= n; i++) {
st[i] = query(a[i] - 1);
update(a[i]);
}
long long ans = 0;
memset(aib, 0, sizeof(aib));
for (int i = n; i >= 1; i--) {
dr[i] = query(a[i] -1);
update(a[i]);
ans += 1ll * st[i] * dr[i];
}
cout << ans;
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... |