Submission #1090012

# Submission time Handle Problem Language Result Execution time Memory
1090012 2024-09-17T14:16:57 Z akamizane A Huge Tower (CEOI10_tower) C++14
100 / 100
87 ms 11192 KB
#include<bits/stdc++.h>
 
using namespace std;


using ll = long long;
using pii = pair<int,int>;
using db = double;

#define el cout << '\n'
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FOD(i, a, b) for (int i = (a); i >= (b); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
template <class T1, class T2>void chmax(T1 &a, T2 b){a = max(a, b);}
template <class T1, class T2>void chmin(T1 &a, T2 b){a = min(a, b);}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll mod = 1e9 + 9;;

template<typename T> T inv(T a, T m){ T u = 0, v = 1; while (a != 0) { T t = m / a; m -= t * a; swap(a, m); u -= t * v; swap(u, v); } assert(m == 1); return u; }
 
template<typename T>
class Modular{
public:
  long long x;
  constexpr Modular() {}
  template<typename U> Modular(U x){if(x < 0) x += mod(); this->x = x; }
 
  constexpr long long& operator()(){return x;}
  template<typename U> explicit operator U() const {return static_cast<U>(x);}
  constexpr static long long mod(){return T::value;}
 
  Modular& operator+= (const Modular &a){ x += a.x; if(x >= mod()) x -= mod(); return *this; }
  template<typename U> Modular& operator+=(const U& a){ return *this += Modular(a); }
  Modular& operator-= (const Modular &a){ x -= a.x; if(x < 0) x += mod(); return *this; }
  template<typename U> Modular& operator-=(const U& a){ return *this -= Modular(a); }
  Modular& operator*= (const Modular &a){ x = (x % mod()) * (a.x % mod()); x %= mod(); return *this; }
  Modular& operator/= (const Modular &a){ return *this *= Modular(inv(a.x, mod())); } 
 
  Modular& operator++(){ return *this += 1; }
  Modular operator++(int) { Modular res(*this); *this += 1; return res; }
  Modular& operator--(){ return *this -= 1; }
  Modular operator--(int){ Modular res(*this); *this -= 1; return res;}
 
  Modular operator-() const {return Modular(-x);} 
 
  template<typename U> friend std::ostream& operator<<(std::ostream& out, const Modular<U> &b);
  template<typename U> friend std::istream& operator>>(std::istream& in, Modular<U>& b);
};
 
template<typename T> Modular<T> operator+(const Modular<T>& a, const Modular<T>& b){ return Modular<T>(a) += b; }
template<typename T, typename U> Modular<T> operator+(const Modular<T>& a, U b){ return Modular<T>(a) += b; }
template<typename T, typename U> Modular<U> operator+(T a, const Modular<U>& b){ return Modular<U>(a) += b; }
 
template<typename T> Modular<T> operator-(const Modular<T>& a, const Modular<T>& b){ return Modular<T>(a) -= b; }
template<typename T, typename U> Modular<T> operator-(const Modular<T>& a, U b){ return Modular<T>(a) -= b; }
template<typename T, typename U> Modular<U> operator-(T a, const Modular<U>& b){ return Modular<U>(a) -= b; }
 
template<typename T> Modular<T> operator*(const Modular<T>& a, const Modular<T>& b){ return Modular<T>(a) *= b; }
template<typename T, typename U> Modular<T> operator*(const Modular<T>& a, U b){ return Modular<T>(a) *= b; }
template<typename T, typename U> Modular<U> operator*(T a, const Modular<U>& b){ return Modular<U>(a) *= b; }
 
template<typename T> Modular<T> operator/(const Modular<T>& a, const Modular<T>& b){ return Modular<T>(a) /= b; }
template<typename T, typename U> Modular<T> operator/(const Modular<T>& a, U b){ return Modular<T>(a) /= b; }
template<typename T, typename U> Modular<U> operator/(T a, const Modular<U>& b){ return Modular<U>(a) /= b; }
 
template<typename T, typename U> 
Modular<T> Pow(const Modular<T>& a, const U& b){ assert(b >= 0); Modular<T> x = a,res = 1; U p = b; while(p){ if(p & 1) res *= x; x *= x; p >>= 1; } return res; }
 
template<typename T> std::ostream& operator<<(std::ostream& out, const Modular<T> &a){ out << a.x; return out; }
template<typename T> std::istream& operator>>(std::istream& in, Modular<T> &a){ in >> a.x; a.x %= Modular<T>::mod(); return in; }
 
template<typename T> string to_string(const Modular<T> &a){ return to_string((int) a); }
 
using Mint = Modular<std::integral_constant<decay<decltype(mod)>::type, mod>>;

const int maxn = 3e5 + 5;

void solve(){
  ll n, k;
  cin >> n >> k;
  vector<ll> x(n);
  for (auto& a : x) cin >> a;
  sort(x.begin(), x.end());
  Mint ans = 1;
  for (int l = 0, r = 0; l < n; l++){
    while(r < n && x[r] - x[l] <= k) r++;
    ans *= (r - l);
  }
  cout << ans;
}


int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int tests = 1;
  //cin >> tests;
  for (int itest = 1; itest <= tests; itest++){
    cerr << "- TEST " << itest << ": \n";
    solve();
    el;
  }
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 1116 KB Output is correct
2 Correct 7 ms 1236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 4724 KB Output is correct
2 Correct 35 ms 4696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 83 ms 11192 KB Output is correct
2 Correct 87 ms 10564 KB Output is correct