| 比赛 |
2026.1.3 |
评测结果 |
ATAATATAAA |
| 题目名称 |
极差序列 |
最终得分 |
70 |
| 用户昵称 |
梦那边的美好ME |
运行时间 |
3.498 s |
| 代码语言 |
C++ |
内存使用 |
4.34 MiB |
| 提交时间 |
2026-01-03 09:13:30 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod=998245353;
ll n,k;
ll a[210000];
ll ans;
ll mpow(ll a,ll b){
ll res=1;
while (b){
if (b&1) res=res*a%mod;
a=a*a%mod;
b>>=1;
}
return res%mod;
}
int main(){
freopen("maxmin.in","r",stdin);
freopen("maxmin.out","w",stdout);
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin>>n>>k;
for (int i=1;i<=n;i++){
cin>>a[i];
}
sort(a+1,a+n+1);
for (ll i=1,j=1;i<=n&&j<=n;){
if (a[i]-a[j]==k){
ans=(ans+mpow(2,i-j-1))%mod;
if (a[i]==a[i+1]) i++;
else if (a[j]==a[j+1]) j++;
else j++;
}else{
while (a[i]-a[j]!=k&&i<=n&&j<=n){
if (a[i]-a[j]>k) j++;
if (a[i]-a[j]<k) i++;
}
}
}
cout<<ans;
return 0;
}