結果
問題 | No.916 Encounter On A Tree |
ユーザー | Pachicobue |
提出日時 | 2019-10-25 22:52:20 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 10 ms / 2,000 ms |
コード長 | 11,274 bytes |
コンパイル時間 | 2,321 ms |
コンパイル使用メモリ | 209,368 KB |
実行使用メモリ | 9,036 KB |
最終ジャッジ日時 | 2024-09-13 06:31:55 |
合計ジャッジ時間 | 4,413 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,944 KB |
testcase_02 | AC | 10 ms
8,528 KB |
testcase_03 | AC | 10 ms
8,016 KB |
testcase_04 | AC | 10 ms
8,524 KB |
testcase_05 | AC | 9 ms
7,632 KB |
testcase_06 | AC | 10 ms
7,888 KB |
testcase_07 | AC | 9 ms
7,632 KB |
testcase_08 | AC | 3 ms
6,940 KB |
testcase_09 | AC | 4 ms
6,940 KB |
testcase_10 | AC | 2 ms
6,944 KB |
testcase_11 | AC | 2 ms
6,940 KB |
testcase_12 | AC | 8 ms
6,944 KB |
testcase_13 | AC | 9 ms
6,944 KB |
testcase_14 | AC | 9 ms
7,628 KB |
testcase_15 | AC | 10 ms
8,276 KB |
testcase_16 | AC | 4 ms
6,940 KB |
testcase_17 | AC | 9 ms
7,764 KB |
testcase_18 | AC | 2 ms
6,940 KB |
testcase_19 | AC | 9 ms
6,944 KB |
testcase_20 | AC | 10 ms
8,268 KB |
testcase_21 | AC | 9 ms
6,940 KB |
testcase_22 | AC | 8 ms
6,940 KB |
testcase_23 | AC | 8 ms
6,944 KB |
testcase_24 | AC | 8 ms
6,944 KB |
testcase_25 | AC | 8 ms
6,940 KB |
testcase_26 | AC | 5 ms
6,940 KB |
testcase_27 | AC | 5 ms
6,940 KB |
testcase_28 | AC | 3 ms
6,940 KB |
testcase_29 | AC | 10 ms
8,656 KB |
testcase_30 | AC | 9 ms
6,944 KB |
testcase_31 | AC | 10 ms
8,528 KB |
testcase_32 | AC | 10 ms
8,908 KB |
testcase_33 | AC | 5 ms
6,940 KB |
testcase_34 | AC | 5 ms
6,940 KB |
testcase_35 | AC | 3 ms
6,940 KB |
testcase_36 | AC | 10 ms
8,272 KB |
testcase_37 | AC | 10 ms
8,016 KB |
testcase_38 | AC | 4 ms
6,944 KB |
testcase_39 | AC | 10 ms
9,036 KB |
testcase_40 | AC | 8 ms
6,944 KB |
testcase_41 | AC | 2 ms
6,944 KB |
testcase_42 | AC | 2 ms
6,940 KB |
testcase_43 | AC | 2 ms
6,940 KB |
testcase_44 | AC | 2 ms
6,940 KB |
testcase_45 | AC | 3 ms
6,940 KB |
testcase_46 | AC | 2 ms
6,940 KB |
testcase_47 | AC | 2 ms
6,940 KB |
testcase_48 | AC | 2 ms
6,940 KB |
testcase_49 | AC | 2 ms
6,944 KB |
testcase_50 | AC | 2 ms
6,940 KB |
testcase_51 | AC | 2 ms
6,944 KB |
testcase_52 | AC | 2 ms
6,944 KB |
testcase_53 | AC | 2 ms
6,940 KB |
testcase_54 | AC | 2 ms
6,940 KB |
testcase_55 | AC | 2 ms
6,944 KB |
testcase_56 | AC | 2 ms
6,940 KB |
testcase_57 | AC | 2 ms
6,940 KB |
testcase_58 | AC | 2 ms
6,944 KB |
testcase_59 | AC | 2 ms
6,940 KB |
testcase_60 | AC | 2 ms
6,940 KB |
ソースコード
#include <bits/stdc++.h> #pragma GCC diagnostic ignored "-Wsign-compare" #pragma GCC diagnostic ignored "-Wsign-conversion" #define NDEBUG using i32 = int32_t; using i64 = int64_t; using u32 = uint32_t; using u64 = uint64_t; using uint = unsigned int; using usize = std::size_t; using ll = long long; using ull = unsigned long long; using ld = long double; template<typename T> constexpr T popcount(const T u) { return u ? static_cast<T>(__builtin_popcountll(static_cast<u64>(u))) : static_cast<T>(0); } template<typename T> constexpr T log2p1(const T u) { return u ? static_cast<T>(64 - __builtin_clzll(static_cast<u64>(u))) : static_cast<T>(0); } template<typename T> constexpr T msbp1(const T u) { return log2p1(u); } template<typename T> constexpr T lsbp1(const T u) { return __builtin_ffsll(u); } template<typename T> constexpr T clog(const T u) { return u ? log2p1(u - 1) : static_cast<T>(u); } template<typename T> constexpr bool ispow2(const T u) { return u and (static_cast<u64>(u) & static_cast<u64>(u - 1)) == 0; } template<typename T> constexpr T ceil2(const T u) { return static_cast<T>(1) << clog(u); } template<typename T> constexpr T floor2(const T u) { return u == 0 ? static_cast<T>(0) : static_cast<T>(1) << (log2p1(u) - 1); } template<typename T> constexpr bool btest(const T mask, const usize ind) { return ((static_cast<u64>(mask) >> ind) & static_cast<u64>(1)); } template<typename T> constexpr T bcut(const T mask, const usize ind) { return ind == 0 ? static_cast<T>(0) : static_cast<T>((static_cast<u64>(mask) << (64 - ind)) >> (64 - ind)); } template<typename T> bool chmin(T& a, const T& b) { return (a > b ? a = b, true : false); } template<typename T> bool chmax(T& a, const T& b) { return (a < b ? a = b, true : false); } constexpr unsigned int mod = 1000000007; template<typename T> constexpr T inf_v = std::numeric_limits<T>::max() / 4; template<typename Real> constexpr Real pi_v = Real{3.141592653589793238462643383279502884}; template<typename T> T read() { T v; return std::cin >> v, v; } template<typename T> std::vector<T> read_vec(const std::size_t size) { std::vector<T> v(size); for (auto& e : v) { std::cin >> e; } return v; } template<typename... Types> auto read_vals() { return std::tuple<std::decay_t<Types>...>{read<Types>()...}; } #define SHOW(...) static_cast<void>(0) template<typename T> std::vector<T> make_v(const std::size_t size, T v) { return std::vector<T>(size, v); } template<class... Args> auto make_v(const std::size_t size, Args... args) { return std::vector<decltype(make_v(args...))>(size, make_v(args...)); } template<typename T> T gcd(const T& a, const T& b) { return (a > b ? gcd(b, a) : a == 0 ? b : gcd(b % a, a)); } template<typename T> T lcm(const T& a, const T& b) { return a / gcd(a, b) * b; } template<typename T> constexpr std::pair<T, T> extgcd(const T a, const T b) { if (b == 0) { return std::pair<T, T>{1, 0}; } const auto g = gcd(a, b), da = std::abs(b) / g; const auto p = extgcd(b, a % b); const auto x = (da + p.second % da) % da, y = (g - a * x) / b; return {x, y}; } template<typename T> constexpr T inverse(const T a, const T mod) { return extgcd(a, mod).first; } template<uint mod_value, bool dynamic = false> class modint_base { public: template<typename UInt = uint> static std::enable_if_t<dynamic, const UInt> mod() { return mod_ref(); } template<typename UInt = uint> static constexpr std::enable_if_t<not dynamic, const UInt> mod() { return mod_value; } template<typename UInt = uint> static void set_mod(const std::enable_if_t<dynamic, const UInt> mod) { mod_ref() = mod, inv_ref() = {1, 1}; } modint_base() : v{0} {} modint_base(const ll val) : v{norm(static_cast<uint>(val % static_cast<ll>(mod()) + static_cast<ll>(mod())))} {} modint_base(const modint_base& n) : v{n()} {} explicit operator bool() const { return v != 0; } bool operator!() const { return not static_cast<bool>(*this); } modint_base& operator=(const modint_base& m) { return v = m(), (*this); } modint_base& operator=(const ll val) { return v = norm(uint(val % static_cast<ll>(mod()) + static_cast<ll>(mod()))), (*this); } friend modint_base operator+(const modint_base& m) { return m; } friend modint_base operator-(const modint_base& m) { return make(norm(mod() - m.v)); } friend modint_base operator+(const modint_base& m1, const modint_base& m2) { return make(norm(m1.v + m2.v)); } friend modint_base operator-(const modint_base& m1, const modint_base& m2) { return make(norm(m1.v + mod() - m2.v)); } friend modint_base operator*(const modint_base& m1, const modint_base& m2) { return make(static_cast<uint>(static_cast<ll>(m1.v) * static_cast<ll>(m2.v) % static_cast<ll>(mod()))); } friend modint_base operator/(const modint_base& m1, const modint_base& m2) { return m1 * inv(m2.v); } friend modint_base operator+(const modint_base& m, const ll val) { return modint_base{static_cast<ll>(m.v) + val}; } friend modint_base operator-(const modint_base& m, const ll val) { return modint_base{static_cast<ll>(m.v) - val}; } friend modint_base operator*(const modint_base& m, const ll val) { return modint_base{static_cast<ll>(m.v) * (val % static_cast<ll>(mod()))}; } friend modint_base operator/(const modint_base& m, const ll val) { return modint_base{static_cast<ll>(m.v) * inv(val)}; } friend modint_base operator+(const ll val, const modint_base& m) { return modint_base{static_cast<ll>(m.v) + val}; } friend modint_base operator-(const ll val, const modint_base& m) { return modint_base{-static_cast<ll>(m.v) + val}; } friend modint_base operator*(const ll val, const modint_base& m) { return modint_base{static_cast<ll>(m.v) * (val % static_cast<ll>(mod()))}; } friend modint_base operator/(const ll val, const modint_base& m) { return modint_base{val * inv(static_cast<ll>(m.v))}; } friend modint_base& operator+=(modint_base& m1, const modint_base& m2) { return m1 = m1 + m2; } friend modint_base& operator-=(modint_base& m1, const modint_base& m2) { return m1 = m1 - m2; } friend modint_base& operator*=(modint_base& m1, const modint_base& m2) { return m1 = m1 * m2; } friend modint_base& operator/=(modint_base& m1, const modint_base& m2) { return m1 = m1 / m2; } friend modint_base& operator+=(modint_base& m, const ll val) { return m = m + val; } friend modint_base& operator-=(modint_base& m, const ll val) { return m = m - val; } friend modint_base& operator*=(modint_base& m, const ll val) { return m = m * val; } friend modint_base& operator/=(modint_base& m, const ll val) { return m = m / val; } friend modint_base operator^(const modint_base& m, const ll n) { return power(m.v, n); } friend modint_base& operator^=(modint_base& m, const ll n) { return m = m ^ n; } friend bool operator==(const modint_base& m1, const modint_base& m2) { return m1.v == m2.v; } friend bool operator!=(const modint_base& m1, const modint_base& m2) { return not(m1 == m2); } friend bool operator==(const modint_base& m, const ll val) { return m.v == norm(static_cast<uint>(static_cast<ll>(mod()) + val % static_cast<ll>(mod()))); } friend bool operator!=(const modint_base& m, const ll val) { return not(m == val); } friend bool operator==(const ll val, const modint_base& m) { return m.v == norm(static_cast<uint>(static_cast<ll>(mod()) + val % static_cast<ll>(mod()))); } friend bool operator!=(const ll val, const modint_base& m) { return not(m == val); } friend std::istream& operator>>(std::istream& is, modint_base& m) { ll v; return is >> v, m = v, is; } friend std::ostream& operator<<(std::ostream& os, const modint_base& m) { return os << m(); } uint operator()() const { return v; } static modint_base small_inv(const usize n) { auto& in = inv_ref(); if (n < in.size()) { return in[n]; } for (usize i = in.size(); i <= n; i++) { in.push_back(-in[modint_base::mod() % i] * (modint_base::mod() / i)); } return in.back(); } private: template<typename UInt = uint> static std::enable_if_t<dynamic, UInt&> mod_ref() { static UInt mod = 0; return mod; } static uint norm(const uint x) { return x < mod() ? x : x - mod(); } static modint_base make(const uint x) { modint_base m; return m.v = x, m; } static modint_base power(modint_base x, ull n) { modint_base ans = 1; for (; n; n >>= 1, x *= x) { if (n & 1) { ans *= x; } } return ans; } static modint_base inv(const ll v) { return v < 1000000 ? small_inv(static_cast<usize>(v)) : modint_base{inverse(v, static_cast<ll>(mod()))}; } static std::vector<modint_base>& inv_ref() { static std::vector<modint_base> in{1, 1}; return in; } uint v; }; template<uint mod> using modint = modint_base<mod, false>; template<uint id> using dynamic_modint = modint_base<id, true>; template<uint mod_value, bool dynamic = false> class modcomb_base { public: using value_type = modint_base<mod_value, dynamic>; modcomb_base() = delete; static void set_mod(const uint mod) { value_type::set_mod(mod), fact_ref() = {1, 1}, inv_fact_ref() = {1, 1}; } static value_type fact(const usize n) { auto& f = fact_ref(); if (n < f.size()) { return f[n]; } for (usize i = f.size(); i <= n; i++) { f.push_back(f.back() * i); } return f.back(); } static value_type inv_fact(const usize n) { auto& invf = inv_fact_ref(); if (n < invf.size()) { return invf[n]; } for (usize i = invf.size(); i <= n; i++) { invf.push_back(invf.back() * value_type::small_inv(i)); } return invf.back(); } static value_type perm(const usize n, const usize k) { return k > n ? value_type{0} : fact(n) * inv_fact(n - k); } static value_type comb(const usize n, const usize k) { return k > n ? value_type{0} : fact(n) * inv_fact(n - k) * inv_fact(k); } private: static std::vector<value_type>& fact_ref() { static std::vector<value_type> f{1, 1}; return f; } static std::vector<value_type>& inv_fact_ref() { static std::vector<value_type> invf{1, 1}; return invf; } }; template<uint mod> using modcomb = modcomb_base<mod, false>; template<uint id> using dynamic_modcomb = modcomb_base<id, true>; int main() { using mint = modint<mod>; using moc = modcomb<mod>; const auto [n, l, r, k] = read_vals<usize, usize, usize, usize>(); usize dl = log2p1(l) - 1, dr = log2p1(r) - 1; if (dl > dr) { std::swap(dl, dr); } SHOW(dl, dr); mint ans = 0; for (usize d = 0; d <= std::min(dl, dr); d++) { const usize pl = (dl - d) + (dr - d); if (pl != k) { continue; } ans += (mint(2) ^ d) * (mint(2) ^ (dl - d)) * (mint(2) ^ (dr - d - 1)) * (d == dl ? 2 : 1); } for (usize i = 0; i < n; i++) { ll num = 1LL << i; if (i == dl) { num--; } if (i == dr) { num--; } SHOW(i, num); ans *= moc::fact(num); } std::cout << ans << std::endl; return 0; }