// start fold
#include <bits/stdc++.h>
#ifdef LOCAL
#include <sys/resource.h>
#include <sys/time.h>
#define MAX_FILE_SIZE 536870912
#define CPU_TIME 2
#endif
#define endl '\n'
using namespace std;
using ull = unsigned long long;
using ll = long long;
using ld = long double;
typedef int integer;
/* #define int long long */
#define p(x) cout<<(x)<<endl
#define p2(x,y) cout<<(x)<<' '<<(y)<<endl
#define p3(x,y,z) cout<<(x)<<' '<<(y)<<' '<<(z)<<endl
#define p4(x,y,z,w) cout<<(x)<<' '<<(y)<<' '<<(z)<<' '<<(w)<<endl
#define p1d(a,n) for(int ix=0;ix<n-1;ix++) cout<<a[ix]<<' '; cout<<a[n-1]<<'\n';
#define p2d(a,n,m) for(int ix=0;ix<n;ix++){ for(int jx=0;jx<m;jx++) cout<<a[ix][jx]<<" "; cout<<endl;}
#define range(v) v.begin(),v.end()
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define rst(x) memset(x, -1, sizeof(x))
#define EACH(x, a) for (auto& x: a)
template<class T> void read_v(T& x, std::istream& in) {
in >> (x);
}
template<class A> void read_vec(vector<A>& x, std::istream& in) {
EACH(a, x)
read_v(a, in);
}
void __print(integer x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (const auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ["; _print(__VA_ARGS__)
#else
#define debug(...) 42
#endif
int iceildiv(const int a, const int b){ if(a==0){return 0;} return (1 + ((a - 1)/b));}
bool sortpairbysec(const pair<int,int> &a,const pair<int,int> &b){return (a.second < b.second);}
template <typename T> int power(T a, T b){ int ans=1; while(b>0){if(b&1){ans*=a;}a*=a;b>>=1;}return ans;}
template <typename T> void setmin(T& a, T b) { if (b < a) a = b; }
template <typename T> void setmax(T& a, T b) { if (b > a) a = b; }
// end fold
template <unsigned int MOD>
struct ModInt {
using uint = unsigned int;
using ull = unsigned long long;
using M = ModInt;
uint v;
ModInt(ll _v = 0) { set_norm(_v % MOD + MOD); }
M& set_norm(uint _v) { //[0, MOD * 2)->[0, MOD)
v = (_v < MOD) ? _v : _v - MOD;
return *this;
}
explicit operator bool() const { return v != 0; }
M operator+(const M& a) const { return M().set_norm(v + a.v); }
M operator-(const M& a) const { return M().set_norm(v + MOD - a.v); }
M operator*(const M& a) const { return M().set_norm(ull(v) * a.v % MOD); }
M operator/(const M& a) const { return *this * a.inv(); }
M& operator+=(const M& a) { return *this = *this + a; }
M& operator-=(const M& a) { return *this = *this - a; }
M& operator*=(const M& a) { return *this = *this * a; }
M& operator/=(const M& a) { return *this = *this / a; }
M operator-() const { return M() - *this; }
M& operator++(int) { return *this = *this + 1; }
M& operator--(int) { return *this = *this - 1; }
M pow(ll n) const {
if (n < 0) return inv().pow(-n);
M x = *this, res = 1;
while (n) {
if (n & 1) res *= x;
x *= x;
n >>= 1;
}
return res;
}
M inv() const {
ll a = v, b = MOD, p = 1, q = 0, t;
while (b != 0) {
t = a / b;
swap(a -= t * b, b);
swap(p -= t * q, q);
}
return M(p);
}
bool operator==(const M& a) const { return v == a.v; }
bool operator!=(const M& a) const { return v != a.v; }
friend ostream& operator<<(ostream& os, const M& a) { return os << a.v; }
static uint get_mod() { return MOD; }
};
//using Mint = ModInt<998244353>;
using Mint = ModInt<1000000009>;
void __print(Mint x) {cerr << x.v;}
void solve(){
int n, m; cin >> n >> m;
vector<int> a(n); read_vec(a, cin); sort(all(a));
Mint ans = 1;
int r = 0;
for(int i = 0; i < n; i++){
while(r + 1 < n && a[r + 1] - a[i] <= m){
r++;
}
ans *= (int64_t)(r - i + 1);
}
p(ans);
return;
}
// start fold
integer main() {
#ifdef LOCAL
rlimit rlim, rlim_time;
if(getrlimit(RLIMIT_FSIZE, &rlim) || getrlimit(RLIMIT_CPU , &rlim_time))
return 1 ;
rlim.rlim_cur = MAX_FILE_SIZE; // maximum file size (in bytes) that your program will be able to create
rlim_time.rlim_cur = CPU_TIME; // maximum allowed runtime for your program
if(setrlimit(RLIMIT_FSIZE, &rlim) || setrlimit(RLIMIT_CPU , &rlim_time))
return 2;
#endif
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int test_cases = 1;
while(test_cases--){
solve();
}
return 0;
}
// end fold
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
492 KB |
Output is correct |
2 |
Correct |
11 ms |
1004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
1260 KB |
Output is correct |
2 |
Correct |
50 ms |
3564 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
107 ms |
2796 KB |
Output is correct |
2 |
Correct |
135 ms |
5112 KB |
Output is correct |