比赛 |
20200622 |
评测结果 |
AAAAAAAAAA |
题目名称 |
三元数对 |
最终得分 |
100 |
用户昵称 |
ShallowDream雨梨 |
运行时间 |
0.090 s |
代码语言 |
C++ |
内存使用 |
5.45 MiB |
提交时间 |
2020-06-22 19:54:33 |
显示代码纯文本
#include<bits/stdc++.h>
#define int long long
#define re register
#define il inline
#define inf 1e18
#define eps 1e-15
#define ll long long
#define mod 998244353
#define bianli for(int i=head[x];i;i=a[i].next)
#define QWQ cout<<"qwq";
#define me(qw) memset(qw,0,sizeof(qw));
#define meinf(qw) memset(qw,0x3f,sizeof(qw));
#define lowbit(x) x&(-x)
using namespace std;
const int maxn=5e4+5;
int n;
int a[maxn],b[maxn],tree[maxn],l[maxn],r[maxn],tp[maxn];
void add1(int x){
while(x<=n){
tree[x]++;
x+=lowbit(x);}}
int ask1(int x){
int ans=0;
while(x){
ans+=tree[x];
x-=lowbit(x);}
return ans;}
void add2(int x){
while(x<=n){
tp[x]++;
x+=lowbit(x);}}
int ask2(int x){
int ans=0;
while(x){
ans+=tp[x];
x-=lowbit(x);}
return ans;}
signed main(){
freopen("three.in", "r", stdin);
freopen("three.out", "w", stdout);
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i],b[i]=a[i];
sort(a+1,a+1+n);
int len=unique(a+1,a+1+n)-a-1;
for(int i=1;i<=n;i++)
b[i]=lower_bound(a+1,a+1+len,b[i])-a;
for(int i=1;i<=n;i++)
add1(b[i]),l[i]=ask1(b[i]-1);
for(int i=n;i>=1;i--)
add2(b[i]),r[i]=n-i-ask2(b[i])+1;
int ans=0;
for(int i=1;i<=n;i++)
ans+=l[i]*r[i];//cout<<l[i]<<r[i]<<endl;
cout<<ans;
return 0;
}