/** * date : 2026-10-16 22:37:23 * author : yamadanull * library : https://github.com/yamadanull/yamadalib/ */ // ===== BEGIN INCLUDE: ../../template/template.hpp ===== #include using namespace std; // ===== BEGIN INCLUDE: util.hpp ===== namespace yamada { using ll = long long; using i32 = int; using u32 = unsigned int; using i64 = long long; using u64 = unsigned long long; using i128 = __int128_t; using u128 = __uint128_t; using lld = long double; template using vc = vector; template using vvc = vector>; template using vvvc = vector>>; template using vvvvc = vector>>>; using vint = vector; using vl = vector; using vd = vector; using vs = vector; using vvl = vector>; using vvvl = vector>>; using vvvvl = vector>>>; template using minpq = priority_queue, greater>; template using maxpq = priority_queue, less>; using pint = pair; using pl = pair; using vp = vc; using vvp = vvc; template int len(const T &t) { return t.size(); } constexpr int inf = 1001001001; constexpr long long infLL = 4004004004004004004LL; template inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; } template inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; } template pair mkp(const T &t, const U &u) { return make_pair(t, u); } template tuple mkt(const Args&... args) { return make_tuple(args...); } template ranges::range_value_t Sum(const R &v) { return ranges::fold_left(v, ranges::range_value_t(0), plus()); } template int lb(const vector &v, const T &a) { return ranges::lower_bound(v, a) - v.begin(); } template int ub(const vector &v, const T &a) { return ranges::upper_bound(v, a) - v.begin(); } constexpr long long TEN(int n) { long long ret = 1, x = 10; for (; n; x *= x, n >>= 1) ret *= (n & 1 ? x : 1); return ret; } template vector mkrui(const vector &v, const bool rev = false) { vector ret(v.size() + 1); if (rev) { for (int i = (int)v.size() - 1; i >= 0; i--) ret[i] = v[i] + ret[i + 1]; } else { for (int i = 0; i < (int)v.size(); i++) ret[i + 1] = ret[i] + v[i]; } return ret; }; template vector mkuni(const vector &v) { vector ret(v); ranges::sort(ret); ret.erase(ranges::unique(ret).begin(), ret.end()); return ret; } template vector mkord(int N, const F &f) { vector ord = views::iota(0, N) | ranges::to(); ranges::sort(ord, f); return ord; } template vector mkinv(const vector &v) { vector inv(ranges::max(v) + 1, -1); for (int i = 0; i < (int)v.size(); i++) inv[v[i]] = i; return inv; } vector mkiota(int N) { return views::iota(0, N) | ranges::to(); } vector p_mrg(const vector &f, const vector &g) { // g o f return f | views::transform([&](auto a) { return g[a]; }) | ranges::to(); } template // f: old_idx -> new_idx vector p_shf(const vector& A, const vector& f, const bool inv = false) { int n = A.size(); vector ret(n); if (!inv) for (int i = 0; i < n; i++) ret[f[i]] = A[i]; else for (int i = 0; i < n; i++) ret[i] = A[f[i]]; return ret; } template T mkrev(const T &v) { return v | views::reverse | ranges::to(); } template bool nxp(C &v) { return ranges::next_permutation(v).found; } template void nxp(int N, F f) { auto a = views::iota(0, N) | ranges::to(); do { f(a); } while (nxp(a)); } // i 要素目 : [0, A[i]) template void Product(const vector &A, const F& f) { vector cur; [&](this auto dfs, int i) -> void { if (i == (int)A.size()) { f(cur); return; } for (int j = 0; j < A[i]; j++) cur.emplace_back(j), dfs(i + 1), cur.pop_back(); }(0); } // i 要素目 : [0, M) template void Product(const int N, const int M, const F& f) { vector A(N, M); Product(A, f); } template vector Digit(T a, const U &x, int siz = -1) { vector ret; while (a > 0) { ret.emplace_back(a % x); a /= x; } if (siz >= 0) ret.resize(siz); return ret; } // F : function(void(T&)), mod を取る操作 // T : 整数型のときはオーバーフローに注意する template T Power(T a, long long n, const T &I, const function &f) { T res = I; for (; n; f(a = a * a), n >>= 1) { if (n & 1) f(res = res * a); } return res; } // T : 整数型のときはオーバーフローに注意する template T Power(T a, long long n, const T &I = T{1}) { return Power(a, n, I, function{[](T &) -> void {}}); } template vector Transpose(const vector &A) { if (A.empty()) return {}; return views::iota(0, (int)A[0].size()) | views::transform([&](auto j) { return A | views::transform([&](auto&& a) { return a[j]; }) | ranges::to(); }) | ranges::to>(); } template vector RotateGrid(const vector &A) { if (A.empty()) return {}; return views::iota(0, (int)A[0].size()) | views::transform([&](auto j) { return A | views::transform([&](auto&& a) { return a[j]; }) | ranges::to(); }) | views::reverse | ranges::to>(); } template T bisect(T ok, T ng, F f) { // ok < ng でも ok > ng でも可能 // f(ok) && !f(ng) が必要 while (abs(ok - ng) > 1) { T mid = (ok + ng) / 2; (f(mid) ? ok : ng) = mid; } return ok; } template T bisect(F f) { // 判定回数は上限を決め打ちした場合の高々2倍程度 // f(0) && !f(inf) が必要 T ok = 0, ng = 1; while (f(ng)) ng *= 2; while (ng - ok > 1) { T mid = ok + (ng - ok) / 2; (f(mid) ? ok : ng) = mid; } return ng; } template T bisect_double(T ok, T ng, F f, int iter = 100) { if (ok == ng) return ok; while (iter--) { T mid = (ok + ng) / 2; (f(mid) ? ok : ng) = mid; } return ng; } template bool inLR(T0 L, T1 x, T2 R){ return L <= x && x < R; } bool YESNO(bool b) { cout << (b ? "YES\n" : "NO\n"); return b; } bool YesNo(bool b) { cout << (b ? "Yes\n" : "No\n"); return b; } bool yesno(bool b) { cout << (b ? "yes\n" : "no\n"); return b; } long long Isqrt(long long n) { if (n <= 0) return 0; long long x = sqrt(n); while ((x + 1) * (x + 1) <= n) x++; while (x * x > n) x--; return x; } template struct CumulativeSum { vector S; CumulativeSum(vector &A) : S(A.size() + 1) { for (int i = 0; i < (int)A.size(); i++) S[i + 1] = S[i] + A[i]; } T query(int l, int r) { return (l <= r ? S[r] - S[l] : T(0)); } T query() { return S.back(); } inline T operator()(int l, int r) { return query(l, r); } inline T operator()() { return query(); } }; // 速度よりオーバーフロー対策優先 template T floor(T a, T b) { assert(b); if (b < 0) a = -a, b = -b; return a / b - (a % b < 0); } template T under(T a, T b) { assert(b); if (b < 0) a = -a, b = -b; return a / b - (a % b <= 0); } template T ceil (T a, T b) { assert(b); if (b < 0) a = -a, b = -b; return a / b + (a % b > 0); } template T over (T a, T b) { assert(b); if (b < 0) a = -a, b = -b; return a / b + (a % b >= 0); } template T modulo(T a, T b) { assert(b > 0); T c = a % b; return c < 0 ? c + b : c; } template pair divmod(T a, T b) { assert(b > 0); T q = a / b, r = a % b; if (r < 0) --q, r += b; return {q, r}; } template string tof(const mint &a) { for (int deno = 1; deno <= iter; deno++) { mint inv = ((mint)deno).inverse(); for (int nume = 0; nume <= iter; nume++) { mint val = inv * nume; if (val == a) { if (deno == 1) return to_string(nume); return to_string(nume) + "/" + to_string(deno); } else if (-val == a) { if (deno == 1) return to_string(-nume); return to_string(-nume) + "/" + to_string(deno); } } } return "!NF"; // Not Found } template constexpr auto Tof = views::transform(tof); } // namespace yamada // ===== END INCLUDE: util.hpp ===== // ===== BEGIN INCLUDE: bitop.hpp ===== namespace yamada { __attribute__((target("popcnt"))) inline int popcnt(const u64 &a) { return __builtin_popcountll(a); } inline int lsb(const u64 &a) { return a ? __builtin_ctzll(a) : 64; } inline int msb(const u64 &a) { return a ? 63 - __builtin_clzll(a) : -1; } template inline int gbit(const T &a, int i) { return (a >> i) & 1; } template inline void sbit(T &a, int i, bool b) { if (gbit(a, i) != b) a ^= T(1) << i; } constexpr long long PW(int n) { return 1LL << n; } constexpr long long MSK(int n) { return (1LL << n) - 1; } string tog(int msk, int N) { return views::iota(0, N) | views::transform([&](auto i) { return msk >> i & 1 ? '#' : '.'; }) | ranges::to(); } } // namespace yamada // ===== END INCLUDE: bitop.hpp ===== // ===== BEGIN INCLUDE: io.hpp ===== namespace yamada { istream& operator>>(istream& is, __int128_t& x) { string S; is >> S; x = 0; bool f{}; for (auto &c : S) { if (c == '-') { f = 1; continue; } x *= 10; x += c - '0'; } if (f) x = -x; return is; } istream& operator>>(istream& is, __uint128_t& x) { string S; is >> S; x = 0; for (auto &c : S) { x *= 10; x += c - '0'; } return is; } ostream& operator<<(ostream& os, __int128_t x) { if (x == 0) return os << 0; if (x < 0) os << '-', x = -x; string S; while (x) S.push_back('0' + x % 10), x /= 10; ranges::reverse(S); return os << S; } ostream& operator<<(ostream& os, __uint128_t x) { if (x == 0) return os << 0; string S; while (x) S.push_back('0' + x % 10), x /= 10; ranges::reverse(S); return os << S; } template // tuple / pair / array concept TupleLike = requires { tuple_size>::value; }; template // vector / set / ranges::view など(set は入力不可) concept ListLike = ranges::input_range && !convertible_to && !TupleLike; template ostream& operator<<(ostream&, const T&); template istream& operator>>(istream&, T&&); template ostream& operator<<(ostream&, const R&); template istream& operator>>(istream&, R&&); template istream& operator>>(istream& is, T&& t) { apply([&](auto&... x) { (..., (is >> x)); }, t); return is; } template istream& operator>>(istream& is, R&& a) { for (auto&& x : a) is >> x; return is; } template ostream& operator<<(ostream& os, const T& t) { bool f{}; apply([&](const auto&... x) { (..., (os << (exchange(f, 1) ? " " : "") << x)); }, t); return os; } template ostream& operator<<(ostream& os, const R& a) { bool f{}; for (const auto& x : a) os << (exchange(f, 1) ? " " : "") << x; return os; } template void in(T&&... x) { (cin >> ... >> x); } template void out (const T&... x) { bool f{}; (..., (cout << (exchange(f, 1) ? " " : "") << x)); cout << '\n'; } template // "Flush after OUT" void fout(const T&... x) { bool f{}; (..., (cout << (exchange(f, 1) ? " " : "") << x)); cout << endl; } template // "WithOUT ln" void wout(const T&... x) { bool f{}; (..., (cout << (exchange(f, 1) ? " " : "") << x)); } struct IoSetupYamada { IoSetupYamada() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(7); } } iosetupyamada; namespace DebugImpl { void dump(const char& t) { cerr << t; } void dump(const string& t) { cerr << t; } void dump(const bool& t) { cerr << (t ? "true" : "false"); } void dump(__int128_t t) { cerr << t; } void dump(__uint128_t t) { cerr << t; } template void dump(const T& t) { string res; if (t == yamada::inf) res = "inf"; if constexpr (is_signed::value) { if (t == -yamada::inf) res = "-inf"; } if constexpr (sizeof(T) == 8) { if (t == yamada::infLL) res = "inf"; if constexpr (is_signed::value) { if (t == -yamada::infLL) res = "-inf"; } } if (res.empty()) res = to_string(t); cerr << res; } template requires (!ListLike && !TupleLike && !integral) void dump(const T& t) { cerr << t; } template void dump(const R&); template void dump(const T&); template void dump(const R& a) { bool f{}; for (const auto& x : a) { cerr << (exchange(f, 1) ? ", " : "[ "); dump(x); } cerr << " ]"; } template void dump(const T& t) { bool f{}; apply([&](const auto&... x) { (..., (cerr << (exchange(f, 1) ? ", " : "( "), dump(x))); }, t); cerr << " )"; } template void trace(const T&... x) { bool f{}; (..., (cerr << (exchange(f, 1) ? ", " : " "), dump(x))); cerr << endl; } } // namespace DebugImpl } // namespace yamada #ifdef yamadaDebug #define err(...) \ do { \ std::cerr << "## " << #__VA_ARGS__ << " = "; \ yamada::DebugImpl::trace(__VA_ARGS__); \ } while (0) #else #define err(...) (void(0)) #endif // ===== END INCLUDE: io.hpp ===== // ===== BEGIN INCLUDE: io-extension.hpp ===== namespace yamada { namespace ioImpl { struct EVAL_TAG {}; template T read() { T x{}; cin >> x; return x; } template struct GEN { F f; auto operator()(long long i = 0) const { return f(i); } auto operator=(EVAL_TAG) const { return (*this)(); } template auto to(auto n) const { auto g = [p = *this, n](long long) { long long size; if constexpr (requires { n(); }) size = n(); else size = n; A a; if constexpr (requires { a.reserve(size); }) a.reserve(size); for (long long i = 0; i < size; ++i) a.insert(a.end(), p(i)); return a; }; return GEN{g}; } template class A> auto to(auto n) const { return to(declval>() | views::as_rvalue))>(n); } auto operator* (auto n) const { return to(n); } auto operator[](auto n) const { return to(n); } template auto array() const { return ioImpl::GEN{[p = *this](long long) { std::array a; if constexpr (N > 0) for (size_t i = 0; i < N; ++i) a[i] = p(i); return a; }}; } auto operator-(auto d) const { return ioImpl::GEN{[p = *this, d](long long i) { return p(i) - d; }}; } auto operator+(auto d) const { return ioImpl::GEN{[p = *this, d](long long i) { return p(i) + d; }}; } auto operator--() const { // 前置デクリメントで使う (例: --LL --INT) (後置だと CE) return ioImpl::GEN{[p = *this](long long i) { return p(i) - 1; }}; } auto operator++() const { return ioImpl::GEN{[p = *this](long long i) { return p(i) + 1; }}; } auto uz() { // UnZip return ioImpl::GEN{[p = *this](long long i) { auto v = p(i); using T = ranges::range_value_t; return [&](index_sequence) { tuple>...> ans; ((get(ans).reserve(v.size())), ...); for (auto &x : v) ((get(ans).push_back(get(x))), ...); return ans; }(make_index_sequence>{}); }}; } }; template const auto RD = GEN{[](long long) { return read(); }}; [[maybe_unused]] const auto IDX = GEN{[](long long i) { return i; }}; [[maybe_unused]] const auto INT = RD; [[maybe_unused]] const auto LL = RD; [[maybe_unused]] const auto CHR = RD; [[maybe_unused]] const auto STR = RD; [[maybe_unused]] const auto DBL = RD; [[maybe_unused]] const auto LLD = RD; auto CON(auto x) { return GEN{[x = move(x)](long long) { return x; }}; } // CONstant auto PR(auto p, auto q) { return GEN{[=](ll i) { return pair{p(i), q(i)}; }}; } // PaiR auto TP(auto... p) { return GEN{[=](long long i) { return tuple{p(i)...}; }}; } // TuPle } // namespace ioImpl using ioImpl::RD; using ioImpl::IDX; using ioImpl::INT; using ioImpl::LL; using ioImpl::CHR; using ioImpl::STR; using ioImpl::DBL; using ioImpl::LLD; using ioImpl::CON; using ioImpl::PR; using ioImpl::TP; } // namespace yamada #define FN(i,...) yamada::ioImpl::GEN{[&](long long i) { return (__VA_ARGS__); }} // これ衝突怖い #define IN(...) __VA_OPT__(IOIMPL_E3(IOIMPL_EACH(__VA_ARGS__))) // これ衝突怖い #define BIND(...) ([__VA_ARGS__]) #define IOIMPL_E0(...) __VA_ARGS__ #define IOIMPL_E1(...) IOIMPL_E0(IOIMPL_E0(IOIMPL_E0(__VA_ARGS__))) #define IOIMPL_E2(...) IOIMPL_E1(IOIMPL_E1(IOIMPL_E1(__VA_ARGS__))) #define IOIMPL_E3(...) IOIMPL_E2(IOIMPL_E2(IOIMPL_E2(__VA_ARGS__))) #define IOIMPL_LP () #define IOIMPL_NEXT() IOIMPL_EACH #define IOIMPL_EACH(e,...) IOIMPL_ITEM(e) __VA_OPT__(IOIMPL_NEXT IOIMPL_LP (__VA_ARGS__)) #define IOIMPL_ITEM(e) auto IOIMPL_NORMALIZE(e) = [] { \ if constexpr (std::string_view{#e}.contains('=')) return yamada::ioImpl::EVAL_TAG{}; \ else return yamada::ioImpl::LL(); \ }(); #define IOIMPL_PROBE(...) ~, 1, #define IOIMPL_CHECK_N(_0, _1, ...) _1 #define IOIMPL_CHECK(...) IOIMPL_CHECK_N(__VA_ARGS__, 0) #define IOIMPL_IS_PAREN(x) IOIMPL_CHECK(IOIMPL_PROBE x) #define IOIMPL_UNPAREN(...) __VA_ARGS__ #define IOIMPL_STRIP_0(x) x #define IOIMPL_STRIP_1(x) IOIMPL_UNPAREN x #define IOIMPL_STRIP_IMPL(b,x) IOIMPL_STRIP_##b(x) #define IOIMPL_STRIP(b,x) IOIMPL_STRIP_IMPL(b,x) #define IOIMPL_NORMALIZE(x) IOIMPL_STRIP(IOIMPL_IS_PAREN(x),x) // ===== END INCLUDE: io-extension.hpp ===== // ===== BEGIN INCLUDE: ranges.hpp ===== namespace yamada { constexpr auto All = ranges::all_of; // of なし (Python に合わせている) constexpr auto Any = ranges::any_of; // 同上 constexpr auto BinarySearch = ranges::binary_search; constexpr auto Contains = ranges::contains; constexpr auto Copy = ranges::copy; constexpr auto Count = ranges::count; constexpr auto CountIf = ranges::count_if; constexpr auto Fill = ranges::fill; constexpr auto Find = ranges::find; constexpr auto FindIf = ranges::find_if; constexpr auto FoldLeft = ranges::fold_left; constexpr auto FoldRight = ranges::fold_right; constexpr auto IsSorted = ranges::is_sorted; constexpr auto IsSortedUntil = ranges::is_sorted_until; constexpr auto LowerBound = ranges::lower_bound; constexpr auto Max = ranges::max; constexpr auto MaxElement = ranges::max_element; constexpr auto Min = ranges::min; constexpr auto MinElement = ranges::min_element; constexpr auto MinMax = ranges::minmax; constexpr auto MinMaxElement = ranges::minmax_element; constexpr auto Reverse = ranges::reverse; constexpr auto Rotate = ranges::rotate; constexpr auto Sort = ranges::sort; constexpr auto UpperBound = ranges::upper_bound; template constexpr auto Adjacent = views::adjacent; constexpr auto Chunk = views::chunk; constexpr auto Drop = views::drop; constexpr auto DropWhile = views::drop_while; constexpr auto Enumerate = views::enumerate; constexpr auto Filter = views::filter; constexpr auto Join = views::join; constexpr auto Slide = views::slide; constexpr auto Stride = views::stride; constexpr auto Take = views::take; constexpr auto TakeWhile = views::take_while; constexpr auto Zip = views::zip; constexpr auto Rev = views::reverse; // ranges の方と混同しない constexpr auto Transform = views::transform; // ranges の方は多分使わない constexpr auto Iota = views::iota; // ranges の方は多分使わない constexpr auto rtov = ranges::to(); constexpr auto rtos = ranges::to(); using namespace placeholders; constexpr auto Ofs(const int K = 1) { return views::transform(bind(plus(), _1, K)); } } // namespace yamada // ===== END INCLUDE: ranges.hpp ===== // ===== BEGIN INCLUDE: macro.hpp ===== #define FORE1(x, v) for (auto&& x : v) #define FORE2(x, y, v) for (auto&& [x, y] : v) #define FORE3(x, y, z, v) for (auto&& [x, y, z] : v) #define FORE4(x, y, z, u, v) for (auto&& [x, y, z, u] : v) #define FORE5(x, y, z, t, u, v) for (auto&& [x, y, z, t, u] : v) #define FORE6(x, y, z, s, t, u, v) for (auto&& [x, y, z, s, t, u] : v) #define OVERLOAD7(a, b, c, d, e, f, g, h, ...) h #define each(...) OVERLOAD7(__VA_ARGS__, FORE6, FORE5, FORE4, FORE3, FORE2, FORE1)(__VA_ARGS__) #define FOR1(a) for (long long _ = 0; _ < (long long)(a); ++_) #define FOR2(i, a) for (long long i = 0; i < (long long)(a); ++i) #define FOR3(i, a, b) for (long long i = a; i < (long long)(b); ++i) #define FOR4(i, a, b, c) for (long long i = a; i < (long long)(b); i += c) #define OVERLOAD4(a, b, c, d, e, ...) e #define rep(...) OVERLOAD4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__) #define FOR_R1(a) for (long long i = (long long)(a)-1; i >= 0LL; --i) #define FOR_R2(i, a) for (long long i = (long long)(a)-1; i >= 0LL; --i) #define FOR_R3(i, a, b) for (long long i = (long long)(b)-1; i >= (long long)(a); --i) #define OVERLOAD3(a, b, c, d, ...) d #define repr(...) OVERLOAD3(__VA_ARGS__, FOR_R3, FOR_R2, FOR_R1)(__VA_ARGS__) #define eb emplace_back #define pb push_back #define fi first #define se second #define VV(type, name, h, ...) \ vector> name(h, vector(__VA_ARGS__)) #define VVV(type, name, h, w, ...) \ vector>> name( \ h, vector>(w, vector(__VA_ARGS__))) #define VVVV(type, name, a, b, c, ...) \ vector>>> name( \ a, vector>>( \ b, vector>(c, vector(__VA_ARGS__)))) #define DIE(...) do { yamada::out(__VA_ARGS__); return; } while (0) // ===== END INCLUDE: macro.hpp ===== namespace yamada { void solve(); } int main() { yamada::solve(); } // ===== END INCLUDE: ../../template/template.hpp ===== using namespace yamada; ll F(vint A){ ll ans=0; each(i,a,A|Enumerate)ans|=i&a; return ans; } map memo; vint cal(ll N,ll K){ if(memo.count(mkp(N,K)))return memo[mkp(N,K)]; if(N==1){ return memo[mkp(N,K)]={0}; } ll T=msb(N-1); ll n=N-(1<>T&1){ each(b,bns)ans.eb(b); return memo[mkp(N,K)]=ans; } else{ each(a,ans|Drop(n))bns.eb(a); each(a,ans|Take(n))bns.eb(a); return memo[mkp(N,K)]=bns; } } void yamada::solve() { IN(N,K); if(!YesNo(msb(N-1)>=msb(K)))return; fout(mkiota(N)); fout(cal(N,K)); assert(F(cal(N,K))==K); }