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 MAXN 300001
long long n;
long long h[MAXN];
map<long long,long long> kompresija;
long long fenw[MAXN];
long long sol[MAXN];
void update(long long pos)
{
for (long long i=pos;i<=n;i+=(i&(-i))) fenw[i]++;
}
long long query(long long pos)
{
long long sum=0;
for (long long i=pos;i>=1;i-=(i&(-i))) sum+=fenw[i];
return sum;
}
int main()
{
cin>>n;
for (long long i=1;i<=n;i++) cin>>h[i];
for (long long i=1;i<=n;i++) kompresija[h[i]]=1;
long long idx=0;
for (auto&p:kompresija) {idx++;p.second=idx;}
for (long long i=1;i<=n;i++) h[i]=kompresija[h[i]];
for (long long i=1;i<=n;i++) {sol[i]=query(h[i]-1);update(h[i]);}
for (long long i=0;i<MAXN;i++) fenw[i]=0;
for (long long i=n;i>=1;i--) {sol[i]*=query(h[i]-1);update(h[i]);}
long long ans=0;
for (long long i=1;i<=n;i++) ans+=sol[i];
cout<<ans<<endl;
}
# | 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... |