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 <iostream>
#include <set>
#include <map>
using namespace std;
const int NMAX = 3e5;
int N;
long long v[NMAX + 5];
set <long long> xs;
int k;
map <long long, int> norm;
int st[NMAX + 5], dr[NMAX + 5];
struct AIB
{
int n, v[NMAX + 5];
void Reset(int _n)
{
n = _n;
for(int i = 0; i <= n; i++)
v[i] = 0;
}
int Lsb(int x)
{
return x & (-x);
}
void Update(int pos, int val)
{
for(int i = pos; i <= n; i += Lsb(i))
v[i] += val;
}
int Query(int pos)
{
int ans = 0;
for(int i = pos; i > 0; i -= Lsb(i))
ans += v[i];
return ans;
}
};
AIB aib;
int main()
{
cin >> N;
for(int i = 1; i <= N; i++)
{
cin >> v[i];
xs.insert(v[i]);
}
while(!xs.empty())
{
int val = *xs.begin();
xs.erase(xs.begin());
norm[val] = ++k;
}
aib.Reset(N);
for(int i = 1; i <= N; i++)
{
st[i] = aib.Query(norm[v[i]] - 1);
aib.Update(norm[v[i]], 1);
}
aib.Reset(N);
for(int i = N; i >= 1; i--)
{
dr[i] = aib.Query(norm[v[i]] - 1);
aib.Update(norm[v[i]], 1);
}
long long sol = 0LL;
for(int i = 1; i <= N; i++)
sol += 1LL * st[i] * dr[i];
cout << sol << '\n';
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... |