这不是sb题么我还想了这么久。。。TAT
先把长度都排个序
然后考虑插入第i个
显然前面i个都可以插在它上面
然后就是要考虑前面有哪些可以放在它下面,也就是
Aj+D>=Ai
的j。随便就好了,然后答案乘上
i−j+1
。
claris怎么做到的又快又短QAQ
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define maxn 700007
inline int rd() {
char c = getchar();
while (!isdigit(c) && c != '-') c = getchar() ; int x = 0 , f = 1;
if (c == '-') f = -1 ; else x = c - '0';
while (isdigit(c = getchar())) x = x * 10 + c - '0';
return x * f;
}
typedef long long ll;
const int mod = 998244353;
int n , d , a[maxn];
void input() {
n = rd() , d = rd();
rep (i , 1 , n) a[i] = rd();
std::sort(a + 1 , a + n + 1);
}
void solve() {
int ans = 1;
for (int i = 2 , j = 1 , *t = a + 2 ; i <= n ; i ++ , t ++) {
for (; a[j] + d < *t ; j ++) ;
ans = (ll) ans * (i - j + 1) % mod;
}
printf("%d\n" , ans);
}
int main() {
input();
solve();
return 0;
}