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>
#include <string>
#define ll long long
#define pb push_back
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
map<ll,ll>m;
ll ans;
const ll maxn=3e5+100;
ll n,a[maxn];
ll tr[maxn],lft[maxn];
ll cnt=1;
ll sum(ll id){
ll ret=0;
for(;id;id-=id&(-id))ret+=tr[id];
return ret;
}
void add(ll id){
for(;id<=cnt;id+=id&(-id))tr[id]++;
}
ll qur(ll l,ll r){
if(r==0)return 0;
return sum(r)-sum(l-1);
}
int main()
{
IOS
cin>>n;
for(ll i=0;i<n;i++){
cin>>a[i];
m[a[i]]=1;
}
for(auto &x:m){
x.second=cnt++;
}
for(ll i=0;i<n;i++){
a[i]=m[a[i]];
//cout<<a[i]<<' ';
}
cnt--;
for(ll i=0;i<n;i++){
lft[i]=qur(1,a[i]-1);
add(a[i]);
//cout<<lft[i]<<' ';
}
for(ll i=0;i<n;i++){
ll righ=qur(1,a[i]-1)-lft[i];
ans+=righ*lft[i];
}
cout<<ans<<endl;
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... |