QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#726355#9519. Build a ComputersubcripAC ✓0ms3852kbC++1723.0kb2024-11-08 23:16:272024-11-08 23:16:27

Judging History

This is the latest submission verdict.

  • [2024-11-08 23:16:27]
  • Judged
  • Verdict: AC
  • Time: 0ms
  • Memory: 3852kb
  • [2024-11-08 23:16:27]
  • Submitted

answer

// #pragma GCC target("popcnt,lzcnt,abm,bmi,bmi2")
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
/************* This code requires C++17. ***************/

#include<bits/stdc++.h>
using namespace std;

/* macro helpers */
#define __NARGS(...) std::tuple_size<decltype(std::make_tuple(__VA_ARGS__))>::value
#define __DECOMPOSE_S(a, x) auto x = a;
#define __DECOMPOSE_N(a, ...) auto [__VA_ARGS__] = a;
constexpr void __() {}
#define __AS_PROCEDURE(...) __(); __VA_ARGS__; __()
#define __as_typeof(container) remove_reference<decltype(container)>::type

/* type aliases */
#if LONG_LONG_MAX != INT64_MAX
using ll = int64_t;
using ull = uint64_t;
#else
using ll = long long;
using ull = unsigned long long;
#endif
using int128 = __int128_t;
using uint128 = __uint128_t;
using ld = long double;
using pii = pair<int, int>;           using pil = pair<int, ll>;           using pid = pair<int, ld>;
using pli = pair<ll, int>;            using pll = pair<ll, ll>;            using pld = pair<ll, ld>;
using pdi = pair<ld, int>;            using pdl = pair<ld, ll>;            using pdd = pair<ld, ld>;
using tiii = tuple<int, int, int>;    using tiil = tuple<int, int, ll>;    using tiid = tuple<int, int, ld>;
using tili = tuple<int, ll, int>;     using till = tuple<int, ll, ll>;     using tild = tuple<int, ll, ld>;
using tidi = tuple<int, ld, int>;     using tidl = tuple<int, ld, ll>;     using tidd = tuple<int, ld, ld>;
using tlii = tuple<ll, int, int>;     using tlil = tuple<ll, int, ll>;     using tlid = tuple<ll, int, ld>;
using tlli = tuple<ll, ll, int>;      using tlll = tuple<ll, ll, ll>;      using tlld = tuple<ll, ll, ld>;
using tldi = tuple<ll, ld, int>;      using tldl = tuple<ll, ld, ll>;      using tldd = tuple<ll, ld, ld>;
using tdii = tuple<ld, int, int>;     using tdil = tuple<ld, int, ll>;     using tdid = tuple<ld, int, ld>;
using tdli = tuple<ld, ll, int>;      using tdll = tuple<ld, ll, ll>;      using tdld = tuple<ld, ll, ld>;
using tddi = tuple<ld, ld, int>;      using tddl = tuple<ld, ld, ll>;      using tddd = tuple<ld, ld, ld>;
template <typename T> using max_heap = priority_queue<T>;
template <typename T> using min_heap = priority_queue<T, vector<T>, greater<>>;
template <typename T> using oi = ostream_iterator<T>;
template <typename T> using ii = istream_iterator<T>;

/* constants */
constexpr int INF = 0x3f3f3f3f;
constexpr ll INFLL = 0x3f3f3f3f3f3f3f3fLL;
constexpr ll MDL = 1e9 + 7;
constexpr ll PRIME = 998'244'353;
constexpr ll MDL1 = 8784491;
constexpr ll MDL2 = PRIME;
constexpr int128 INT128_MAX = numeric_limits<int128>::max();
constexpr uint128 UINT128_MAX = numeric_limits<uint128>::max();
constexpr int128 INT128_MIN = numeric_limits<int128>::min();
constexpr uint128 UINT128_MIN = numeric_limits<uint128>::min();

/* random */

mt19937_64 rd(chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now().time_since_epoch()).count());

/* bit-wise operations */
#define lowbit(x) ((x) & -(x))
#define popcount(x) (__builtin_popcountll(ll(x)))
#define parity(x) (__builtin_parityll(ll(x)))
#define msp(x) (63LL - __builtin_clzll(ll(x)))
#define lsp(x) (__builtin_ctzll(ll(x)))

/* arithmetic operations */
#define mod(x, y) ((((x) % (y)) + (y)) % (y))

/* fast pairs */
#define upair ull
#define umake(x, y) (ull(x) << 32 | (ull(y) & ((1ULL << 32) - 1)))
#define u1(p) ((p) >> 32)
#define u2(p) ((p) & ((1ULL << 32) - 1))
#define ult std::less<upair>
#define ugt std::greater<upair>

#define ipair ull
#define imake(x, y) (umake(x, y))
#define i1(p) (int(u1(ll(p))))
#define i2(p) (ll(u2(p) << 32) >> 32)
struct ilt {
    bool operator()(const ipair& a, const ipair& b) const {
        if (i1(a) == i1(b)) return i2(a) < i2(b);
        else return i1(a) < i1(b);
    }
};
struct igt {
    bool operator()(const ipair& a, const ipair& b) const {
        if (i1(a) == i1(b)) return i2(a) > i2(b);
        else return i1(a) > i1(b);
    }
};

/* conditions */
#define loop while (1)
#define if_or(var, val) if (!(var == val)) var = val; else
#define continue_or(var, val) __AS_PROCEDURE(if (var == val) continue; var = val;)
#define break_or(var, val) __AS_PROCEDURE(if (var == val) break; var = val;)

/* hash */
struct safe_hash {
    // https://codeforces.com/blog/entry/62393
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

struct pair_hash {
    template <typename T, typename U>
    size_t operator()(const pair<T, U>& a) const {
        auto hash1 = safe_hash()(a.first);
        auto hash2 = safe_hash()(a.second);
        if (hash1 != hash2) {
            return hash1 ^ hash2;
        }
        return hash1;
    }
};

uniform_int_distribution<mt19937::result_type> dist(PRIME);
const size_t __array_hash_b = 31, __array_hash_mdl1 = dist(rd), __array_hash_mdl2 = dist(rd);
struct array_hash {
    template <typename Sequence>
    size_t operator()(const Sequence& arr) const {
        size_t pw1 = 1, pw2 = 1;
        size_t res1 = 0, res2 = 0;
        for (auto&& x : arr) {
            res1 = (res1 + x * pw1) % __array_hash_mdl1;
            res2 = (res2 + x * pw2) % __array_hash_mdl2;
            pw1 = (pw1 * __array_hash_b) % __array_hash_mdl1;
            pw2 = (pw2 * __array_hash_b) % __array_hash_mdl2;
        }
        return res1 + res2;
    }
};

/* build data structures */
#define faster(um) __AS_PROCEDURE((um).reserve(1024); (um).max_load_factor(0.25);)
#define unordered_counter(from, to) __AS_PROCEDURE(unordered_map<__as_typeof(from), size_t, safe_hash> to; for (auto&& x : from) ++to[x];)
#define counter(from, to, cmp) __AS_PROCEDURE(map<__as_typeof(from), size_t, cmp> to; for (auto&& x : from) ++to[x];)
#define adj(ch, n) __AS_PROCEDURE(vector<vector<int>> ch((n) + 1);)
#define edge(ch, u, v) __AS_PROCEDURE(ch[u].push_back(v), ch[v].push_back(u);)
#define edgew(ch, u, v, ...) __AS_PROCEDURE(ch[u].emplace_back(v, __VA_ARGS__), ch[v].emplace_back(u, __VA_ARGS__);)
#define Edge(ch, u, v) __AS_PROCEDURE(ch[u].push_back(v);)
#define Edgew(ch, u, v, ...) __AS_PROCEDURE(ch[u].emplace_back(v, __VA_ARGS__);)
template <typename T, typename Iterator> pair<size_t, map<T, size_t>> discretize(Iterator __first, Iterator __last) {
    set<T> st(__first, __last);
    size_t N = 0;
    map<T, size_t> mp;
    for (auto&& x : st) mp[x] = ++N;
    return {N, mp};
}
template <typename T, typename Iterator> pair<size_t, unordered_map<T, size_t, safe_hash>> unordered_discretize(Iterator __first, Iterator __last) {
    set<T> st(__first, __last);
    size_t N = 0;
    unordered_map<T, size_t, safe_hash> mp;
    for (auto&& x : st) mp[x] = ++N;
    return {N, mp};
}

/* io */
#define untie __AS_PROCEDURE(ios_base::sync_with_stdio(0), cin.tie(NULL))
template<typename T, typename U> istream& operator>>(istream& in, pair<T, U>& p) {
    return in >> p.first >> p.second;
}
template<typename T, typename U> ostream& operator<<(ostream& out, const pair<T, U>& p) {
    out << "{" << p.first << ", " << p.second << "}";
    return out;
}
template<typename Char, typename Traits, typename Tuple, std::size_t... Index>
void print_tuple_impl(std::basic_ostream<Char, Traits>& os, const Tuple& t, std::index_sequence<Index...>) {
    using swallow = int[]; // guaranties left to right order
    (void)swallow { 0, (void(os << (Index == 0 ? "" : ", ") << std::get<Index>(t)), 0)... };
}
template<typename Char, typename Traits, typename... Args>
decltype(auto) operator<<(std::basic_ostream<Char, Traits>& os, const std::tuple<Args...>& t) {
    os << "{";
    print_tuple_impl(os, t, std::index_sequence_for<Args...>{});
    return os << "}";
}
template<typename T> ostream& operator<<(ostream& out, const vector<T>& vec) {
    for (auto&& i : vec) out << i << ' ';
    return out;
}
std::ostream& operator<<(std::ostream& dest, const int128& value) {
    // https://stackoverflow.com/a/25115163/23881100
    std::ostream::sentry s( dest );
    if ( s ) {
        uint128 tmp = value < 0 ? -value : value;
        char buffer[ 128 ];
        char* d = std::end( buffer );
        do {
            -- d;
            *d = "0123456789"[ tmp % 10 ];
            tmp /= 10;
        } while ( tmp != 0 );
        if ( value < 0 ) {
            -- d;
            *d = '-';
        }
        int len = std::end( buffer ) - d;
        if ( dest.rdbuf()->sputn( d, len ) != len ) {
            dest.setstate( std::ios_base::badbit );
        }
    }
    return dest;
}
template<typename T> void __read(T& x) { cin >> x; }
template<typename T, typename... U> void __read(T& x, U&... args) { cin >> x; __read(args...); }
#define read(type, ...) __AS_PROCEDURE(type __VA_ARGS__; __read(__VA_ARGS__);)
#define readvec(type, a, n) __AS_PROCEDURE(vector<type> a(n); for (auto& x : a) cin >> x;)
#define readvec1(type, a, n) __AS_PROCEDURE(vector<type> a((n) + 1); copy_n(ii<type>(cin), (n), a.begin() + 1);)
#define putvec(a) __AS_PROCEDURE(copy(a.begin(), a.end(), oi<__as_typeof(a)::value_type>(cout, " ")); cout << endl;)
#define putvec1(a) __AS_PROCEDURE(copy(a.begin() + 1, a.end(), oi<__as_typeof(a)::value_type>(cout, " ")); cout << endl;)
#define putvec_eol(a) __AS_PROCEDURE(copy(a.begin(), a.end(), oi<__as_typeof(a)::value_type>(cout, "\n"));)
#define putvec1_eol(a) __AS_PROCEDURE(copy(a.begin() + 1, a.end(), oi<__as_typeof(a)::value_type>(cout, "\n"));)
#define debug(x) __AS_PROCEDURE(cerr << #x" = " << (x) << endl;)
#define debugvec(a) __AS_PROCEDURE(cerr << #a" = "; for (auto&& x : a) cerr << x << ' '; cerr << endl;)
#define deb(...) debug(make_tuple(__VA_ARGS__))

/* pops */
#define poptop(q, ...) __AS_PROCEDURE(auto [__VA_ARGS__] = q.top(); q.pop();)
#define popback(q, ...) __AS_PROCEDURE(auto [__VA_ARGS__] = q.back(); q.pop_back();)
#define popfront(q, ...) __AS_PROCEDURE(auto [__VA_ARGS__] = q.front();q.pop_front();)

/* math */
template <typename return_t>
return_t qpow(ll b, ll p) {
    if (b == 0 and p != 0) return 0;
    if (p == 0) return 1;
    return_t half = qpow<return_t>(b, p / 2);
    if (p % 2 == 1) return half * half * b;
    else return half * half;
}

#define comb(n, k) ((n) < 0 or (k) < 0 or (n) < (k) ? 0 : fact[n] / fact[k] / fact[(n) - (k)])
#define fastcomb(n, k) ((n) < 0 or (k) < 0 or (n) < (k) ? 0 : fact[n] * factrev[k] * factrev[(n) - (k)])

constexpr inline int lg2(ll x) { return x == 0 ? -1 : sizeof(ll) * 8 - 1 - __builtin_clzll(x); }

void __exgcd(ll a, ll b, ll& x, ll& y) {
  if (b == 0) {
    x = 1, y = 0;
    return;
  }
  __exgcd(b, a % b, y, x);
  y -= a / b * x;
}

ll inverse(ll a, ll b) {
    ll x, y;
    __exgcd(a, b, x, y);
    return mod(x, b);
}

vector<tuple<int, int, ll>> decompose(ll x) {
    // return (factor, count, factor ** count)
    vector<tuple<int, int, ll>> res;
    for (int i = 2; i * i <= x; i++) {
        if (x % i == 0) {
            int cnt = 0;
            ll pw = 1;
            while (x % i == 0) ++cnt, x /= i, pw *= i;
            res.emplace_back(i, cnt, pw);
        }
    }
    if (x != 1) {
        res.emplace_back(x, 1, x);
    }
    return res;
}

vector<pii> decompose_prime(int N) {
    // return (factor, count)
    vector<pii> result;
    for (int i = 2; i * i <= N; i++) {
        if (N % i == 0) {
            int cnt = 0;
            while (N % i == 0) N /= i, ++cnt;
            result.emplace_back(i, cnt);
        }
    }
    if (N != 1) {
        result.emplace_back(N, 1);
    }
    return result;
}

/* string algorithms */
vector<int> calc_next(string t) {  // pi function of t
  int n = (int)t.length();
  vector<int> pi(n);
  for (int i = 1; i < n; i++) {
    int j = pi[i - 1];
    while (j > 0 && t[i] != t[j]) j = pi[j - 1];
    if (t[i] == t[j]) j++;
    pi[i] = j;
  }
  return pi;
}
vector<int> calc_z(string t) {  // z function of t
    int m = t.length();
    vector<int> z;
    z.push_back(m);
    pair<int, int> prev = {1, -1};
    for (int i = 1; i < m; ++i) {
        if (z[i - prev.first] + i <= prev.second) {
            z.push_back(z[i - prev.first]);
        } else {
            int j = max(i, prev.second + 1);
            while (j < m && t[j] == t[j - i]) ++j;
            z.push_back(j - i);
            prev = {i, j - 1};
        }
    }
    return z;
}
vector<int> kmp(string s, string t) {  // find all t in s
  string cur = t + '#' + s;
  int sz1 = s.size(), sz2 = t.size();
  vector<int> v;
  vector<int> lps = calc_next(cur);
  for (int i = sz2 + 1; i <= sz1 + sz2; i++) {
    if (lps[i] == sz2) v.push_back(i - 2 * sz2);
  }
  return v;
}
int period(string s) {  // find the length of shortest recurring period
    int n = s.length();
    auto z = calc_z(s);
    for (int i = 1; i <= n / 2; ++i) {
        if (n % i == 0 && z[i] == n - i) {
            return i;
        }
    }
    return n;
}

/* modular arithmetic */
template <ll mdl> struct MLL {
    ll val;
    MLL(ll v = 0) : val(mod(v, mdl)) {}
    MLL(const MLL<mdl>& other) : val(other.val) {}
    friend MLL operator+(const MLL& lhs, const MLL& rhs) { return mod(lhs.val + rhs.val, mdl); }
    friend MLL operator-(const MLL& lhs, const MLL& rhs) { return mod(lhs.val - rhs.val, mdl); }
    friend MLL operator*(const MLL& lhs, const MLL& rhs) { return mod(lhs.val * rhs.val, mdl); }
    friend MLL operator/(const MLL& lhs, const MLL& rhs) { return mod(lhs.val * mod(inverse(rhs.val, mdl), mdl), mdl); }
    friend MLL operator%(const MLL& lhs, const MLL& rhs) { return mod(lhs.val - (lhs / rhs).val, mdl); }
    friend bool operator==(const MLL& lhs, const MLL& rhs) { return lhs.val == rhs.val; }
    friend bool operator!=(const MLL& lhs, const MLL& rhs) { return lhs.val != rhs.val; }
    void operator+=(const MLL& rhs) { val = (*this + rhs).val; }
    void operator-=(const MLL& rhs) { val = (*this - rhs).val; }
    void operator*=(const MLL& rhs) { val = (*this * rhs).val; }
    void operator/=(const MLL& rhs) { val = (*this / rhs).val; }
    void operator%=(const MLL& rhs) { val = (*this % rhs).val; }
};

template <ll mdl>
ostream& operator<<(ostream& out, const MLL<mdl>& num) {
    return out << num.val;
}

template <ll mdl>
istream& operator>>(istream& in, MLL<mdl>& num) {
    return in >> num.val;
}

// miscancellous
template <typename T, typename U>
bool chmax(T& lhs, const U& rhs) {
    bool ret = lhs < rhs;
    if (ret) {
        lhs = rhs;
    }
    return ret;
}
template <typename T, typename U>
bool chmin(T& lhs, const U& rhs) {
    bool ret = lhs > rhs;
    if (ret) {
        lhs = rhs;
    }
    return ret;
}

#define functor(func) ([&](auto&&... val) \
noexcept(noexcept(func(std::forward<decltype(val)>(val)...))) -> decltype(auto) \
{return func(std::forward<decltype(val)>(val)...);})
#define expr(ret, ...) ([&] (__VA_ARGS__) { return (ret); })
template <typename Func, typename RandomIt> void sort_by_key(RandomIt first, RandomIt last, Func extractor) {
    std::sort(first, last, [&] (auto&& a, auto&& b) { return std::less<>()(extractor(a), extractor(b)); });
}
template <typename Func, typename RandomIt, typename Compare> void sort_by_key(RandomIt first, RandomIt last, Func extractor, Compare comp) {
    std::sort(first, last, [&] (auto&& a, auto&& b) { return comp(extractor(a), extractor(b)); });
}
template <typename T, typename U, typename Iterator_T, typename Iterator_U>
vector<pair<T, U>> zip(Iterator_T a_first, Iterator_T a_last, Iterator_U b_first, Iterator_U b_last) {
    vector<pair<T, U>> res;
    auto a_it = a_first;
    auto b_it = b_first;
    for (; not (a_it == a_last) and not (b_it == b_last); ++a_it, ++b_it) {
        res.emplace_back(*a_it, *b_it);
    }
    return res;
}
template <typename T, typename U, typename Iterator_T, typename Iterator_U>
vector<pair<T, U>> zip_n(Iterator_T a_first, Iterator_U b_first, size_t n) {
    vector<pair<T, U>> res;
    if (n > 0) {
        res.emplace_back(*a_first, *b_first);
        for (size_t i = 1; i != n; ++i) {
            res.emplace_back(*++a_first, *++b_first);
        }
    }
    return res;
}
template <typename T>
class ArithmeticIterator : bidirectional_iterator_tag {
public:
    using difference_type = ptrdiff_t;
    using value_type = T;
private:
    value_type value;
public:
    ArithmeticIterator(const T& value) : value(value) {}
    value_type operator*() const { return value; }
    ArithmeticIterator<T>& operator++() { ++value; return *this; }
    ArithmeticIterator<T>& operator--() { --value; return *this; }
    bool operator==(const ArithmeticIterator<T>& rhs) const { return value == rhs.value; }
};
template <typename T> vector<pair<int, T>> enumerate(const vector<T>& container) {
    return zip<int, T>(ArithmeticIterator<int>(0), ArithmeticIterator<int>(INT_MAX), container.begin(), container.end());
}
#define initarray(init, N) (__initarray<decay<decltype(init)>::type, (N)>(init))
namespace detail {
    template <typename T, std::size_t...Is>
    constexpr std::array<T, sizeof...(Is)>
    make_array(const T& value, std::index_sequence<Is...>) {
        return {{(static_cast<void>(Is), value)...}};
    }
}

template <typename T, std::size_t N>
constexpr std::array<T, N> __initarray(const T& value) {
    return detail::make_array(value, std::make_index_sequence<N>());
}
/*******************************************************/

#define SINGLE_TEST_CASE
// #define DUMP_TEST_CASE 7219
// #define TOT_TEST_CASE 10000

void dump() {}

void dump_ignore() {}

void prep() {
}

__attribute__((target("lzcnt")))
void solve() {
    read(int, l, r);

    if (l == r) {
        cout << msp(l) + 2 << '\n';
        int cnt = 0;
        for (int i = msp(l); ~i; --i) {
            cnt += 1;
            cout << "1 " << cnt + 1 << ' ' << (l >> i & 1) << '\n';
        }
        cout << "0\n";
    } else {
        int dpos;
        for (int i = msp(r); ~i; --i) {
            if ((l >> i & 1) != (r >> i & 1)) {
                dpos = i;
                break;
            }
        }

        vector<vector<pii>> e(2);
        int start = 0, end = 1;

        int head;
        {
            int curr = start;
            for (int i = msp(r); i > dpos; --i) {
                e[curr].emplace_back(e.size(), r >> i & 1);
                e.emplace_back();
                curr = e.size() - 1;
            }
            head = curr;
        }

        if (dpos == 0) {
            e[head].emplace_back(end, 0);
            e[head].emplace_back(end, 1);
        } else {
            // right half
            e[head].emplace_back(e.size(), 1);
            e.emplace_back();
            int curr = e.size() - 1;
            vector<int> mp_zero;
            for (int i = dpos - 1; ~i; --i) {
                int bit = r >> i & 1;
                if (bit == 1) {
                    if (mp_zero.empty()) {
                        mp_zero.emplace_back(end);
                        for (int j = 1; j <= i; ++j) {
                            mp_zero.emplace_back(e.size());
                            e.emplace_back();
                        }
                        for (int j = i - 1; ~j; --j) {
                            e[mp_zero[j + 1]].emplace_back(mp_zero[j], 1);
                            e[mp_zero[j + 1]].emplace_back(mp_zero[j], 0);
                        }
                    }
                    e[curr].emplace_back(mp_zero[i], 0);
                }
                if (i == 0) {
                    e[curr].emplace_back(end, bit);
                } else {
                    e[curr].emplace_back(e.size(), bit);
                    e.emplace_back();
                    curr = e.size() - 1;
                }
            }

            // left half
            vector<int> mp_one;
            int s;
            if (head == start) {
                if (msp(l) == 0) {
                    e[head].emplace_back(end, 1);
                } else {
                    e[head].emplace_back(e.size(), 1);
                    e.emplace_back();
                    curr = e.size() - 1;
                }
                s = msp(l) - 1;
                for (int i = dpos - 1; i > msp(l); --i) {
                    if (mp_one.empty()) {
                        mp_one.emplace_back(end);
                        for (int j = 1; j <= i; ++j) {
                            mp_one.emplace_back(e.size());
                            e.emplace_back();
                        }
                        for (int j = i - 1; ~j; --j) {
                            e[mp_one[j + 1]].emplace_back(mp_one[j], 1);
                            e[mp_one[j + 1]].emplace_back(mp_one[j], 0);
                        }
                    }
                    e[head].emplace_back(mp_one[i], 1);
                }
            } else {
                e[head].emplace_back(e.size(), 0);
                e.emplace_back();
                curr = e.size() - 1;
                s = dpos - 1;
            }
            for (int i = s; ~i; --i) {
                int bit = l >> i & 1;
                if (bit == 0) {
                    if (mp_one.empty()) {
                        mp_one.emplace_back(end);
                        for (int j = 1; j <= i; ++j) {
                            mp_one.emplace_back(e.size());
                            e.emplace_back();
                        }
                        for (int j = i - 1; ~j; --j) {
                            e[mp_one[j + 1]].emplace_back(mp_one[j], 1);
                            e[mp_one[j + 1]].emplace_back(mp_one[j], 0);
                        }
                    }
                    e[curr].emplace_back(mp_one[i], 1);
                }
                if (i == 0) {
                    e[curr].emplace_back(end, bit);
                } else {
                    e[curr].emplace_back(e.size(), bit);
                    e.emplace_back();
                    curr = e.size() - 1;
                }
            }
        }


        int n = e.size();
        cout << n << '\n';
        for (int i = 0; i < n; ++i) {
            cout << e[i].size() << ' ';
            for (auto&& [j, v] : e[i]) {
                cout << j + 1 << ' ' << v << ' ';
            }
            cout << '\n';
        }
    }
}

int main() {
#if __cplusplus < 201402L or defined(_MSC_VER) and not defined(__clang__)
    assert(false && "incompatible compiler variant detected.");
#endif
    untie;
    prep();
#ifdef SINGLE_TEST_CASE
    solve();
#else
    read(int, t);
    for (int i = 0; i < t; ++i) {
#ifdef DUMP_TEST_CASE
        if (t != (TOT_TEST_CASE)) {
            solve();
        } else if (i + 1 == (DUMP_TEST_CASE)) {
            dump();
        } else {
            dump_ignore();
        }
#else
        solve();
#endif
    }
#endif
}

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

詳細信息

Test #1:

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

input:

5 7

output:

5
1 3 1 
0 
2 4 1 5 0 
2 2 0 2 1 
1 2 1 

result:

ok ok

Test #2:

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

input:

10 27

output:

14
2 3 1 10 1 
0 
2 6 0 7 1 
2 2 1 2 0 
2 4 1 4 0 
2 5 1 5 0 
1 8 0 
2 4 0 9 1 
2 2 0 2 1 
2 12 1 13 0 
2 2 1 2 0 
2 11 1 11 0 
1 14 1 
2 2 1 2 0 

result:

ok ok

Test #3:

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

input:

5 13

output:

10
2 3 1 8 1 
0 
2 5 0 6 1 
2 2 1 2 0 
2 4 1 4 0 
1 7 0 
2 2 0 2 1 
2 9 1 10 0 
2 2 1 2 0 
1 2 1 

result:

ok ok

Test #4:

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

input:

1 1000000

output:

57
20 3 1 2 1 57 1 56 1 55 1 54 1 53 1 52 1 51 1 50 1 49 1 48 1 47 1 46 1 45 1 44 1 43 1 42 1 41 1 40 1 
0 
2 21 0 22 1 
2 2 1 2 0 
2 4 1 4 0 
2 5 1 5 0 
2 6 1 6 0 
2 7 1 7 0 
2 8 1 8 0 
2 9 1 9 0 
2 10 1 10 0 
2 11 1 11 0 
2 12 1 12 0 
2 13 1 13 0 
2 14 1 14 0 
2 15 1 15 0 
2 16 1 16 0 
2 17 1 17 0...

result:

ok ok

Test #5:

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

input:

1 1

output:

2
1 2 1
0

result:

ok ok

Test #6:

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

input:

7 9

output:

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

result:

ok ok

Test #7:

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

input:

3 7

output:

6
2 3 1 6 1 
0 
2 4 0 5 1 
2 2 1 2 0 
2 2 0 2 1 
1 2 1 

result:

ok ok

Test #8:

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

input:

1 5

output:

5
3 3 1 2 1 5 1 
0 
1 4 0 
2 2 0 2 1 
2 2 1 2 0 

result:

ok ok

Test #9:

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

input:

1 4

output:

5
3 3 1 2 1 5 1 
0 
1 4 0 
1 2 0 
2 2 1 2 0 

result:

ok ok

Test #10:

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

input:

8 9

output:

5
1 3 1 
0 
1 4 0 
1 5 0 
2 2 0 2 1 

result:

ok ok

Test #11:

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

input:

7 51

output:

17
4 3 1 12 1 16 1 15 1 
0 
2 7 0 8 1 
2 2 1 2 0 
2 4 1 4 0 
2 5 1 5 0 
2 6 1 6 0 
1 9 0 
1 10 0 
2 4 0 11 1 
2 2 0 2 1 
1 17 1 
2 2 1 2 0 
2 13 1 13 0 
2 14 1 14 0 
2 15 1 15 0 
1 2 1 

result:

ok ok

Test #12:

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

input:

51 79

output:

19
2 3 1 12 1 
0 
1 4 0 
1 5 0 
2 8 0 9 1 
2 2 1 2 0 
2 6 1 6 0 
2 7 1 7 0 
2 7 0 10 1 
2 6 0 11 1 
2 2 0 2 1 
1 13 1 
2 16 1 17 0 
2 2 1 2 0 
2 14 1 14 0 
2 15 1 15 0 
2 15 1 18 0 
1 19 1 
1 2 1 

result:

ok ok

Test #13:

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

input:

92 99

output:

15
1 3 1 
0 
2 4 1 10 0 
1 5 0 
1 6 0 
1 7 0 
2 8 0 9 1 
2 2 1 2 0 
2 2 0 2 1 
1 11 1 
1 12 1 
1 13 1 
2 14 1 15 0 
2 2 1 2 0 
2 2 1 2 0 

result:

ok ok

Test #14:

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

input:

27 36

output:

15
2 3 1 10 1 
0 
1 4 0 
1 5 0 
2 7 0 8 1 
2 2 1 2 0 
2 6 1 6 0 
1 9 0 
1 2 0 
1 11 1 
2 13 1 14 0 
2 2 1 2 0 
2 12 1 12 0 
1 15 1 
1 2 1 

result:

ok ok

Test #15:

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

input:

55 84

output:

20
2 3 1 13 1 
0 
1 4 0 
2 8 0 9 1 
2 2 1 2 0 
2 5 1 5 0 
2 6 1 6 0 
2 7 1 7 0 
1 10 0 
2 6 0 11 1 
1 12 0 
1 2 0 
1 14 1 
2 17 1 18 0 
2 2 1 2 0 
2 15 1 15 0 
2 16 1 16 0 
1 19 1 
1 20 1 
1 2 1 

result:

ok ok

Test #16:

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

input:

297208 929600

output:

74
2 3 1 40 1 
0 
2 21 0 22 1 
2 2 1 2 0 
2 4 1 4 0 
2 5 1 5 0 
2 6 1 6 0 
2 7 1 7 0 
2 8 1 8 0 
2 9 1 9 0 
2 10 1 10 0 
2 11 1 11 0 
2 12 1 12 0 
2 13 1 13 0 
2 14 1 14 0 
2 15 1 15 0 
2 16 1 16 0 
2 17 1 17 0 
2 18 1 18 0 
2 19 1 19 0 
2 20 1 20 0 
2 20 0 23 1 
1 24 0 
1 25 0 
1 26 0 
2 16 0 27 1 ...

result:

ok ok

Test #17:

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

input:

45728 589156

output:

69
5 3 1 37 1 55 1 54 1 53 1 
0 
1 4 0 
1 5 0 
1 6 0 
2 21 0 22 1 
2 2 1 2 0 
2 7 1 7 0 
2 8 1 8 0 
2 9 1 9 0 
2 10 1 10 0 
2 11 1 11 0 
2 12 1 12 0 
2 13 1 13 0 
2 14 1 14 0 
2 15 1 15 0 
2 16 1 16 0 
2 17 1 17 0 
2 18 1 18 0 
2 19 1 19 0 
2 20 1 20 0 
2 20 0 23 1 
2 19 0 24 1 
2 18 0 25 1 
2 17 0 ...

result:

ok ok

Test #18:

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

input:

129152 138000

output:

57
2 3 1 32 1 
0 
1 4 0 
1 5 0 
1 6 0 
1 7 0 
2 19 0 20 1 
2 2 1 2 0 
2 8 1 8 0 
2 9 1 9 0 
2 10 1 10 0 
2 11 1 11 0 
2 12 1 12 0 
2 13 1 13 0 
2 14 1 14 0 
2 15 1 15 0 
2 16 1 16 0 
2 17 1 17 0 
2 18 1 18 0 
2 18 0 21 1 
1 22 0 
2 16 0 23 1 
2 15 0 24 1 
1 25 0 
1 26 0 
1 27 0 
2 11 0 28 1 
1 29 0 ...

result:

ok ok

Test #19:

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

input:

245280 654141

output:

72
3 3 1 38 1 56 1 
0 
1 4 0 
1 5 0 
2 21 0 22 1 
2 2 1 2 0 
2 6 1 6 0 
2 7 1 7 0 
2 8 1 8 0 
2 9 1 9 0 
2 10 1 10 0 
2 11 1 11 0 
2 12 1 12 0 
2 13 1 13 0 
2 14 1 14 0 
2 15 1 15 0 
2 16 1 16 0 
2 17 1 17 0 
2 18 1 18 0 
2 19 1 19 0 
2 20 1 20 0 
2 20 0 23 1 
2 19 0 24 1 
2 18 0 25 1 
2 17 0 26 1 
...

result:

ok ok

Test #20:

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

input:

202985 296000

output:

67
2 3 1 36 1 
0 
1 4 0 
1 5 0 
2 20 0 21 1 
2 2 1 2 0 
2 6 1 6 0 
2 7 1 7 0 
2 8 1 8 0 
2 9 1 9 0 
2 10 1 10 0 
2 11 1 11 0 
2 12 1 12 0 
2 13 1 13 0 
2 14 1 14 0 
2 15 1 15 0 
2 16 1 16 0 
2 17 1 17 0 
2 18 1 18 0 
2 19 1 19 0 
1 22 0 
1 23 0 
1 24 0 
1 25 0 
2 15 0 26 1 
1 27 0 
1 28 0 
1 29 0 
2...

result:

ok ok

Test #21:

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

input:

438671 951305

output:

73
2 3 1 40 1 
0 
2 21 0 22 1 
2 2 1 2 0 
2 4 1 4 0 
2 5 1 5 0 
2 6 1 6 0 
2 7 1 7 0 
2 8 1 8 0 
2 9 1 9 0 
2 10 1 10 0 
2 11 1 11 0 
2 12 1 12 0 
2 13 1 13 0 
2 14 1 14 0 
2 15 1 15 0 
2 16 1 16 0 
2 17 1 17 0 
2 18 1 18 0 
2 19 1 19 0 
2 20 1 20 0 
2 20 0 23 1 
1 24 0 
2 18 0 25 1 
1 26 0 
1 27 0 ...

result:

ok ok

Test #22:

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

input:

425249 739633

output:

72
2 3 1 39 1 
0 
1 4 0 
2 21 0 22 1 
2 2 1 2 0 
2 5 1 5 0 
2 6 1 6 0 
2 7 1 7 0 
2 8 1 8 0 
2 9 1 9 0 
2 10 1 10 0 
2 11 1 11 0 
2 12 1 12 0 
2 13 1 13 0 
2 14 1 14 0 
2 15 1 15 0 
2 16 1 16 0 
2 17 1 17 0 
2 18 1 18 0 
2 19 1 19 0 
2 20 1 20 0 
2 20 0 23 1 
1 24 0 
2 18 0 25 1 
1 26 0 
1 27 0 
2 1...

result:

ok ok

Test #23:

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

input:

551207 961718

output:

73
1 3 1 
0 
2 4 1 39 0 
2 21 0 22 1 
2 2 1 2 0 
2 5 1 5 0 
2 6 1 6 0 
2 7 1 7 0 
2 8 1 8 0 
2 9 1 9 0 
2 10 1 10 0 
2 11 1 11 0 
2 12 1 12 0 
2 13 1 13 0 
2 14 1 14 0 
2 15 1 15 0 
2 16 1 16 0 
2 17 1 17 0 
2 18 1 18 0 
2 19 1 19 0 
2 20 1 20 0 
1 23 0 
2 19 0 24 1 
1 25 0 
2 17 0 26 1 
1 27 0 
2 1...

result:

ok ok

Test #24:

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

input:

114691 598186

output:

71
4 3 1 38 1 56 1 55 1 
0 
1 4 0 
1 5 0 
2 21 0 22 1 
2 2 1 2 0 
2 6 1 6 0 
2 7 1 7 0 
2 8 1 8 0 
2 9 1 9 0 
2 10 1 10 0 
2 11 1 11 0 
2 12 1 12 0 
2 13 1 13 0 
2 14 1 14 0 
2 15 1 15 0 
2 16 1 16 0 
2 17 1 17 0 
2 18 1 18 0 
2 19 1 19 0 
2 20 1 20 0 
1 23 0 
1 24 0 
2 18 0 25 1 
1 26 0 
1 27 0 
1 ...

result:

ok ok

Test #25:

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

input:

234654 253129

output:

58
1 3 1 
0 
1 4 1 
1 5 1 
2 6 1 32 0 
1 7 0 
2 19 0 20 1 
2 2 1 2 0 
2 8 1 8 0 
2 9 1 9 0 
2 10 1 10 0 
2 11 1 11 0 
2 12 1 12 0 
2 13 1 13 0 
2 14 1 14 0 
2 15 1 15 0 
2 16 1 16 0 
2 17 1 17 0 
2 18 1 18 0 
2 18 0 21 1 
2 17 0 22 1 
1 23 0 
1 24 0 
2 14 0 25 1 
2 13 0 26 1 
1 27 0 
1 28 0 
2 10 0 ...

result:

ok ok

Test #26:

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

input:

554090 608599

output:

66
1 3 1 
0 
1 4 0 
1 5 0 
2 6 1 36 0 
1 7 0 
2 21 0 22 1 
2 2 1 2 0 
2 8 1 8 0 
2 9 1 9 0 
2 10 1 10 0 
2 11 1 11 0 
2 12 1 12 0 
2 13 1 13 0 
2 14 1 14 0 
2 15 1 15 0 
2 16 1 16 0 
2 17 1 17 0 
2 18 1 18 0 
2 19 1 19 0 
2 20 1 20 0 
1 23 0 
1 24 0 
2 18 0 25 1 
1 26 0 
1 27 0 
2 15 0 28 1 
1 29 0 ...

result:

ok ok

Extra Test:

score: 0
Extra Test Passed