比赛 NOIP2025模拟赛3 评测结果 AAAAAAAAAA
题目名称 Good Triplets 最终得分 100
用户昵称 郑霁桓 运行时间 1.104 s
代码语言 C++ 内存使用 40.81 MiB
提交时间 2025-11-26 09:56:06
显示代码纯文本
#include<bits/stdc++.h>
using namespace std; 
long long n,m,a[1000005],t[2000005],b[2000005],c[2000005],p,ps,s1,s2,as;
int main(){
	freopen("Triplets.in","r",stdin);
	freopen("Triplets.out","w",stdout);
	ios::sync_with_stdio(false);
	cin>>m>>n;
	for(int i=1;i<=m;i++){
		cin>>a[i];
		t[a[i]]++;
		t[a[i]+n]++;
	} 
	if(n%2==0){
		for(int i=0;i<n+n;i++) b[i]=b[i-1]+t[i];
		for(int i=0;i<n+n;i++) c[i]=c[i-1]+t[i]*b[i+n/2-1];
		for(int i=1;i<=n;i++){
			as+=t[i]*(c[i+n/2-1]-c[i]);
			as-=t[i]*b[i+n/2]*(b[i+n/2-1]-b[i]);
		}
		cout<<as/3;
	}else{
		for(int i=0;i<n+n;i++) b[i]=b[i-1]+t[i];
		for(int i=0;i<n+n;i++) c[i]=c[i-1]+t[i]*b[i+n/2];
		for(int i=1;i<=n;i++){
			as+=t[i]*(c[i+n/2]-c[i-1]);
			as-=t[i]*b[i+n/2]*(b[i+n/2]-b[i-1]);
		}
		cout<<as/3;
	}
    return 0;
}