其他分享
首页 > 其他分享> > AtCoder Beginner Contest 252 D - Distinct Trio

AtCoder Beginner Contest 252 D - Distinct Trio

作者:互联网

找出三元组i,j,k(i<j<k,ai,aj,ak互不相等) 
等价于找出ai,aj,ak(ai<aj<ak,i,j,k互不相等)
#include<bits/stdc++.h>
using namespace std;

typedef long long LL;

const int N = 2e5+10;

int sum[N];

unordered_map<int,int> cnt;
vector<int> v;

int main(){
	int n,a;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a;
		if(cnt[a]==0) v.push_back(a);
		cnt[a]++;
	}
	sort(v.begin(),v.end());
	LL ans=0;
	int len=v.size();
	for(int i=0;i<len;i++) sum[i+1]=sum[i]+cnt[v[i]];
	for(int i=2;i<=len-1;i++) ans+=(LL)(sum[i]-sum[i-1])*sum[i-1]*(sum[len]-sum[i]);
	cout<<ans;
	return 0;
}

标签:AtCoder,Trio,Beginner,Contest,int,LL,cnt,long,三元组
来源: https://www.cnblogs.com/xhy666/p/16306723.html