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;
typedef long long ll;
const int Nmax=300000;
ll n, v[Nmax];
set <ll> s;
map <ll, int> m;
int aib[Nmax+5];
ll sol[Nmax];
void aib_add(int pos){
for (int i=pos; i<=n; i+=i&-i)
aib[i]++;
}
int aib_check(int pos){
int r=0;
for (int i=pos; i>0; i-=i&-i)
r+=aib[i];
return r;
}
int main()
{
cin>>n;
for (int i=0; i<n; i++){
cin>>v[i];
s.insert(v[i]);
}
int ind=1;
for (auto it=s.begin(); it!=s.end(); it++)
m[*it]=ind++;
for (int i=0; i<n; i++){
aib_add(m[v[i]]);
sol[i]=aib_check(m[v[i]]-1);
}
for (int i=0; i<=n; i++)
aib[i]=0;
ll t=0;
for (int i=n-1; i>=0; i--){
aib_add(m[v[i]]);
t+=sol[i]*aib_check(m[v[i]]-1);
}
cout<<t;
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... |