QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#550877#9249. Elimination Series Once Moreucup-team112#AC ✓756ms52376kbC++2033.4kb2024-09-07 14:33:032024-09-07 14:33:04

Judging History

你现在查看的是最新测评结果

  • [2024-09-07 14:33:04]
  • 评测
  • 测评结果:AC
  • 用时:756ms
  • 内存:52376kb
  • [2024-09-07 14:33:03]
  • 提交

answer


#ifndef ATCODER_INTERNAL_BITOP_HPP
#define ATCODER_INTERNAL_BITOP_HPP 1
#ifdef _MSC_VER
#include <intrin.h>
#endif
namespace atcoder {
namespace internal {
// @param n `0 <= n`
// @return minimum non-negative `x` s.t. `n <= 2**x`
int ceil_pow2(int n) {
    int x = 0;
    while ((1U << x) < (unsigned int)(n)) x++;
    return x;
}
// @param n `1 <= n`
// @return minimum non-negative `x` s.t. `(n & (1 << x)) != 0`
int bsf(unsigned int n) {
#ifdef _MSC_VER
    unsigned long index;
    _BitScanForward(&index, n);
    return index;
#else
    return __builtin_ctz(n);
#endif
}
}  // namespace internal
}  // namespace atcoder
#endif  // ATCODER_INTERNAL_BITOP_HPP
#ifndef ATCODER_INTERNAL_MATH_HPP
#define ATCODER_INTERNAL_MATH_HPP 1
#include <utility>
namespace atcoder {
namespace internal {
// @param m `1 <= m`
// @return x mod m
constexpr long long safe_mod(long long x, long long m) {
    x %= m;
    if (x < 0) x += m;
    return x;
}
// Fast moduler by barrett reduction
// Reference: https://en.wikipedia.org/wiki/Barrett_reduction
// NOTE: reconsider after Ice Lake
struct barrett {
    unsigned int _m;
    unsigned long long im;
    // @param m `1 <= m`
    barrett(unsigned int m) : _m(m), im((unsigned long long)(-1) / m + 1) {}
    // @return m
    unsigned int umod() const { return _m; }
    // @param a `0 <= a < m`
    // @param b `0 <= b < m`
    // @return `a * b % m`
    unsigned int mul(unsigned int a, unsigned int b) const {
        // [1] m = 1
        // a = b = im = 0, so okay
        // [2] m >= 2
        // im = ceil(2^64 / m)
        // -> im * m = 2^64 + r (0 <= r < m)
        // let z = a*b = c*m + d (0 <= c, d < m)
        // a*b * im = (c*m + d) * im = c*(im*m) + d*im = c*2^64 + c*r + d*im
        // c*r + d*im < m * m + m * im < m * m + 2^64 + m <= 2^64 + m * (m + 1) < 2^64 * 2
        // ((ab * im) >> 64) == c or c + 1
        unsigned long long z = a;
        z *= b;
#ifdef _MSC_VER
        unsigned long long x;
        _umul128(z, im, &x);
#else
        unsigned long long x =
            (unsigned long long)(((unsigned __int128)(z)*im) >> 64);
#endif
        unsigned int v = (unsigned int)(z - x * _m);
        if (_m <= v) v += _m;
        return v;
    }
};
// @param n `0 <= n`
// @param m `1 <= m`
// @return `(x ** n) % m`
constexpr long long pow_mod_constexpr(long long x, long long n, int m) {
    if (m == 1) return 0;
    unsigned int _m = (unsigned int)(m);
    unsigned long long r = 1;
    unsigned long long y = safe_mod(x, m);
    while (n) {
        if (n & 1) r = (r * y) % _m;
        y = (y * y) % _m;
        n >>= 1;
    }
    return r;
}
// Reference:
// M. Forisek and J. Jancina,
// Fast Primality Testing for Integers That Fit into a Machine Word
// @param n `0 <= n`
constexpr bool is_prime_constexpr(int n) {
    if (n <= 1) return false;
    if (n == 2 || n == 7 || n == 61) return true;
    if (n % 2 == 0) return false;
    long long d = n - 1;
    while (d % 2 == 0) d /= 2;
    for (long long a : {2, 7, 61}) {
        long long t = d;
        long long y = pow_mod_constexpr(a, t, n);
        while (t != n - 1 && y != 1 && y != n - 1) {
            y = y * y % n;
            t <<= 1;
        }
        if (y != n - 1 && t % 2 == 0) {
            return false;
        }
    }
    return true;
}
template <int n> constexpr bool is_prime = is_prime_constexpr(n);
// @param b `1 <= b`
// @return pair(g, x) s.t. g = gcd(a, b), xa = g (mod b), 0 <= x < b/g
constexpr std::pair<long long, long long> inv_gcd(long long a, long long b) {
    a = safe_mod(a, b);
    if (a == 0) return {b, 0};
    // Contracts:
    // [1] s - m0 * a = 0 (mod b)
    // [2] t - m1 * a = 0 (mod b)
    // [3] s * |m1| + t * |m0| <= b
    long long s = b, t = a;
    long long m0 = 0, m1 = 1;
    while (t) {
        long long u = s / t;
        s -= t * u;
        m0 -= m1 * u;  // |m1 * u| <= |m1| * s <= b
        // [3]:
        // (s - t * u) * |m1| + t * |m0 - m1 * u|
        // <= s * |m1| - t * u * |m1| + t * (|m0| + |m1| * u)
        // = s * |m1| + t * |m0| <= b
        auto tmp = s;
        s = t;
        t = tmp;
        tmp = m0;
        m0 = m1;
        m1 = tmp;
    }
    // by [3]: |m0| <= b/g
    // by g != b: |m0| < b/g
    if (m0 < 0) m0 += b / s;
    return {s, m0};
}
// Compile time primitive root
// @param m must be prime
// @return primitive root (and minimum in now)
constexpr int primitive_root_constexpr(int m) {
    if (m == 2) return 1;
    if (m == 167772161) return 3;
    if (m == 469762049) return 3;
    if (m == 754974721) return 11;
    if (m == 998244353) return 3;
    int divs[20] = {};
    divs[0] = 2;
    int cnt = 1;
    int x = (m - 1) / 2;
    while (x % 2 == 0) x /= 2;
    for (int i = 3; (long long)(i)*i <= x; i += 2) {
        if (x % i == 0) {
            divs[cnt++] = i;
            while (x % i == 0) {
                x /= i;
            }
        }
    }
    if (x > 1) {
        divs[cnt++] = x;
    }
    for (int g = 2;; g++) {
        bool ok = true;
        for (int i = 0; i < cnt; i++) {
            if (pow_mod_constexpr(g, (m - 1) / divs[i], m) == 1) {
                ok = false;
                break;
            }
        }
        if (ok) return g;
    }
}
template <int m> constexpr int primitive_root = primitive_root_constexpr(m);
}  // namespace internal
}  // namespace atcoder
#endif  // ATCODER_INTERNAL_MATH_HPP
#ifndef ATCODER_INTERNAL_QUEUE_HPP
#define ATCODER_INTERNAL_QUEUE_HPP 1
#include <vector>
namespace atcoder {
namespace internal {
template <class T> struct simple_queue {
    std::vector<T> payload;
    int pos = 0;
    void reserve(int n) { payload.reserve(n); }
    int size() const { return int(payload.size()) - pos; }
    bool empty() const { return pos == int(payload.size()); }
    void push(const T& t) { payload.push_back(t); }
    T& front() { return payload[pos]; }
    void clear() {
        payload.clear();
        pos = 0;
    }
    void pop() { pos++; }
};
}  // namespace internal
}  // namespace atcoder
#endif  // ATCODER_INTERNAL_QUEUE_HPP
#ifndef ATCODER_INTERNAL_SCC_HPP
#define ATCODER_INTERNAL_SCC_HPP 1
#include <algorithm>
#include <utility>
#include <vector>
namespace atcoder {
namespace internal {
template <class E> struct csr {
    std::vector<int> start;
    std::vector<E> elist;
    csr(int n, const std::vector<std::pair<int, E>>& edges)
        : start(n + 1), elist(edges.size()) {
        for (auto e : edges) {
            start[e.first + 1]++;
        }
        for (int i = 1; i <= n; i++) {
            start[i] += start[i - 1];
        }
        auto counter = start;
        for (auto e : edges) {
            elist[counter[e.first]++] = e.second;
        }
    }
};
// Reference:
// R. Tarjan,
// Depth-First Search and Linear Graph Algorithms
struct scc_graph {
  public:
    scc_graph(int n) : _n(n) {}
    int num_vertices() { return _n; }
    void add_edge(int from, int to) { edges.push_back({from, {to}}); }
    // @return pair of (# of scc, scc id)
    std::pair<int, std::vector<int>> scc_ids() {
        auto g = csr<edge>(_n, edges);
        int now_ord = 0, group_num = 0;
        std::vector<int> visited, low(_n), ord(_n, -1), ids(_n);
        visited.reserve(_n);
        auto dfs = [&](auto self, int v) -> void {
            low[v] = ord[v] = now_ord++;
            visited.push_back(v);
            for (int i = g.start[v]; i < g.start[v + 1]; i++) {
                auto to = g.elist[i].to;
                if (ord[to] == -1) {
                    self(self, to);
                    low[v] = std::min(low[v], low[to]);
                } else {
                    low[v] = std::min(low[v], ord[to]);
                }
            }
            if (low[v] == ord[v]) {
                while (true) {
                    int u = visited.back();
                    visited.pop_back();
                    ord[u] = _n;
                    ids[u] = group_num;
                    if (u == v) break;
                }
                group_num++;
            }
        };
        for (int i = 0; i < _n; i++) {
            if (ord[i] == -1) dfs(dfs, i);
        }
        for (auto& x : ids) {
            x = group_num - 1 - x;
        }
        return {group_num, ids};
    }
    std::vector<std::vector<int>> scc() {
        auto ids = scc_ids();
        int group_num = ids.first;
        std::vector<int> counts(group_num);
        for (auto x : ids.second) counts[x]++;
        std::vector<std::vector<int>> groups(ids.first);
        for (int i = 0; i < group_num; i++) {
            groups[i].reserve(counts[i]);
        }
        for (int i = 0; i < _n; i++) {
            groups[ids.second[i]].push_back(i);
        }
        return groups;
    }
  private:
    int _n;
    struct edge {
        int to;
    };
    std::vector<std::pair<int, edge>> edges;
};
}  // namespace internal
}  // namespace atcoder
#endif  // ATCODER_INTERNAL_SCC_HPP
#ifndef ATCODER_INTERNAL_TYPE_TRAITS_HPP
#define ATCODER_INTERNAL_TYPE_TRAITS_HPP 1
#include <cassert>
#include <numeric>
#include <type_traits>
namespace atcoder {
namespace internal {
#ifndef _MSC_VER
template <class T>
using is_signed_int128 =
    typename std::conditional<std::is_same<T, __int128_t>::value ||
                                  std::is_same<T, __int128>::value,
                              std::true_type,
                              std::false_type>::type;
template <class T>
using is_unsigned_int128 =
    typename std::conditional<std::is_same<T, __uint128_t>::value ||
                                  std::is_same<T, unsigned __int128>::value,
                              std::true_type,
                              std::false_type>::type;
template <class T>
using make_unsigned_int128 =
    typename std::conditional<std::is_same<T, __int128_t>::value,
                              __uint128_t,
                              unsigned __int128>;
template <class T>
using is_integral = typename std::conditional<std::is_integral<T>::value ||
                                                  is_signed_int128<T>::value ||
                                                  is_unsigned_int128<T>::value,
                                              std::true_type,
                                              std::false_type>::type;
template <class T>
using is_signed_int = typename std::conditional<(is_integral<T>::value &&
                                                 std::is_signed<T>::value) ||
                                                    is_signed_int128<T>::value,
                                                std::true_type,
                                                std::false_type>::type;
template <class T>
using is_unsigned_int =
    typename std::conditional<(is_integral<T>::value &&
                               std::is_unsigned<T>::value) ||
                                  is_unsigned_int128<T>::value,
                              std::true_type,
                              std::false_type>::type;
template <class T>
using to_unsigned = typename std::conditional<
    is_signed_int128<T>::value,
    make_unsigned_int128<T>,
    typename std::conditional<std::is_signed<T>::value,
                              std::make_unsigned<T>,
                              std::common_type<T>>::type>::type;
#else
template <class T> using is_integral = typename std::is_integral<T>;
template <class T>
using is_signed_int =
    typename std::conditional<is_integral<T>::value && std::is_signed<T>::value,
                              std::true_type,
                              std::false_type>::type;
template <class T>
using is_unsigned_int =
    typename std::conditional<is_integral<T>::value &&
                                  std::is_unsigned<T>::value,
                              std::true_type,
                              std::false_type>::type;
template <class T>
using to_unsigned = typename std::conditional<is_signed_int<T>::value,
                                              std::make_unsigned<T>,
                                              std::common_type<T>>::type;
#endif
template <class T>
using is_signed_int_t = std::enable_if_t<is_signed_int<T>::value>;
template <class T>
using is_unsigned_int_t = std::enable_if_t<is_unsigned_int<T>::value>;
template <class T> using to_unsigned_t = typename to_unsigned<T>::type;
}  // namespace internal
}  // namespace atcoder
#endif  // ATCODER_INTERNAL_TYPE_TRAITS_HPP
#ifndef ATCODER_MODINT_HPP
#define ATCODER_MODINT_HPP 1
#include <cassert>
#include <numeric>
#include <type_traits>
#ifdef _MSC_VER
#include <intrin.h>
#endif
namespace atcoder {
namespace internal {
struct modint_base {};
struct static_modint_base : modint_base {};
template <class T> using is_modint = std::is_base_of<modint_base, T>;
template <class T> using is_modint_t = std::enable_if_t<is_modint<T>::value>;
}  // namespace internal
template <int m, std::enable_if_t<(1 <= m)>* = nullptr>
struct static_modint : internal::static_modint_base {
    using mint = static_modint;
  public:
    static constexpr int mod() { return m; }
    static mint raw(int v) {
        mint x;
        x._v = v;
        return x;
    }
    static_modint() : _v(0) {}
    template <class T, internal::is_signed_int_t<T>* = nullptr>
    static_modint(T v) {
        long long x = (long long)(v % (long long)(umod()));
        if (x < 0) x += umod();
        _v = (unsigned int)(x);
    }
    template <class T, internal::is_unsigned_int_t<T>* = nullptr>
    static_modint(T v) {
        _v = (unsigned int)(v % umod());
    }
    static_modint(bool v) { _v = ((unsigned int)(v) % umod()); }
    unsigned int val() const { return _v; }
    mint& operator++() {
        _v++;
        if (_v == umod()) _v = 0;
        return *this;
    }
    mint& operator--() {
        if (_v == 0) _v = umod();
        _v--;
        return *this;
    }
    mint operator++(int) {
        mint result = *this;
        ++*this;
        return result;
    }
    mint operator--(int) {
        mint result = *this;
        --*this;
        return result;
    }
    mint& operator+=(const mint& rhs) {
        _v += rhs._v;
        if (_v >= umod()) _v -= umod();
        return *this;
    }
    mint& operator-=(const mint& rhs) {
        _v -= rhs._v;
        if (_v >= umod()) _v += umod();
        return *this;
    }
    mint& operator*=(const mint& rhs) {
        unsigned long long z = _v;
        z *= rhs._v;
        _v = (unsigned int)(z % umod());
        return *this;
    }
    mint& operator/=(const mint& rhs) { return *this = *this * rhs.inv(); }
    mint operator+() const { return *this; }
    mint operator-() const { return mint() - *this; }
    mint pow(long long n) const {
        assert(0 <= n);
        mint x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    mint inv() const {
        if (prime) {
            assert(_v);
            return pow(umod() - 2);
        } else {
            auto eg = internal::inv_gcd(_v, m);
            assert(eg.first == 1);
            return eg.second;
        }
    }
    friend mint operator+(const mint& lhs, const mint& rhs) {
        return mint(lhs) += rhs;
    }
    friend mint operator-(const mint& lhs, const mint& rhs) {
        return mint(lhs) -= rhs;
    }
    friend mint operator*(const mint& lhs, const mint& rhs) {
        return mint(lhs) *= rhs;
    }
    friend mint operator/(const mint& lhs, const mint& rhs) {
        return mint(lhs) /= rhs;
    }
    friend bool operator==(const mint& lhs, const mint& rhs) {
        return lhs._v == rhs._v;
    }
    friend bool operator!=(const mint& lhs, const mint& rhs) {
        return lhs._v != rhs._v;
    }
  private:
    unsigned int _v;
    static constexpr unsigned int umod() { return m; }
    static constexpr bool prime = internal::is_prime<m>;
};
template <int id> struct dynamic_modint : internal::modint_base {
    using mint = dynamic_modint;
  public:
    static int mod() { return (int)(bt.umod()); }
    static void set_mod(int m) {
        assert(1 <= m);
        bt = internal::barrett(m);
    }
    static mint raw(int v) {
        mint x;
        x._v = v;
        return x;
    }
    dynamic_modint() : _v(0) {}
    template <class T, internal::is_signed_int_t<T>* = nullptr>
    dynamic_modint(T v) {
        long long x = (long long)(v % (long long)(mod()));
        if (x < 0) x += mod();
        _v = (unsigned int)(x);
    }
    template <class T, internal::is_unsigned_int_t<T>* = nullptr>
    dynamic_modint(T v) {
        _v = (unsigned int)(v % mod());
    }
    dynamic_modint(bool v) { _v = ((unsigned int)(v) % mod()); }
    unsigned int val() const { return _v; }
    mint& operator++() {
        _v++;
        if (_v == umod()) _v = 0;
        return *this;
    }
    mint& operator--() {
        if (_v == 0) _v = umod();
        _v--;
        return *this;
    }
    mint operator++(int) {
        mint result = *this;
        ++*this;
        return result;
    }
    mint operator--(int) {
        mint result = *this;
        --*this;
        return result;
    }
    mint& operator+=(const mint& rhs) {
        _v += rhs._v;
        if (_v >= umod()) _v -= umod();
        return *this;
    }
    mint& operator-=(const mint& rhs) {
        _v += mod() - rhs._v;
        if (_v >= umod()) _v -= umod();
        return *this;
    }
    mint& operator*=(const mint& rhs) {
        _v = bt.mul(_v, rhs._v);
        return *this;
    }
    mint& operator/=(const mint& rhs) { return *this = *this * rhs.inv(); }
    mint operator+() const { return *this; }
    mint operator-() const { return mint() - *this; }
    mint pow(long long n) const {
        assert(0 <= n);
        mint x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    mint inv() const {
        auto eg = internal::inv_gcd(_v, mod());
        assert(eg.first == 1);
        return eg.second;
    }
    friend mint operator+(const mint& lhs, const mint& rhs) {
        return mint(lhs) += rhs;
    }
    friend mint operator-(const mint& lhs, const mint& rhs) {
        return mint(lhs) -= rhs;
    }
    friend mint operator*(const mint& lhs, const mint& rhs) {
        return mint(lhs) *= rhs;
    }
    friend mint operator/(const mint& lhs, const mint& rhs) {
        return mint(lhs) /= rhs;
    }
    friend bool operator==(const mint& lhs, const mint& rhs) {
        return lhs._v == rhs._v;
    }
    friend bool operator!=(const mint& lhs, const mint& rhs) {
        return lhs._v != rhs._v;
    }
  private:
    unsigned int _v;
    static internal::barrett bt;
    static unsigned int umod() { return bt.umod(); }
};
template <int id> internal::barrett dynamic_modint<id>::bt = 998244353;
using modint998244353 = static_modint<998244353>;
using modint1000000007 = static_modint<1000000007>;
using modint = dynamic_modint<-1>;
namespace internal {
template <class T>
using is_static_modint = std::is_base_of<internal::static_modint_base, T>;
template <class T>
using is_static_modint_t = std::enable_if_t<is_static_modint<T>::value>;
template <class> struct is_dynamic_modint : public std::false_type {};
template <int id>
struct is_dynamic_modint<dynamic_modint<id>> : public std::true_type {};
template <class T>
using is_dynamic_modint_t = std::enable_if_t<is_dynamic_modint<T>::value>;
}  // namespace internal
}  // namespace atcoder
#endif  // ATCODER_MODINT_HPP
#ifndef ATCODER_CONVOLUTION_HPP
#define ATCODER_CONVOLUTION_HPP 1
#include <algorithm>
#include <array>
#include <cassert>
#include <type_traits>
#include <vector>
namespace atcoder {
namespace internal {
template <class mint, internal::is_static_modint_t<mint>* = nullptr>
void butterfly(std::vector<mint>& a) {
    static constexpr int g = internal::primitive_root<mint::mod()>;
    int n = int(a.size());
    int h = internal::ceil_pow2(n);
    static bool first = true;
    static mint sum_e[30];  // sum_e[i] = ies[0] * ... * ies[i - 1] * es[i]
    if (first) {
        first = false;
        mint es[30], ies[30];  // es[i]^(2^(2+i)) == 1
        int cnt2 = bsf(mint::mod() - 1);
        mint e = mint(g).pow((mint::mod() - 1) >> cnt2), ie = e.inv();
        for (int i = cnt2; i >= 2; i--) {
            // e^(2^i) == 1
            es[i - 2] = e;
            ies[i - 2] = ie;
            e *= e;
            ie *= ie;
        }
        mint now = 1;
        for (int i = 0; i < cnt2 - 2; i++) {
            sum_e[i] = es[i] * now;
            now *= ies[i];
        }
    }
    for (int ph = 1; ph <= h; ph++) {
        int w = 1 << (ph - 1), p = 1 << (h - ph);
        mint now = 1;
        for (int s = 0; s < w; s++) {
            int offset = s << (h - ph + 1);
            for (int i = 0; i < p; i++) {
                auto l = a[i + offset];
                auto r = a[i + offset + p] * now;
                a[i + offset] = l + r;
                a[i + offset + p] = l - r;
            }
            now *= sum_e[bsf(~(unsigned int)(s))];
        }
    }
}
template <class mint, internal::is_static_modint_t<mint>* = nullptr>
void butterfly_inv(std::vector<mint>& a) {
    static constexpr int g = internal::primitive_root<mint::mod()>;
    int n = int(a.size());
    int h = internal::ceil_pow2(n);
    static bool first = true;
    static mint sum_ie[30];  // sum_ie[i] = es[0] * ... * es[i - 1] * ies[i]
    if (first) {
        first = false;
        mint es[30], ies[30];  // es[i]^(2^(2+i)) == 1
        int cnt2 = bsf(mint::mod() - 1);
        mint e = mint(g).pow((mint::mod() - 1) >> cnt2), ie = e.inv();
        for (int i = cnt2; i >= 2; i--) {
            // e^(2^i) == 1
            es[i - 2] = e;
            ies[i - 2] = ie;
            e *= e;
            ie *= ie;
        }
        mint now = 1;
        for (int i = 0; i < cnt2 - 2; i++) {
            sum_ie[i] = ies[i] * now;
            now *= es[i];
        }
    }
    for (int ph = h; ph >= 1; ph--) {
        int w = 1 << (ph - 1), p = 1 << (h - ph);
        mint inow = 1;
        for (int s = 0; s < w; s++) {
            int offset = s << (h - ph + 1);
            for (int i = 0; i < p; i++) {
                auto l = a[i + offset];
                auto r = a[i + offset + p];
                a[i + offset] = l + r;
                a[i + offset + p] =
                    (unsigned long long)(mint::mod() + l.val() - r.val()) *
                    inow.val();
            }
            inow *= sum_ie[bsf(~(unsigned int)(s))];
        }
    }
}
}  // namespace internal
template <class mint, internal::is_static_modint_t<mint>* = nullptr>
std::vector<mint> convolution(std::vector<mint> a, std::vector<mint> b) {
    int n = int(a.size()), m = int(b.size());
    if (!n || !m) return {};
    if (std::min(n, m) <= 60) {
        if (n < m) {
            std::swap(n, m);
            std::swap(a, b);
        }
        std::vector<mint> ans(n + m - 1);
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                ans[i + j] += a[i] * b[j];
            }
        }
        return ans;
    }
    int z = 1 << internal::ceil_pow2(n + m - 1);
    a.resize(z);
    internal::butterfly(a);
    b.resize(z);
    internal::butterfly(b);
    for (int i = 0; i < z; i++) {
        a[i] *= b[i];
    }
    internal::butterfly_inv(a);
    a.resize(n + m - 1);
    mint iz = mint(z).inv();
    for (int i = 0; i < n + m - 1; i++) a[i] *= iz;
    return a;
}
template <unsigned int mod = 998244353,
          class T,
          std::enable_if_t<internal::is_integral<T>::value>* = nullptr>
std::vector<T> convolution(const std::vector<T>& a, const std::vector<T>& b) {
    int n = int(a.size()), m = int(b.size());
    if (!n || !m) return {};
    using mint = static_modint<mod>;
    std::vector<mint> a2(n), b2(m);
    for (int i = 0; i < n; i++) {
        a2[i] = mint(a[i]);
    }
    for (int i = 0; i < m; i++) {
        b2[i] = mint(b[i]);
    }
    auto c2 = convolution(move(a2), move(b2));
    std::vector<T> c(n + m - 1);
    for (int i = 0; i < n + m - 1; i++) {
        c[i] = c2[i].val();
    }
    return c;
}
std::vector<long long> convolution_ll(const std::vector<long long>& a,
                                      const std::vector<long long>& b) {
    int n = int(a.size()), m = int(b.size());
    if (!n || !m) return {};
    static constexpr unsigned long long MOD1 = 754974721;  // 2^24
    static constexpr unsigned long long MOD2 = 167772161;  // 2^25
    static constexpr unsigned long long MOD3 = 469762049;  // 2^26
    static constexpr unsigned long long M2M3 = MOD2 * MOD3;
    static constexpr unsigned long long M1M3 = MOD1 * MOD3;
    static constexpr unsigned long long M1M2 = MOD1 * MOD2;
    static constexpr unsigned long long M1M2M3 = MOD1 * MOD2 * MOD3;
    static constexpr unsigned long long i1 =
        internal::inv_gcd(MOD2 * MOD3, MOD1).second;
    static constexpr unsigned long long i2 =
        internal::inv_gcd(MOD1 * MOD3, MOD2).second;
    static constexpr unsigned long long i3 =
        internal::inv_gcd(MOD1 * MOD2, MOD3).second;
    auto c1 = convolution<MOD1>(a, b);
    auto c2 = convolution<MOD2>(a, b);
    auto c3 = convolution<MOD3>(a, b);
    std::vector<long long> c(n + m - 1);
    for (int i = 0; i < n + m - 1; i++) {
        unsigned long long x = 0;
        x += (c1[i] * i1) % MOD1 * M2M3;
        x += (c2[i] * i2) % MOD2 * M1M3;
        x += (c3[i] * i3) % MOD3 * M1M2;
        // B = 2^63, -B <= x, r(real value) < B
        // (x, x - M, x - 2M, or x - 3M) = r (mod 2B)
        // r = c1[i] (mod MOD1)
        // focus on MOD1
        // r = x, x - M', x - 2M', x - 3M' (M' = M % 2^64) (mod 2B)
        // r = x,
        //     x - M' + (0 or 2B),
        //     x - 2M' + (0, 2B or 4B),
        //     x - 3M' + (0, 2B, 4B or 6B) (without mod!)
        // (r - x) = 0, (0)
        //           - M' + (0 or 2B), (1)
        //           -2M' + (0 or 2B or 4B), (2)
        //           -3M' + (0 or 2B or 4B or 6B) (3) (mod MOD1)
        // we checked that
        //   ((1) mod MOD1) mod 5 = 2
        //   ((2) mod MOD1) mod 5 = 3
        //   ((3) mod MOD1) mod 5 = 4
        long long diff =
            c1[i] - internal::safe_mod((long long)(x), (long long)(MOD1));
        if (diff < 0) diff += MOD1;
        static constexpr unsigned long long offset[5] = {
            0, 0, M1M2M3, 2 * M1M2M3, 3 * M1M2M3};
        x -= offset[diff % 5];
        c[i] = x;
    }
    return c;
}
}  // namespace atcoder
#endif  // ATCODER_CONVOLUTION_HPP

#ifndef ATCODER_SEGTREE_HPP
#define ATCODER_SEGTREE_HPP 1
#include <algorithm>
#include <cassert>
#include <vector>
namespace atcoder {
template <class S, S (*op)(S, S), S (*e)()> struct segtree {
  public:
    segtree() : segtree(0) {}
    segtree(int n) : segtree(std::vector<S>(n, e())) {}
    segtree(const std::vector<S>& v) : _n(int(v.size())) {
        log = internal::ceil_pow2(_n);
        size = 1 << log;
        d = std::vector<S>(2 * size, e());
        for (int i = 0; i < _n; i++) d[size + i] = v[i];
        for (int i = size - 1; i >= 1; i--) {
            update(i);
        }
    }
    void set(int p, S x) {
        assert(0 <= p && p < _n);
        p += size;
        d[p] = x;
        for (int i = 1; i <= log; i++) update(p >> i);
    }
    S get(int p) {
        assert(0 <= p && p < _n);
        return d[p + size];
    }
    S prod(int l, int r) {
        assert(0 <= l && l <= r && r <= _n);
        S sml = e(), smr = e();
        l += size;
        r += size;
        while (l < r) {
            if (l & 1) sml = op(sml, d[l++]);
            if (r & 1) smr = op(d[--r], smr);
            l >>= 1;
            r >>= 1;
        }
        return op(sml, smr);
    }
    S all_prod() { return d[1]; }
    template <bool (*f)(S)> int max_right(int l) {
        return max_right(l, [](S x) { return f(x); });
    }
    template <class F> int max_right(int l, F f) {
        assert(0 <= l && l <= _n);
        assert(f(e()));
        if (l == _n) return _n;
        l += size;
        S sm = e();
        do {
            while (l % 2 == 0) l >>= 1;
            if (!f(op(sm, d[l]))) {
                while (l < size) {
                    l = (2 * l);
                    if (f(op(sm, d[l]))) {
                        sm = op(sm, d[l]);
                        l++;
                    }
                }
                return l - size;
            }
            sm = op(sm, d[l]);
            l++;
        } while ((l & -l) != l);
        return _n;
    }
    template <bool (*f)(S)> int min_left(int r) {
        return min_left(r, [](S x) { return f(x); });
    }
    template <class F> int min_left(int r, F f) {
        assert(0 <= r && r <= _n);
        assert(f(e()));
        if (r == 0) return 0;
        r += size;
        S sm = e();
        do {
            r--;
            while (r > 1 && (r % 2)) r >>= 1;
            if (!f(op(d[r], sm))) {
                while (r < size) {
                    r = (2 * r + 1);
                    if (f(op(d[r], sm))) {
                        sm = op(d[r], sm);
                        r--;
                    }
                }
                return r + 1 - size;
            }
            sm = op(d[r], sm);
        } while ((r & -r) != r);
        return 0;
    }
  private:
    int _n, size, log;
    std::vector<S> d;
    void update(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); }
};
}  // namespace atcoder
#endif  // ATCODER_SEGTREE_HPP

#include <bits/stdc++.h>
#include <iostream>
#include <limits>
#include <numeric>
#include <type_traits>
#include <bitset>
#include <map>
#include <unordered_map>
#include <set>
#include <random>

using namespace atcoder;
using namespace std;
using ll = long long;

#define rep(i,n,m) for(ll (i)=(n);(i)<(m);(i)++)
#define rrep(i,n,m) for(ll (i)=(n);(i)>(m);(i)--)
const ll mod = 998244353;
const ll inf = 1e18;
const ll INF = 4e18+10;

using mint = modint998244353;
using pll = pair<ll,ll>;

void pline(vector<int> lis){
    rep(i,0,lis.size()){
        printf ("%d",lis[i]);
        if (i != lis.size()-1) printf(" ");
        else printf("\n");
    }
}

void pline(vector<ll> lis){
    rep(i,0,lis.size()){
        printf ("%lld",lis[i]);
        if (i != lis.size()-1) printf(" ");
        else printf("\n");
    }
}

void pline(vector<mint> lis){
    rep(i,0,lis.size()){
        printf ("%d",lis[i].val());
        if (i != lis.size()-1) printf(" ");
        else printf("\n");
    }
}

void pline2(vector<ll> lis){
    rep(i,0,lis.size()){
        printf ("%lld",lis[i]);
        if (i != lis.size()-1) printf("");
        else printf("\n");
    }
}

void pline(vector<pair<ll,ll>> lis){
    rep(i,0,lis.size()){
        printf ("/%lld,%lld/",lis[i].first,lis[i].second);
        if (i != lis.size()-1) printf(" ");
        else printf("\n");
    }
}

vector<ll> Sieve(ll n,ll mode = 0){

    vector<ll> plis(0);
    vector<ll> divlis(n+1,-1);
    vector<ll> flag(n+1,1);

    flag[0] = 0;
    flag[1] = 0;

    ll ind = 2;

    while (ind <= n){

        if (flag[ind]){
            plis.push_back(ind);

            ll ind2 = ind*ind;

            while (ind2 <= n){
                flag[ind2] = 0;
                divlis[ind2] = ind;
                ind2 += ind;
            }
        }

        ind += 1;
    }

    if (mode == 0){
        return plis;
    }else{
        return divlis;
    }

}

struct ModFac{
    private:
        int n;
        vector<mint> facs,invs;

    public:
        ModFac(int x){
            n = x;
            facs.resize(n+1);
            invs.resize(n+1);

            mint f = 1;
            facs[0] = f;
            for (int i = 1 ; i < n+1 ; i++){
                f *= i;
                facs[i] = f;
            }

            mint g = f.inv();
            invs[n] = g ; invs[0] = 1;
            for (int i = n; i > 1 ; i--){
                g *= i;
                invs[i-1] = g;
            }
        }

        mint getfac(int n){
            return facs[n];
        }

        mint getinv(int n){
            return invs[n];
        }

        mint nCr(int n,int r){
            return facs[n] * invs[n-r] * invs[r];
        }
};

ll op(ll l,ll r){
    return l + r;
}

ll e(){
    return 0LL;
}

int main() {

    ll n,k;
    cin >> n >> k;

    vector<ll> a(1<<n);
    vector<ll> arev(1<<n);
    rep(i,0,(1<<n)){
        cin >> a[i];
        a[i] -= 1;
        arev[a[i]] = i;
    }

    vector<ll> ans(1<<n);
    segtree<ll,op,e> seg(1<<n);

    rep(power,0,(1<<n)){

        ll idx = arev[power];
        seg.set( idx , 1 );

        ll L = min(idx^1 , idx);

        ll nans = 0;
        rep(j,0,n){

            ll newL = min( L ^ (1<<j) , L );
            ll newR = newL + (1<<(j+1));
            ll cnt = newR-newL;

            // cerr << newL << idx << newR << " " << cnt << " " << cnt - seg.prod(newL,newR) <<  endl;

            if (cnt <= power+1 && cnt - seg.prod(newL,newR) <= k ){
                nans += 1;
            }else{
                break;
            }
            L = newL;
        }

        ans[idx] = nans;

    }

    pline(ans);

}

/*

000 001 010 011

*/

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3684kb

input:

2 1
1 2 3 4

output:

0 1 1 2

result:

ok 4 number(s): "0 1 1 2"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3816kb

input:

3 5
2 4 7 5 3 8 6 1

output:

1 2 2 2 1 3 2 0

result:

ok 8 numbers

Test #3:

score: 0
Accepted
time: 0ms
memory: 3816kb

input:

3 0
1 2 7 4 5 8 3 6

output:

0 1 2 0 0 3 0 1

result:

ok 8 numbers

Test #4:

score: 0
Accepted
time: 0ms
memory: 3708kb

input:

3 5
3 7 1 2 4 8 5 6

output:

1 2 0 1 2 3 2 2

result:

ok 8 numbers

Test #5:

score: 0
Accepted
time: 0ms
memory: 3816kb

input:

3 3
3 4 8 2 7 6 1 5

output:

1 2 3 1 2 2 0 2

result:

ok 8 numbers

Test #6:

score: 0
Accepted
time: 0ms
memory: 3792kb

input:

3 3
4 2 6 8 3 5 1 7

output:

2 1 2 3 1 2 0 2

result:

ok 8 numbers

Test #7:

score: 0
Accepted
time: 0ms
memory: 3808kb

input:

3 4
5 8 1 3 2 4 6 7

output:

2 3 0 1 1 2 2 2

result:

ok 8 numbers

Test #8:

score: 0
Accepted
time: 0ms
memory: 4092kb

input:

3 1
7 3 8 6 5 2 4 1

output:

2 1 3 1 2 1 2 0

result:

ok 8 numbers

Test #9:

score: 0
Accepted
time: 0ms
memory: 3720kb

input:

3 4
1 2 5 3 6 7 4 8

output:

0 1 2 1 2 2 2 3

result:

ok 8 numbers

Test #10:

score: 0
Accepted
time: 0ms
memory: 3752kb

input:

3 2
2 4 8 6 3 7 5 1

output:

1 2 3 2 1 2 2 0

result:

ok 8 numbers

Test #11:

score: 0
Accepted
time: 1ms
memory: 4140kb

input:

10 780
495 929 348 345 426 543 187 419 839 812 320 1018 251 284 944 258 721 640 730 528 316 247 313 195 809 948 261 615 805 213 388 894 1005 77 599 636 881 444 144 923 240 520 592 465 96 455 563 943 237 860 531 269 106 989 740 506 23 224 84 475 108 718 3 16 731 436 591 627 672 300 573 613 253 637 46...

output:

8 9 8 8 8 9 7 8 9 9 8 9 7 8 9 8 9 9 9 9 8 7 8 7 9 9 8 9 9 7 8 9 9 6 9 9 9 8 7 9 7 9 9 8 6 8 9 9 7 9 9 8 6 9 9 8 4 7 6 8 6 9 1 4 9 8 9 9 9 8 9 9 7 9 8 9 9 9 6 7 6 7 9 9 9 9 9 7 6 8 8 8 9 9 6 6 9 9 9 8 9 9 6 9 9 8 6 7 8 8 3 8 8 9 6 9 7 8 8 9 9 9 9 8 7 9 8 8 7 7 9 9 9 9 9 8 8 9 6 9 9 9 9 9 9 6 9 8 8 9 ...

result:

ok 1024 numbers

Test #12:

score: 0
Accepted
time: 1ms
memory: 3828kb

input:

10 175
10 301 861 580 539 53 822 97 923 133 952 870 438 265 55 825 557 784 976 584 993 897 981 259 875 18 106 399 1019 692 336 485 491 9 565 114 738 128 678 23 562 538 869 787 768 385 494 640 655 666 332 930 798 418 801 266 1009 846 54 37 967 139 394 802 168 503 233 848 340 329 240 898 251 1023 779 ...

output:

3 7 9 8 8 5 9 6 9 7 9 9 8 7 5 9 8 9 9 8 9 9 9 7 9 4 6 8 9 9 8 8 8 3 8 6 9 7 9 4 8 8 9 9 9 8 8 8 8 8 8 9 9 8 9 7 9 9 5 5 9 7 8 9 7 8 7 9 8 8 7 9 7 9 9 9 8 8 9 9 8 7 9 7 8 6 8 5 5 9 9 7 8 9 6 5 8 9 8 5 7 8 9 7 6 9 8 9 8 2 6 9 8 9 9 8 8 5 9 8 9 7 9 9 9 6 9 9 7 10 9 8 9 9 9 7 8 7 8 8 8 6 7 6 7 4 8 9 9 8...

result:

ok 1024 numbers

Test #13:

score: 0
Accepted
time: 1ms
memory: 3856kb

input:

10 15
829 331 590 799 39 456 888 779 60 411 796 148 678 930 101 653 81 429 4 457 455 703 780 260 251 21 291 122 366 177 665 326 114 96 445 123 154 340 522 113 895 170 144 857 447 865 874 891 679 541 867 731 436 219 871 596 285 1008 435 263 881 798 16 275 14 97 845 269 974 782 343 404 561 540 443 482...

output:

6 4 5 6 4 5 7 5 4 4 6 4 5 7 4 5 4 5 2 5 5 5 6 4 4 4 4 4 4 4 5 4 4 4 4 4 4 4 5 4 7 4 4 6 5 6 7 7 5 5 6 5 4 4 6 5 4 9 4 4 7 6 4 4 3 4 6 4 8 6 4 4 5 5 4 5 7 7 4 4 4 4 4 5 9 4 4 7 5 8 4 4 6 4 6 9 6 4 8 5 5 4 4 4 5 4 5 5 4 4 4 4 5 4 5 5 4 5 4 4 5 4 4 6 4 9 5 6 8 6 5 6 6 7 4 4 4 4 4 4 4 3 4 4 4 4 6 7 7 5 ...

result:

ok 1024 numbers

Test #14:

score: 0
Accepted
time: 1ms
memory: 3776kb

input:

10 215
910 367 1011 675 689 697 604 665 730 306 743 225 210 1008 546 439 411 475 529 640 54 505 420 481 213 406 1012 933 392 121 751 554 265 550 621 537 212 908 49 918 768 125 16 927 507 863 1000 44 900 7 645 543 784 461 569 669 984 249 189 727 497 994 719 282 666 691 58 795 119 515 682 150 53 494 6...

output:

9 8 9 9 9 9 9 9 9 8 9 7 7 9 8 8 8 8 8 9 5 8 8 8 7 8 9 9 8 6 9 8 8 8 9 8 7 9 5 9 9 6 4 9 8 9 9 5 9 2 9 8 9 8 8 9 9 7 7 9 8 9 9 8 9 9 5 9 6 8 9 7 5 8 9 8 9 9 7 9 8 9 9 9 8 9 7 5 8 7 9 8 8 6 9 9 8 6 5 9 8 8 9 8 7 9 9 8 6 4 9 6 9 8 8 9 7 8 9 8 5 8 8 9 8 9 8 9 9 8 8 7 5 9 9 9 9 9 8 8 9 9 6 8 6 8 6 9 9 9 ...

result:

ok 1024 numbers

Test #15:

score: 0
Accepted
time: 1ms
memory: 4072kb

input:

10 358
714 252 544 999 507 766 720 169 379 856 698 40 910 610 564 125 278 426 285 205 746 43 23 284 81 525 848 540 827 604 630 741 27 313 452 724 9 745 762 263 44 901 864 445 418 596 310 719 988 536 799 625 202 895 412 153 847 145 353 297 133 260 717 893 158 314 90 356 108 315 1016 510 1015 1007 747...

output:

9 7 9 9 8 9 9 7 8 9 9 5 9 9 9 6 8 8 8 7 9 5 4 8 6 9 9 9 9 9 9 9 4 8 8 9 3 9 9 8 5 9 9 8 8 9 8 9 9 9 9 9 7 9 8 7 9 7 8 8 7 8 9 9 7 8 6 8 6 8 9 8 9 9 9 7 9 9 7 9 6 9 9 7 8 7 9 7 8 7 9 9 7 9 9 4 8 9 8 9 9 9 7 9 6 9 8 9 9 9 8 9 9 9 8 3 8 9 4 7 8 8 8 8 8 8 9 6 8 6 9 7 9 9 8 7 9 9 9 9 7 8 9 8 9 8 9 7 8 9 ...

result:

ok 1024 numbers

Test #16:

score: 0
Accepted
time: 0ms
memory: 3776kb

input:

10 409
720 603 348 938 361 756 506 176 661 192 318 599 115 548 681 692 915 148 721 93 424 707 404 392 695 342 247 799 743 814 82 120 365 428 461 355 184 372 224 810 225 569 630 800 480 226 802 867 136 592 723 412 248 619 817 67 891 72 74 315 624 250 1001 73 536 397 859 553 647 143 575 733 468 298 71...

output:

9 9 8 9 8 9 8 7 9 7 8 9 6 9 9 9 9 7 9 6 8 9 8 8 9 8 7 9 9 9 6 6 8 8 8 8 7 8 7 9 7 9 9 9 8 7 9 9 7 9 9 8 7 9 9 6 9 6 6 8 9 7 9 6 9 8 9 9 9 7 9 9 8 8 9 6 9 9 8 9 9 9 7 8 8 9 5 9 7 7 7 9 9 9 8 7 8 9 8 8 8 8 4 8 8 9 9 8 6 9 9 9 2 9 7 9 8 9 8 7 8 7 9 6 6 9 9 9 7 9 9 8 9 9 9 9 8 9 8 8 8 9 9 9 8 9 6 9 8 9 ...

result:

ok 1024 numbers

Test #17:

score: 0
Accepted
time: 1ms
memory: 3836kb

input:

10 700
469 249 763 385 977 949 423 11 825 442 744 993 553 908 410 860 465 291 751 234 50 897 64 346 481 1010 444 88 605 268 531 167 853 367 389 191 784 723 783 277 916 649 418 932 516 972 714 905 358 364 334 293 391 337 785 837 721 568 555 102 456 554 165 141 253 852 43 109 699 963 915 611 16 156 83...

output:

8 7 9 8 9 9 8 3 9 8 9 9 9 9 8 9 8 8 9 7 5 9 6 8 8 9 8 6 9 8 9 7 9 8 8 7 9 9 9 8 9 9 8 9 9 9 9 9 8 8 8 8 8 8 9 9 9 9 9 6 8 9 7 7 7 9 5 6 9 9 9 9 4 7 6 8 9 9 9 7 6 5 8 8 9 8 8 8 9 7 8 9 8 8 7 9 7 9 6 6 8 9 5 9 9 8 9 8 9 9 9 8 9 8 8 9 7 9 8 6 8 6 9 9 6 9 9 5 8 7 8 9 8 8 9 6 7 7 9 8 9 9 9 9 9 6 9 9 7 6 ...

result:

ok 1024 numbers

Test #18:

score: 0
Accepted
time: 1ms
memory: 3724kb

input:

10 655
971 111 296 479 453 490 163 686 195 492 1014 762 1021 15 351 618 137 181 853 758 876 598 703 486 125 35 41 266 603 682 733 294 391 967 373 508 860 501 1018 1003 642 365 531 883 89 674 869 311 442 734 886 165 701 139 447 271 540 190 983 474 816 769 1015 101 896 904 692 627 643 750 615 20 406 5...

output:

9 6 8 8 8 8 7 9 7 8 9 9 9 3 8 9 7 7 9 9 9 9 9 8 6 5 5 8 9 9 9 8 8 9 8 8 9 8 9 9 9 8 9 9 6 9 9 8 8 9 9 7 9 7 8 8 9 7 9 8 9 9 9 6 9 9 9 9 9 9 9 4 8 8 7 8 7 9 9 8 2 9 9 9 9 9 9 5 8 7 9 9 7 8 8 6 7 7 7 8 9 9 9 9 9 7 9 9 9 5 9 9 7 7 9 9 8 9 7 6 7 8 9 8 4 9 8 9 9 9 8 9 8 8 9 5 8 7 4 9 9 9 6 8 8 9 8 9 9 8 ...

result:

ok 1024 numbers

Test #19:

score: 0
Accepted
time: 1ms
memory: 3772kb

input:

10 827
692 816 52 570 178 260 248 531 852 777 232 378 955 632 325 256 328 599 802 165 966 493 166 125 488 942 965 716 947 276 156 894 194 742 933 185 384 152 277 333 991 424 487 435 423 504 113 106 307 205 745 155 654 226 16 518 884 757 1009 133 401 392 451 510 682 717 922 608 148 206 854 355 728 51...

output:

9 9 5 9 7 8 7 9 9 9 7 8 9 9 8 8 8 9 9 7 9 8 7 6 8 9 9 9 9 8 7 9 7 9 9 7 8 7 8 8 9 8 8 8 8 8 6 6 8 7 9 7 9 7 4 9 9 9 9 7 8 8 8 8 9 9 9 9 7 7 9 8 9 8 7 7 5 7 8 9 8 8 8 9 9 7 9 6 9 8 6 6 4 9 8 5 9 6 9 9 7 9 9 6 9 9 8 8 9 9 9 9 9 9 8 2 6 9 9 9 7 8 9 9 2 8 7 8 8 8 7 9 9 8 9 8 4 9 9 8 9 8 8 9 4 8 9 9 9 6 ...

result:

ok 1024 numbers

Test #20:

score: 0
Accepted
time: 1ms
memory: 4060kb

input:

10 328
454 408 810 540 254 321 33 682 91 53 398 761 1023 243 581 545 825 892 100 356 17 326 487 878 787 756 996 707 770 924 945 272 428 686 339 908 390 645 238 337 517 364 717 404 533 394 849 435 894 947 482 806 657 39 781 946 75 656 129 476 676 984 456 412 463 160 562 592 345 141 145 501 921 991 21...

output:

8 8 9 9 7 8 5 9 6 5 8 9 9 7 9 9 9 9 6 8 4 8 8 9 9 9 9 9 9 9 9 8 8 9 8 9 8 9 7 8 9 8 9 8 9 8 9 8 9 9 8 9 9 5 9 9 6 9 7 8 9 9 8 8 8 7 9 9 8 7 7 8 9 9 7 8 6 5 9 9 3 9 9 6 9 9 6 9 1 9 9 8 8 8 8 8 8 9 8 9 8 5 8 9 7 9 8 7 8 9 9 8 8 2 9 7 8 9 7 9 8 9 9 9 8 8 9 9 9 8 9 6 7 9 9 8 8 9 7 9 9 9 9 9 9 9 9 4 6 9 ...

result:

ok 1024 numbers

Test #21:

score: 0
Accepted
time: 1ms
memory: 3728kb

input:

10 825
601 142 625 471 287 405 117 857 340 984 863 530 575 994 436 394 529 25 141 332 735 966 1 831 673 896 89 272 649 81 384 242 864 817 174 382 145 469 577 715 893 275 914 455 667 169 179 521 305 925 976 213 40 380 659 499 918 725 561 616 948 924 1022 721 235 485 85 781 540 52 892 982 254 461 381 ...

output:

9 7 9 8 8 8 6 9 8 9 9 9 9 9 8 8 9 4 7 8 9 9 0 9 9 9 6 8 9 6 8 7 9 9 7 8 7 8 9 9 9 8 9 8 9 7 7 9 8 9 9 7 5 8 9 8 9 9 9 9 9 9 9 9 7 8 6 9 9 5 9 9 7 8 8 9 9 6 9 9 9 9 8 4 5 7 9 9 8 5 9 9 9 7 9 6 8 9 2 6 9 8 9 7 7 9 9 9 9 9 9 7 8 8 9 9 9 6 9 8 7 9 9 6 9 9 9 4 9 8 9 9 9 8 7 8 7 8 7 8 9 8 4 9 9 9 6 7 7 9 ...

result:

ok 1024 numbers

Test #22:

score: 0
Accepted
time: 423ms
memory: 52244kb

input:

20 0
179487 921757 700836 1026745 871114 487101 416568 943369 555729 702080 475044 257810 489454 716476 879881 237658 884615 645342 654881 754504 537330 488794 60810 581898 627225 134547 267586 35544 535278 202909 1006004 182486 863804 12271 705426 1000913 315415 495258 494119 323180 59354 347058 62...

output:

0 1 0 5 1 0 0 2 0 2 1 0 0 1 3 0 3 0 0 1 1 0 0 2 2 0 1 0 1 0 4 0 1 0 0 3 0 2 1 0 0 1 0 2 1 0 6 0 4 0 0 1 0 1 0 2 2 0 0 1 0 3 0 1 4 0 0 1 2 0 0 1 0 1 0 3 0 1 2 0 2 0 1 0 3 0 0 1 1 0 12 0 2 0 1 0 0 1 4 0 0 1 2 0 0 3 0 1 0 1 0 2 1 0 2 0 0 1 3 0 0 1 0 5 0 1 2 0 1 0 0 3 1 0 0 2 1 0 4 0 2 0 0 1 1 0 2 0 0 5...

result:

ok 1048576 numbers

Test #23:

score: 0
Accepted
time: 429ms
memory: 52120kb

input:

20 0
423991 752898 398498 684927 789044 263019 482251 912839 731501 161924 299043 221772 386164 726231 81052 522548 2147 664063 669633 811292 646801 487230 645801 231433 697608 767873 119403 655574 294512 625240 464604 171777 37789 989183 13473 24697 1013507 285860 816836 313163 256565 724812 246357...

output:

0 2 0 1 1 0 0 5 3 0 1 0 0 2 0 1 0 1 0 4 2 0 1 0 0 3 0 1 0 2 1 0 0 2 0 1 3 0 1 0 0 2 1 0 0 1 0 6 4 0 1 0 0 2 0 1 1 0 0 3 1 0 0 2 0 1 2 0 0 3 1 0 0 5 1 0 0 1 2 0 2 0 1 0 1 0 4 0 0 3 0 1 2 0 1 0 0 1 3 0 2 0 0 1 8 0 0 1 1 0 2 0 1 0 0 3 0 1 2 0 4 0 1 0 0 2 1 0 6 0 1 0 1 0 2 0 1 0 0 2 1 0 3 0 0 1 0 4 2 0 ...

result:

ok 1048576 numbers

Test #24:

score: 0
Accepted
time: 438ms
memory: 52376kb

input:

20 0
983530 824894 353093 559444 613542 519778 1010412 455455 935622 219374 221225 1002197 688110 472174 221344 689249 527925 36045 510374 449980 724144 993684 416271 594751 888484 336792 425268 493926 392740 391689 841678 822738 12764 433848 349413 450603 182285 354617 758953 176599 70237 340919 10...

output:

2 0 0 1 1 0 6 0 1 0 0 3 1 0 0 2 2 0 1 0 0 4 0 1 3 0 0 1 1 0 2 0 0 1 0 2 0 1 4 0 0 1 0 3 0 1 0 2 0 3 0 1 1 0 2 0 0 5 0 1 0 2 0 1 1 0 2 0 0 1 0 4 1 0 0 2 0 1 0 3 0 2 1 0 7 0 1 0 0 3 1 0 0 1 2 0 0 1 2 0 1 0 0 4 0 2 0 1 1 0 0 3 0 2 0 1 0 1 0 3 0 5 1 0 1 0 2 0 4 0 0 1 0 2 0 1 2 0 1 0 3 0 1 0 1 0 6 0 0 2 ...

result:

ok 1048576 numbers

Test #25:

score: 0
Accepted
time: 441ms
memory: 52236kb

input:

20 0
473443 822631 836606 745020 669384 831958 929557 812459 979454 261979 335172 118201 544502 229223 877541 915721 504368 226689 582157 166448 910835 805293 989769 735782 836472 212234 901652 203944 246343 341883 923372 761793 496413 774045 10709 822705 804842 393237 234688 760980 575433 264037 29...

output:

0 1 2 0 0 1 3 0 4 0 1 0 1 0 0 2 1 0 2 0 1 0 5 0 1 0 2 0 0 1 3 0 0 1 0 3 2 0 0 1 1 0 0 6 2 0 0 1 0 1 0 2 0 1 0 3 1 0 2 0 0 4 0 1 0 1 8 0 2 0 1 0 1 0 0 3 2 0 0 1 0 1 0 3 0 2 1 0 2 0 0 1 1 0 0 4 1 0 3 0 1 0 2 0 2 0 0 1 4 0 0 1 2 0 1 0 1 0 3 0 0 2 1 0 0 1 5 0 2 0 1 0 0 4 1 0 3 0 0 1 1 0 0 2 0 6 0 1 2 0 ...

result:

ok 1048576 numbers

Test #26:

score: 0
Accepted
time: 452ms
memory: 52312kb

input:

20 0
379980 596897 473700 685210 871737 592347 265581 99773 654162 711671 796026 221716 77951 211806 1016499 68541 105291 832026 37890 741817 787 338525 847057 564452 291439 25137 796527 274136 516811 336906 65693 431115 565546 913432 505987 731031 411514 962171 317881 69424 7338 181350 326333 89987...

output:

0 1 0 2 3 0 1 0 0 1 2 0 0 1 5 0 0 2 0 1 0 1 4 0 1 0 3 0 2 0 0 1 0 2 0 1 0 4 1 0 0 1 0 3 1 0 2 0 0 6 0 1 2 0 1 0 0 1 2 0 0 3 1 0 0 3 1 0 0 1 2 0 0 2 0 1 4 0 1 0 0 3 0 1 2 0 1 0 1 0 0 2 1 0 5 0 2 0 0 1 1 0 4 0 0 1 0 3 2 0 1 0 1 0 0 2 1 0 3 0 0 1 2 0 1 0 0 8 0 3 1 0 0 2 1 0 1 0 0 2 5 0 1 0 0 1 0 2 1 0 ...

result:

ok 1048576 numbers

Test #27:

score: 0
Accepted
time: 753ms
memory: 52172kb

input:

20 966077
920272 22829 905052 391939 529694 220017 113245 305146 1033496 776070 372388 649193 372732 578999 535089 376914 300958 674096 713438 294435 185108 175377 843411 186645 326129 937577 777304 855769 317353 63291 166972 152975 982092 882338 296632 371732 94559 247688 915006 853946 1012694 9336...

output:

19 14 19 18 19 17 16 18 19 19 18 19 18 19 19 18 18 19 19 18 17 17 19 17 18 19 19 19 18 15 17 17 19 19 18 18 16 17 19 19 19 19 19 18 19 19 18 18 17 19 18 19 8 19 17 19 18 15 18 18 19 19 18 19 18 18 19 19 18 19 18 15 19 19 19 19 19 19 19 19 18 19 19 19 18 19 19 19 19 19 18 19 19 19 19 18 19 19 17 10 1...

result:

ok 1048576 numbers

Test #28:

score: 0
Accepted
time: 755ms
memory: 52256kb

input:

20 555721
1021880 172635 932280 918167 428846 525908 637187 103654 49068 457344 839373 885403 875027 863134 159977 579040 304249 818545 817257 382257 340884 241982 600075 712988 202019 851311 748360 695531 253852 133923 1008492 733146 54917 186299 303527 503548 507480 252648 624742 477048 106320 821...

output:

19 17 19 19 18 19 19 16 15 18 19 19 19 19 17 19 18 19 19 18 18 17 19 19 17 19 19 19 17 17 19 19 15 17 18 18 18 17 19 18 16 19 19 18 19 18 19 19 19 19 18 18 19 19 19 18 18 18 19 17 18 19 19 18 19 18 19 18 19 18 16 18 18 19 16 19 19 19 18 17 18 19 17 17 14 17 17 19 19 19 17 19 19 17 19 18 19 18 19 19 ...

result:

ok 1048576 numbers

Test #29:

score: 0
Accepted
time: 464ms
memory: 52188kb

input:

20 2
87510 685288 54938 588070 730372 367883 146344 699592 300414 900908 862877 34670 608547 282283 117736 44808 999805 244617 341801 858399 835822 519712 716403 614366 485823 268639 172640 546962 812810 157814 475854 213833 81808 987188 847699 726734 206379 1012914 844523 385962 511314 353768 94378...

output:

2 3 1 2 4 2 1 3 2 5 5 1 3 2 2 1 6 1 2 4 4 1 2 2 3 2 1 3 3 1 2 2 1 5 3 2 1 6 2 2 2 1 4 3 3 2 2 1 2 1 7 3 1 4 2 2 4 1 3 2 2 3 2 1 4 1 2 3 2 2 4 1 3 1 2 3 2 1 4 2 2 1 3 5 2 1 3 2 1 6 2 2 1 5 3 2 1 2 5 2 1 4 2 3 1 3 2 4 1 2 2 3 1 3 2 2 2 3 1 3 2 9 2 1 1 10 2 4 2 1 4 3 2 2 5 1 2 5 3 1 1 2 3 2 1 2 3 2 3 2...

result:

ok 1048576 numbers

Test #30:

score: 0
Accepted
time: 460ms
memory: 52284kb

input:

20 3
924274 728807 143468 851897 609988 262663 982977 610373 135163 134795 923793 569204 875986 702834 971502 187748 476516 975902 30626 644269 750325 1008247 323883 860636 159423 598401 812886 286710 132495 750781 261871 354651 706866 180913 835118 817970 433926 930245 403851 555752 127938 224375 6...

output:

4 3 2 3 2 2 6 2 2 2 4 2 3 3 5 2 2 5 2 2 3 6 2 4 2 3 4 2 2 3 2 3 3 2 4 4 2 5 2 2 2 2 3 3 2 5 2 3 2 2 3 4 3 2 4 2 2 8 2 3 2 3 7 2 3 5 2 2 4 3 2 2 4 2 2 2 3 3 2 5 4 5 2 3 2 5 2 2 3 3 2 4 2 2 3 2 2 3 4 7 4 2 2 2 2 6 2 2 2 3 3 3 2 3 2 4 3 2 7 2 2 3 2 2 2 4 3 6 2 2 6 3 5 2 2 3 3 2 2 2 3 4 8 2 2 2 2 4 3 2 ...

result:

ok 1048576 numbers

Test #31:

score: 0
Accepted
time: 428ms
memory: 52320kb

input:

20 0
902882 664857 1047224 183618 88593 382161 107917 67910 527299 367280 276070 1032135 680366 72379 583921 516904 965765 513924 476186 648968 534455 800221 24161 171781 528257 795611 1385 536913 485662 465619 713814 725103 525557 690722 90305 573527 1015872 121873 542098 949802 127102 958923 53236...

output:

1 0 9 0 0 2 1 0 1 0 0 3 2 0 1 0 4 0 0 1 0 2 0 1 0 3 0 1 1 0 0 2 0 2 0 1 5 0 0 1 0 3 0 1 0 1 2 0 4 0 0 1 0 2 0 1 0 2 1 0 1 0 0 3 2 0 0 1 1 0 5 0 0 1 0 3 1 0 0 2 0 2 0 1 0 3 0 1 2 0 1 0 0 1 4 0 1 0 4 0 2 0 1 0 0 2 0 1 1 0 0 3 0 6 0 1 0 2 0 1 0 3 1 0 0 1 0 2 2 0 0 1 0 7 1 0 0 1 0 2 0 1 3 0 0 2 1 0 1 0 ...

result:

ok 1048576 numbers

Test #32:

score: 0
Accepted
time: 0ms
memory: 4088kb

input:

1 1
2 1

output:

1 0

result:

ok 2 number(s): "1 0"

Test #33:

score: 0
Accepted
time: 0ms
memory: 3748kb

input:

1 0
1 2

output:

0 1

result:

ok 2 number(s): "0 1"

Test #34:

score: 0
Accepted
time: 756ms
memory: 52268kb

input:

20 1048575
924274 728807 143468 851897 609988 262663 982977 610373 135163 134795 923793 569204 875986 702834 971502 187748 476516 975902 30626 644269 750325 1008247 323883 860636 159423 598401 812886 286710 132495 750781 261871 354651 706866 180913 835118 817970 433926 930245 403851 555752 127938 22...

output:

19 19 17 19 19 18 19 19 17 17 19 19 19 19 19 17 18 19 14 19 19 19 18 19 17 19 19 18 17 19 17 18 19 17 19 19 18 19 18 19 16 17 19 18 17 19 15 18 19 16 19 19 19 18 19 17 19 19 19 19 19 19 19 17 19 19 12 18 19 18 14 16 19 16 15 16 19 18 14 19 19 19 16 18 17 19 18 17 19 19 16 19 16 14 18 16 18 19 19 19 ...

result:

ok 1048576 numbers

Extra Test:

score: 0
Extra Test Passed