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;
long long n,a[300005],b[300005],tree_bef[600005],tree_aft[600005],i,k,ans;
map<long long,int>ind;
void update(int idx,int val,int w){
for(int x=idx;x<=n;x+=x&(-x)){
if(w==1){
tree_aft[x]+=val; }
else tree_bef[x]+=val;
}
}
long long getans(int idx,int w){
long long pas=0;
for(int x=idx;x>=1;x-=x&(-x)){
if(w==1) pas+=tree_aft[x];
else pas+=tree_bef[x];
}
return pas;
}
int main(){
cin>>n;
for(k=1;k<=n;k++){
cin>>a[k];
b[k]=a[k];
}
sort(b+1,b+n+1);
for(k=1;k<=n;k++){
if(!ind[b[k]]){
i++;
ind[b[k]]=i;
}
update(ind[b[k]],1,1);
}
for(k=1;k<=n;k++){
update(ind[a[k]],-1,1);
update(ind[a[k]],1,2);
ans+=getans(ind[a[k]]-1,1)*getans(ind[a[k]]-1,2);
//cout<<ans<<endl;
}
cout<<ans;
}
# | 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... |