結果
問題 | No.941 商とあまり |
ユーザー | Pachicobue |
提出日時 | 2019-12-04 03:55:42 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 32,568 bytes |
コンパイル時間 | 3,423 ms |
コンパイル使用メモリ | 239,844 KB |
実行使用メモリ | 81,084 KB |
最終ジャッジ日時 | 2024-05-06 13:15:59 |
合計ジャッジ時間 | 31,578 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | TLE | - |
testcase_01 | TLE | - |
testcase_02 | TLE | - |
testcase_03 | WA | - |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | TLE | - |
testcase_08 | TLE | - |
testcase_09 | TLE | - |
testcase_10 | TLE | - |
testcase_11 | TLE | - |
testcase_12 | TLE | - |
testcase_13 | AC | 30 ms
5,376 KB |
testcase_14 | TLE | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
testcase_40 | -- | - |
testcase_41 | -- | - |
testcase_42 | -- | - |
testcase_43 | -- | - |
testcase_44 | -- | - |
testcase_45 | -- | - |
testcase_46 | -- | - |
testcase_47 | -- | - |
testcase_48 | -- | - |
testcase_49 | -- | - |
testcase_50 | -- | - |
testcase_51 | -- | - |
testcase_52 | -- | - |
testcase_53 | -- | - |
testcase_54 | -- | - |
testcase_55 | -- | - |
testcase_56 | -- | - |
testcase_57 | -- | - |
testcase_58 | -- | - |
testcase_59 | -- | - |
testcase_60 | -- | - |
testcase_61 | -- | - |
testcase_62 | -- | - |
testcase_63 | -- | - |
testcase_64 | -- | - |
testcase_65 | -- | - |
testcase_66 | -- | - |
testcase_67 | -- | - |
testcase_68 | -- | - |
testcase_69 | -- | - |
testcase_70 | -- | - |
testcase_71 | -- | - |
testcase_72 | -- | - |
testcase_73 | -- | - |
testcase_74 | -- | - |
testcase_75 | -- | - |
testcase_76 | -- | - |
testcase_77 | -- | - |
testcase_78 | -- | - |
testcase_79 | -- | - |
testcase_80 | -- | - |
testcase_81 | -- | - |
testcase_82 | -- | - |
testcase_83 | -- | - |
testcase_84 | -- | - |
testcase_85 | -- | - |
testcase_86 | -- | - |
testcase_87 | -- | - |
testcase_88 | -- | - |
testcase_89 | -- | - |
testcase_90 | -- | - |
testcase_91 | -- | - |
testcase_92 | -- | - |
testcase_93 | -- | - |
testcase_94 | -- | - |
testcase_95 | -- | - |
testcase_96 | -- | - |
testcase_97 | -- | - |
testcase_98 | -- | - |
testcase_99 | -- | - |
testcase_100 | -- | - |
testcase_101 | -- | - |
testcase_102 | -- | - |
testcase_103 | -- | - |
testcase_104 | -- | - |
testcase_105 | -- | - |
testcase_106 | -- | - |
testcase_107 | -- | - |
testcase_108 | -- | - |
testcase_109 | -- | - |
ソースコード
#include <bits/stdc++.h> // created [2019/12/03] 23:59:35 #pragma GCC diagnostic ignored "-Wsign-compare" #pragma GCC diagnostic ignored "-Wsign-conversion" 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<bool>((static_cast<u64>(mask) >> ind) & static_cast<u64>(1)); } template<typename T> void bset(T& mask, const usize ind) { mask |= (static_cast<T>(1) << ind); } template<typename T> void breset(T& mask, const usize ind) { mask &= ~(static_cast<T>(1) << ind); } template<typename T> void bflip(T& mask, const usize ind) { mask ^= (static_cast<T>(1) << ind); } template<typename T> void bset(T& mask, const usize ind, const bool b) { (b ? bset(mask, ind) : breset(mask, ind)); } 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, typename... Args> auto read(const usize size, Args... args) { std::vector<decltype(read<T>(args...))> ans(size); for (usize i = 0; i < size; i++) { ans[i] = read<T>(args...); } return ans; } template<typename... Types> auto reads() { return std::tuple<std::decay_t<Types>...>{read<Types>()...}; } # define SHOW(...) static_cast<void>(0) constexpr ull TEN(const usize n) { return n == 0 ? 1ULL : TEN(n - 1) * 10ULL; } template<typename T> std::vector<T> make_v(const usize size, const T v) { return std::vector<T>(size, v); } template<typename... Args> auto make_v(const usize 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 < 0 ? gcd(-a, b) : b < 0 ? gcd(a, -b) : (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>; /** * http://xoshiro.di.unimi.it/xoshiro128starstar.c * http://xoshiro.di.unimi.it/xoshiro256starstar.c * http://xoshiro.di.unimi.it/splitmix64.c */ class xoshiro { public: using result_type = uint32_t; static constexpr result_type min() { return std::numeric_limits<result_type>::min(); } static constexpr result_type max() { return std::numeric_limits<result_type>::max(); } xoshiro() : xoshiro(std::random_device{}()) {} xoshiro(uint64_t seed) { uint64_t z = 0; for (int i = 0; i < 4; i++) { z = (seed += 0x9e3779b97f4a7c15), z = (z ^ (z >> 33)) * 0x62A9D9ED799705F5, z = (z ^ (z >> 28)) * 0xCB24D0A5C88C35B3, s[i] = static_cast<result_type>(z >> 32); } } result_type operator()() { const result_type result = rotl(s[1] * 5, 7) * 9, t = s[1] << 9; return s[2] ^= s[0], s[3] ^= s[1], s[1] ^= s[2], s[0] ^= s[3], s[2] ^= t, s[3] = rotl(s[3], 11), result; } void discard(const usize rep) { for (usize i = 0; i < rep; i++) { (*this)(); } } private: result_type s[4]; static result_type rotl(const result_type x, const int k) { return (x << k) | (x >> (32 - k)); } }; class xoshiro_64 { public: using result_type = uint64_t; static constexpr result_type min() { return std::numeric_limits<result_type>::min(); } static constexpr result_type max() { return std::numeric_limits<result_type>::max(); } xoshiro_64() : xoshiro_64(std::random_device{}()) {} xoshiro_64(uint64_t seed) { uint64_t z = 0; for (int i = 0; i < 4; i++) { z = (seed += 0x9e3779b97f4a7c15), z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9, z = (z ^ (z >> 27)) * 0x94d049bb133111eb, s[i] = static_cast<result_type>(z ^ (z >> 31)); } } result_type operator()() { const result_type result = rotl(s[1] * 5, 7) * 9, t = s[1] << 17; return s[2] ^= s[0], s[3] ^= s[1], s[1] ^= s[2], s[0] ^= s[3], s[2] ^= t, s[3] = rotl(s[3], 45), result; } void discard(const usize rep) { for (usize i = 0; i < rep; i++) { (*this)(); } } private: result_type s[4]; static result_type rotl(const result_type x, const int k) { return (x << k) | (x >> (64 - k)); } }; template<typename Rng> class rng_base { public: using rng_type = Rng; using result_type = typename rng_type::result_type; static constexpr result_type min() { return rng_type::min(); } static constexpr result_type max() { return rng_type::max(); } rng_base() : rng_base(std::random_device{}()) {} rng_base(const u64 seed) : rng(seed) {} ~rng_base() = default; result_type operator()(const result_type max = std::numeric_limits<result_type>::max()) { if (max == std::numeric_limits<result_type>::max()) { return static_cast<result_type>(rng()); } if (ispow2(max + 1)) { return static_cast<result_type>(rng() & max); } const result_type mask = static_cast<result_type>(ceil2(static_cast<u64>(max + 1))) - 1; while (true) { const result_type ans = static_cast<result_type>(rng() & mask); if (ans <= max) { return ans; } } } result_type operator()(const result_type min, const result_type max) { return min + (*this)(max - min); } operator bool() { return *this(0, 1); } template<typename Int> std::pair<Int, Int> pair(const Int min, const Int max, const bool sorted = false) { return sorted ? std::minmax(*this(min, max), *this(min, max)) : std::pair<Int, Int>{*this(min, max), *this(min, max)}; } template<typename Int> std::vector<Int> vec(const std::size_t size, const Int min, const Int max) { std::vector<Int> v(size); for (std::size_t i = 0; i < size; i++) { v[i] = *this(min, max); } return v; } std::vector<usize> perm(const usize n) { std::vector<usize> ans(n); std::iota(ans.begin(), ans.end(), 0UL); std::shuffle(ans.begin(), ans.end(), rng); return ans; } private: Rng rng; }; using rng_mt = rng_base<std::mt19937>; using rng_mt64 = rng_base<std::mt19937_64>; using rng_xoshiro = rng_base<xoshiro>; using rng_xoshiro64 = rng_base<xoshiro_64>; rng_mt g_rng_mt; rng_mt64 g_rng_mt64; rng_xoshiro g_rng_xo; rng_xoshiro64 g_rng_xo64; namespace bbst_node { template<typename Key, typename Node, typename Comp> struct key_node : Node { using ptr = key_node* const; using const_ptr = const ptr; using key_type = Key; using comp_type = Comp; key_node() : Node{}, key{Key{}} {} template<typename... Args> key_node(const Key& key, Args... args) : Node{args...}, key{key} { this->sz = 1; } void pull_up(const_ptr l, const_ptr r) { Node::pull_up(l, r); } void push_down(ptr l, ptr r) { Node::push_down(l, r); } template<typename Value> void set(const Value& val, const_ptr l, const_ptr r) { Node::set(val, l, r); } template<typename Op> void act(const Op& o) { Node::act(o); } friend std::ostream& operator<<(std::ostream& os, const key_node& n) { return os << "key=" << n.key << ":" << static_cast<Node>(n); } const key_type key; }; struct node { using ptr = node* const; using const_ptr = const ptr; void pull_up(const_ptr l, const_ptr r) { sz = (l ? l->sz : 0UL) + 1UL + (r ? r->sz : 0UL); } void push_down(ptr, ptr) {} friend std::ostream& operator<<(std::ostream& os, const node& n) { return os << "size=" << n.sz; } usize sz = 0; }; template<typename Value> struct value_node { using ptr = value_node* const; using const_ptr = const ptr; using value_type = Value; value_node() = default; value_node(const value_type& value) : value{value}, sz{1} {} void pull_up(const_ptr l, const_ptr r) { sz = (l ? l->sz : 0UL) + 1UL + (r ? r->sz : 0UL); } void push_down(ptr, ptr) {} void set(const value_type& val, const_ptr, const_ptr) { value = val; } friend std::ostream& operator<<(std::ostream& os, const value_node& n) { return os << "value=" << n.value; } value_type value{}; usize sz = 0; }; template<typename ValueMonoid> struct merge_node { using ptr = merge_node* const; using const_ptr = const ptr; using value_monoid_type = ValueMonoid; using value_type = typename value_monoid_type::value_type; merge_node() = default; merge_node(const value_type& value) : value{value}, merged{value}, sz{1} {} void pull_up(const_ptr l, const_ptr r) { sz = (l ? l->sz : 0UL) + 1UL + (r ? r->sz : 0UL), merged = value_monoid_type::merge((l ? l->merged : value_monoid_type::id()), value_monoid_type::merge(value, (r ? r->merged : value_monoid_type::id()))); } void push_down(ptr, ptr) {} void set(const value_type& val, const_ptr l, const_ptr r) { value = val, pull_up(l, r); } friend std::ostream& operator<<(std::ostream& os, const merge_node& n) { return os << "value=" << n.value << ",merged=" << n.merged; } value_type value = value_monoid_type::id(), merged = value_monoid_type::id(); usize sz = 0; }; template<typename MonoidAct> struct lazy_node { using ptr = lazy_node* const; using const_ptr = const ptr; using monoid_act_type = MonoidAct; using value_monoid_type = typename monoid_act_type::value_monoid_type; using operator_monoid_type = typename monoid_act_type::operator_monoid_type; using value_type = typename value_monoid_type::value_type; using operator_type = typename operator_monoid_type::operator_type; lazy_node() = default; lazy_node(const value_type& value) : value{value}, merged{value}, sz{1} {} void pull_up(const_ptr l, const_ptr r) { sz = (l ? l->sz : 0UL) + 1UL + (r ? r->sz : 0UL), merged = value_monoid_type::merge((l ? l->merged : value_monoid_type::id()), value_monoid_type::merge(value, (r ? r->merged : value_monoid_type::id()))); } void push_down(ptr l, ptr r) { if (op == operator_monoid_type::id()) { return; } if (l) { l->act(op); } if (r) { r->act(op); } op = operator_monoid_type::id(); } void set(const value_type& val, const_ptr l, const_ptr r) { value = val, pull_up(l, r); } void act(const operator_type& o) { value = monoid_act_type::apply(o, value, 1), merged = monoid_act_type::apply(o, merged, sz), op = operator_monoid_type::compose(op, o); } friend std::ostream& operator<<(std::ostream& os, const lazy_node& n) { return os << "value=" << n.value << ",merged=" << n.merged << ",op=" << n.op; } value_type value = value_monoid_type::id(), merged = value_monoid_type::id(); operator_type op = operator_monoid_type::id(); usize sz = 0; }; } // namespace bbst_node template<typename NodeData> class base_rbstree { private: class node { using ptr = node*; using const_ptr = const node* const; using tree = ptr; public: node() : node_data{} {} template<typename... Args> node(Args... args) : node_data{args...} {} usize size() const { return node_data.sz; } const NodeData& data() const { return node_data; } template<typename Operator> void act(const Operator& op) { node_data.act(op); } template<typename Value> void set(const Value& value) { node_data.set(value, data_ptr_of(l), data_ptr_of(r)), pull_up(); } friend std::ostream& operator<<(std::ostream& os, const node& n) { return os << "[" << n.node_data << "]"; } bool has_left() const { return l; } bool has_right() const { return r; } const node& left() const { return deptr(l); } const node& right() const { return deptr(r); } static node& deptr(ptr x) { return x ? (*x) : empty_node; } static ptr merge(tree tp1, tree tp2) { if (not tp1) { return tp2; } if (not tp2) { return tp1; } if (g_rng_xo(static_cast<uint>(size_of(tp1) + size_of(tp2) - 1)) < static_cast<uint>(size_of(tp1))) { return tp1->push_down(), tp1->r = merge(tp1->r, tp2), tp1->pull_up(), tp1; } else { return tp2->push_down(), tp2->l = merge(tp1, tp2->l), tp2->pull_up(), tp2; } } static std::pair<ptr, ptr> split_at(tree tp, const usize pos) { if (not tp) { return {nullptr, nullptr}; } tp->push_down(); if (pos == 0) { return std::make_pair(nullptr, tp); } if (pos == size_of(tp)) { return std::make_pair(tp, nullptr); } if (pos <= size_of(tp->l)) { auto ls = split_at(tp->l, pos); return tp->l = ls.second, tp->pull_up(), std::make_pair(ls.first, tp); } else { auto rs = split_at(tp->r, pos - size_of(tp->l) - 1); return tp->r = rs.first, tp->pull_up(), std::make_pair(tp, rs.second); } } static std::tuple<ptr, ptr, ptr> split_range(tree tp, const usize pos_min, const usize pos_sup) { auto ts = split_at(tp, pos_min), trs = split_at(ts.second, pos_sup - pos_min); return std::make_tuple(ts.first, trs.first, trs.second); } template<typename Key> static std::pair<ptr, ptr> split_lower(tree tp, const Key& key) { if (not tp) { return {nullptr, nullptr}; } const typename NodeData::comp_type& comp{}; if (comp(tp->data().key, key)) { auto rs = split_lower(tp->r, key); return tp->r = rs.first, tp->pull_up(), std::make_pair(tp, rs.second); } else { auto ls = split_lower(tp->l, key); return tp->l = ls.second, tp->pull_up(), std::make_pair(ls.first, tp); } } template<typename Key> static std::pair<ptr, ptr> split_upper(tree tp, const Key& key) { if (not tp) { return {nullptr, nullptr}; } const typename NodeData::comp_type& comp{}; if (comp(key, tp->data().key)) { auto ls = split_upper(tp->l, key); return tp->l = ls.second, tp->pull_up(), std::make_pair(ls.first, tp); } else { auto rs = split_upper(tp->r, key); return tp->r = rs.first, tp->pull_up(), std::make_pair(tp, rs.second); } } template<typename Key> static std::tuple<ptr, ptr, ptr> split_key_range(tree tp, const Key& key_min, const Key& key_max) { auto ts = split_lower(tp, key_min), trs = split_upper(ts.second, key_max); return std::make_tuple(ts.first, trs.first, trs.second); } private: static NodeData* data_ptr_of(ptr x) { return x ? &(x->node_data) : nullptr; } static usize size_of(const_ptr x) { return x ? x->size() : 0UL; } void pull_up() { node_data.pull_up(data_ptr_of(l), data_ptr_of(r)); } void push_down() { node_data.push_down(data_ptr_of(l), data_ptr_of(r)); } static node empty_node; // inline変数を使いたいでござる NodeData node_data; ptr l = nullptr, r = nullptr; }; using ptr = node*; ptr root = nullptr; public: base_rbstree() = default; base_rbstree(const ptr r) : root{r} {} template<typename... Args> base_rbstree(Args... args) : root{new node{args...}} {} bool empty() const { return not root; } usize size() const { return node::size(root); } const node& top() const { return node::deptr(root); } node at(const usize pos) { return fold_range(pos, pos + 1); } node fold_range(const usize pos_min, const usize pos_sup) { auto ts = node::split_range(root, pos_min, pos_sup); const node ans = node::deptr(std::get<1>(ts)); return root = node::merge(std::get<0>(ts), node::merge(std::get<1>(ts), std::get<2>(ts))), ans; } template<typename Key> node fold_key_range(const Key& key_min, const Key& key_max) { auto ts = node::split_key_range(root, key_min, key_max); const node ans = node::deptr(std::get<1>(ts)); return root = node::merge(std::get<0>(ts), node::merge(std::get<1>(ts), std::get<2>(ts))), ans; } template<typename Key> node fold_lower(const Key& key) { auto ts = node::split_lower(root, key); const node ans = node::deptr(ts.first); return root = node::merge(ts.first, ts.second), ans; } template<typename Key> node fold_upper(const Key& key) { auto ts = node::split_upper(root, key); const node ans = node::deptr(ts.first); return root = node::merge(ts.first, ts.second), ans; } template<typename Value> base_rbstree& set_at(const usize pos, const Value& value) { auto ts = node::split_range(root, pos, pos + 1); std::get<1>(ts)->set(value); return root = node::merge(std::get<0>(ts), node::merge(std::get<1>(ts), std::get<2>(ts))), *this; } template<typename Key, typename Value> base_rbstree& set(const Key& key, const Value& value) { auto ts = node::split_key_range(root, key, key); std::get<1>(ts)->set(value); return root = node::merge(std::get<0>(ts), node::merge(std::get<1>(ts), std::get<2>(ts))), *this; } template<typename Op> base_rbstree& act_range(const usize pos_min, const usize pos_sup, const Op& op) { auto ts = node::split_range(root, pos_min, pos_sup); std::get<1>(ts)->act(op); return root = node::merge(std::get<0>(ts), node::merge(std::get<1>(ts), std::get<2>(ts))), *this; } template<typename Key, typename Op> base_rbstree& act_key_range(const Key& key_min, const Key& key_max, const Op& op) { auto ts = node::split_key_range(root, key_min, key_max); std::get<1>(ts)->act(op); return root = node::merge(std::get<0>(ts), node::merge(std::get<1>(ts), std::get<2>(ts))), *this; } base_rbstree& merge(base_rbstree&& t) { return root = node::merge(root, t.root), *this; } base_rbstree split_at(const usize pos) { auto ts = node::split_at(root, pos); return root = ts.first, base_rbstree(ts.second); } std::pair<base_rbstree, base_rbstree> split_range(const usize pos_min, const usize pos_sup) { auto ts = node::split_range(root, pos_min, pos_sup); return root = std::get<0>(ts), std::make_pair(base_rbstree(std::get<1>(ts)), base_rbstree(std::get<2>(ts))); } base_rbstree& erase_at(const usize pos) { auto ts = node::split_at(root, pos), trs = node::split_at(ts.second, 1); return root = node::merge(ts.first, trs.second), *this; } base_rbstree& insert_at(const usize pos, base_rbstree&& t) { auto ts = node::split_at(root, pos); return root = node::merge(node::merge(ts.first, t.root), ts.second), *this; } template<typename Key> base_rbstree split_lower(const Key& key) { auto ts = node::split_lower(root, key); return root = ts.first, base_rbstree(ts.second); } template<typename Key> base_rbstree split_upper(const Key& key) { auto ts = node::split_upper(root, key); return root = ts.first, base_rbstree(ts.second); } template<typename Key> std::pair<base_rbstree, base_rbstree> split_key_range(const Key& key_min, const Key& key_max) { auto ts = node::split_key_range(root, key_min, key_max); return root = std::get<0>(ts), std::make_pair(base_rbstree(std::get<1>(ts)), base_rbstree(std::get<2>(ts))); } base_rbstree& insert(const node& n) { auto ts = node::split_lower(root, n.data().key); return root = node::merge(node::merge(ts.first, new node{n}), ts.second), *this; } std::vector<node> data() { if (empty()) { return std::vector<node>{}; } auto dfs = [&](auto&& self, const node& n) -> std::vector<node> { std::vector<node> ans; if (n.has_left()) { for (auto&& e : self(self, n.left())) { ans.emplace_back(e); } } ans.push_back(n); if (n.has_right()) { for (auto&& e : self(self, n.right())) { ans.emplace_back(e); } } return ans; }; return dfs(dfs, *root); } }; template<typename NodeData> typename base_rbstree<NodeData>::node base_rbstree<NodeData>::node::empty_node = node{}; template<typename Value> using rbstree = base_rbstree<bbst_node::value_node<Value>>; template<typename Key, typename Comp = std::less<Key>> using mset_rbstree = base_rbstree<bbst_node::key_node<Key, bbst_node::node, Comp>>; template<typename Key, typename Value, typename Comp = std::less<Key>> using mmap_rbstree = base_rbstree<bbst_node::key_node<Key, bbst_node::value_node<Value>, Comp>>; template<typename ValueMonoid> using merge_rbstree = base_rbstree<bbst_node::merge_node<ValueMonoid>>; template<typename MonoidAct> using lazy_rbstree = base_rbstree<bbst_node::lazy_node<MonoidAct>>; int main() { const int N = read<int>(); const ull X = read<ull>(); auto A = read<ull>(N); { ull x = X + 1; for (const ull a : A) { x /= (a + 1); } if (x == 0) { return std::cout << std::string(X, '0') << std::endl, 0; } } { const ull m = *std::min_element(A.begin(), A.end()); if (m == 1) { ull p = 1; for (const ull a : A) { p *= (a + 1); } p--; for (int i = 1; i <= X; i++) { std::cout << (i >= p); } return std::cout << std::endl, 0; } } using mint = modint<mod>; std::vector<mint> hs(X + 1), ihs(X + 1, 1); for (int i = 0; i <= X; i++) { hs[i] = g_rng_xo64(2, mod - 2); } for (int i = 0; i <= X; i++) { ihs[i] /= hs[i]; } rbstree<ull> res; for (const ull a : A) { res.insert_at(0, a); } int n = N; mint hash = 1; for (const ull a : A) { hash *= hs[a]; } ull product = 1; for (const ull a : A) { product *= (a + 1); } std::vector<bool> ok(X + 1, false); ok[product] = true; for (const ull a : A) { for (ull x = product; x <= X; x += a) { ok[x] = true; } } using pll = std::pair<ull, ull>; auto pick = [&](int i, int j) -> pll { const ull x = res.at(i).data().value; const ull y = res.at(j).data().value; assert(product % ((x + 1) * (y + 1)) == 0); (product /= (x + 1)) /= (y + 1); (hash *= ihs[x]) *= ihs[y]; res.erase_at(j); res.erase_at(i); n -= 2; return {x, y}; }; auto insert = [&](const ull z) { res.insert_at(n, z); hash *= hs[z]; product *= (z + 1); n++; }; auto remove = [&]() { const ull z = res.at(n - 1).data().value; res.erase_at(n - 1); assert(product % (z + 1) == 0); (product /= (z + 1)); hash *= ihs[z]; n--; }; auto undo = [&](int i, int j, ull x, ull y) { (product *= (x + 1)) *= (y + 1); (hash *= hs[x]) *= hs[y]; res.insert_at(i, x); res.insert_at(j, y); n += 2; }; std::set<uint> used; auto dfs = [&](auto&& self) -> void { if (used.find(hash()) != used.end()) { return; } used.insert(hash()); if (n == 1) { ok[res.at(0).data().value] = true; return; } for (int i = 0; i + 1 < n; i++) { for (int j = i + 1; j < n; j++) { const auto p = pick(i, j); const ull x = p.first, y = p.second; if (used.find(hash()) == used.end()) { ull min = (x + 1) * (y + 1) - 1; for (ull i = 0; i < 3; i++) { // ここが明らかに無駄なんですが、どうすればいいか分からん const ull z = min + x * i; if (product * (z + 1) > X + 1) { break; } insert(z); self(self); remove(); } for (ull i = 1; i < 3; i++) { // ここが明らかに無駄なんですが、どうすればいいか分からん const ull z = min + y * i; if (product * (z + 1) > X + 1) { break; } insert(z); self(self); remove(); } } undo(i, j, x, y); } } }; dfs(dfs); for (int x = 1; x <= X; x++) { std::cout << ok[x]; } std::cout << std::endl; return 0; }