#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN = 3e5 + 5;
vector<int> peal;
int n;
int a[MAXN];
int bit[MAXN];
int l[MAXN];
int r[MAXN];
int findd(int x)
{
return lower_bound(peal.begin(), peal.end(), x) - peal.begin() + 1;
}
void add(int pos, int val)
{
for (; pos <= n; pos += pos & -pos)
{
bit[pos] += val;
}
}
int get(int pos)
{
int res = 0;
for (; pos > 0; pos -= pos & -pos)
{
res += bit[pos];
}
return res;
}
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];
peal.push_back(a[i]);
}
sort(peal.begin(), peal.end());
peal.erase(unique(peal.begin(), peal.end()), peal.end());
for (int i = 1; i <= n; i++)
{
a[i] = findd(a[i]);
}
for (int i = 1; i <= n; i++)
{
l[i] = get(a[i] - 1);
add(a[i], 1);
}
memset(bit, 0, sizeof bit);
for (int i = n; i >= 1; i--)
{
r[i] = get(a[i] - 1);
add(a[i], 1);
}
int ans = 0;
for (int i = 1; i <= n; i++)
{
ans += l[i] * r[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... |