| 比赛 |
NOIP2025模拟赛3 |
评测结果 |
AAAAAAAAAA |
| 题目名称 |
Good Triplets |
最终得分 |
100 |
| 用户昵称 |
梦那边的美好ME |
运行时间 |
1.096 s |
| 代码语言 |
C++ |
内存使用 |
12.56 MiB |
| 提交时间 |
2025-11-26 11:11:38 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll n,c;
ll a[1100000];
ll cnt[1100000];
ll sum[1100000];
ll hf,ans,now;
ll C(ll x){
if (x<=1) return 0;
return x*(x-1)/2;
}
int main(){
freopen("Triplets.in","r",stdin);
freopen("Triplets.out","w",stdout);
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin>>n>>c;
for (int i=1;i<=n;i++){
cin>>a[i];
cnt[a[i]]++;
}
hf=c/2;
for (int i=1;i<=hf;i++) now+=cnt[i];
for (int i=0;i<c;i++){
ans+=cnt[i]*C(now);
if (c%2==0) ans+=C(cnt[i])*(now-cnt[(i+hf)%c]);
else ans+=C(cnt[i])*now;
now-=cnt[(i+1)%c];
now+=cnt[(i+hf+1)%c];
if (cnt[i]>=3) ans+=cnt[i]*(cnt[i]-1)*(cnt[i]-2)/6;
}
ll sum=n*(n-1)*(n-2)/6;
cout<<sum-ans<<'\n';
return 0;
}