| 比赛 |
NOIP2025模拟赛3 |
评测结果 |
AAAAAAAAAA |
| 题目名称 |
Good Triplets |
最终得分 |
100 |
| 用户昵称 |
梦那边的没好TM |
运行时间 |
1.163 s |
| 代码语言 |
C++ |
内存使用 |
22.61 MiB |
| 提交时间 |
2025-11-26 11:53:29 |
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define cpy(a,b) copy(begin(a),end(a),begin(b))
#define ld long double
#define dot(x) fixed<<setprecision(x)
#define foru(a,b,c) for(ll a=b;a<=c;a++)
ll n,c,p[1000005],cnt[1000005],b[2000005];
int main(){
freopen("Triplets.in" ,"r",stdin );
freopen("Triplets.out","w",stdout);
ios::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);
cin>>n>>c;
foru(i,1,n){
cin>>p[i];
cnt[p[i]]++;
}
sort(p+1,p+n+1);
ll ans=n*(n-1)*(n-2)/6,b1=0,b2=0;
foru(i,1,n){
b[i]=p[i];
}
foru(i,1,n){
b[i+n]=p[i]+c;
}
ll r=0;
foru(i,1,n){
if(r<i)r=i;
while(r<2*n){
ll tmp=b[r]-b[i];
if(tmp*2<c){
r++;
}else{
break;
}
}
ll k=r-i-1;
if(k>=2){
b1+=k*(k-1)/2;
}
}
if(c%2==0){
ll c2=c/2,tmp;
foru(i,0,c2-1){
ll u=cnt[i],v=cnt[i+c2];
if(u>0&&v>0){
tmp=n-u-v;
b2+=u*v*tmp+(u*(u-1)/2)*v+u*(v*(v-1)/2);
}
}
}
cout<<ans-b1-b2;
return 0;
}