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>
#define int long long
using namespace std;
int ar[300005];
int id[300005];
int l[300005];
int r[300005];
vector<int>v;
struct fenwick{
int info[300005];
void upd(int x,int val){
for(int i=x;i<=300000;i+=i&-i){
info[i]+=val;
}
}
int fsum(int x){
int sum=0;
for(int i=x;i>0;i-=i&-i){
sum+=info[i];
}
return sum;
}
}fwl,fwr;
int32_t main(){
int n;cin>>n;
for(int i=0;i<n;i++){
cin>>ar[i];
v.push_back(ar[i]);
}
sort(v.begin(),v.end());
for(int i=0;i<n;i++){
id[i]=lower_bound(v.begin(),v.end(),ar[i])-v.begin()+1;
}
for(int i=0;i<n;i++){
l[i]=fwl.fsum(id[i]-1);
fwl.upd(id[i],1);
}
for(int i=n-1;i>0;i--){
r[i]=fwr.fsum(id[i]-1);
fwr.upd(id[i],1);
}
int ans=0;
for(int i=0;i<n;i++){
ans+=l[i]*r[i];
}
cout<<ans<<"\n";
}
# | 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... |