QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#870012#8616. Fast Tree Queriesucup-team159#AC ✓2902ms25744kbC++2326.3kb2025-01-25 14:24:352025-01-25 14:24:39

Judging History

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

  • [2025-01-25 14:24:39]
  • 评测
  • 测评结果:AC
  • 用时:2902ms
  • 内存:25744kb
  • [2025-01-25 14:24:35]
  • 提交

answer

#line 1 "ucup3-27/F/main.cpp"
#define YOSUPO_AVX2_PRAGMA
// #undef YOSUPO_LOCAL

#line 2 "/home/vscode/yosupo-library/src/yosupo/fastio.hpp"

#include <unistd.h>
#include <algorithm>
#include <array>
#include <bit>
#include <cassert>
#include <cctype>
#include <cstdint>
#include <cstring>
#include <sstream>
#include <string>
#include <type_traits>
#include <vector>

#line 2 "/home/vscode/yosupo-library/src/yosupo/internal_type_traits.hpp"

#line 5 "/home/vscode/yosupo-library/src/yosupo/internal_type_traits.hpp"

namespace yosupo {

namespace internal {

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 ||
                                  internal::is_signed_int128<T>::value ||
                                  internal::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;

template <class T>
using is_integral_t = std::enable_if_t<is_integral<T>::value>;

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 yosupo
#line 17 "/home/vscode/yosupo-library/src/yosupo/fastio.hpp"

namespace yosupo {

struct Scanner {
  public:
    Scanner(const Scanner&) = delete;
    Scanner& operator=(const Scanner&) = delete;

    Scanner(FILE* fp) : fd(fileno(fp)) { line[0] = 127; }

    void read() {}
    template <class H, class... T> void read(H& h, T&... t) {
        bool f = read_single(h);
        assert(f);
        read(t...);
    }

    int read_unsafe() { return 0; }
    template <class H, class... T> int read_unsafe(H& h, T&... t) {
        bool f = read_single(h);
        if (!f) return 0;
        return 1 + read_unsafe(t...);
    }

    int close() { return ::close(fd); }

  private:
    static constexpr int SIZE = 1 << 15;

    int fd = -1;
    std::array<char, SIZE + 1> line;
    int st = 0, ed = 0;
    bool eof = false;

    bool read_single(std::string& ref) {
        if (!skip_space()) return false;
        ref = "";
        while (true) {
            char c = top();
            if (c <= ' ') break;
            ref += c;
            st++;
        }
        return true;
    }
    bool read_single(double& ref) {
        std::string s;
        if (!read_single(s)) return false;
        ref = std::stod(s);
        return true;
    }

    template <class T,
              std::enable_if_t<std::is_same<T, char>::value>* = nullptr>
    bool read_single(T& ref) {
        if (!skip_space<50>()) return false;
        ref = top();
        st++;
        return true;
    }

    template <class T,
              internal::is_signed_int_t<T>* = nullptr,
              std::enable_if_t<!std::is_same<T, char>::value>* = nullptr>
    bool read_single(T& sref) {
        using U = internal::to_unsigned_t<T>;
        if (!skip_space<50>()) return false;
        bool neg = false;
        if (line[st] == '-') {
            neg = true;
            st++;
        }
        U ref = 0;
        do {
            ref = 10 * ref + (line[st++] & 0x0f);
        } while (line[st] >= '0');
        sref = neg ? -ref : ref;
        return true;
    }
    template <class U,
              internal::is_unsigned_int_t<U>* = nullptr,
              std::enable_if_t<!std::is_same<U, char>::value>* = nullptr>
    bool read_single(U& ref) {
        if (!skip_space<50>()) return false;
        ref = 0;
        do {
            ref = 10 * ref + (line[st++] & 0x0f);
        } while (line[st] >= '0');
        return true;
    }

    bool reread() {
        if (ed - st >= 50) return true;
        if (st > SIZE / 2) {
            std::memmove(line.data(), line.data() + st, ed - st);
            ed -= st;
            st = 0;
        }
        if (eof) return false;
        auto u = ::read(fd, line.data() + ed, SIZE - ed);
        if (u == 0) {
            eof = true;
            line[ed] = '\0';
            u = 1;
        }
        ed += int(u);
        line[ed] = char(127);
        return true;
    }

    char top() {
        if (st == ed) {
            bool f = reread();
            assert(f);
        }
        return line[st];
    }

    template <int TOKEN_LEN = 0> bool skip_space() {
        while (true) {
            while (line[st] <= ' ') st++;
            if (ed - st > TOKEN_LEN) return true;
            if (st > ed) st = ed;
            for (auto i = st; i < ed; i++) {
                if (line[i] <= ' ') return true;
            }
            if (!reread()) return false;
        }
    }
};

struct Printer {
  public:
    template <char sep = ' ', bool F = false> void write() {}
    template <char sep = ' ', bool F = false, class H, class... T>
    void write(const H& h, const T&... t) {
        if (F) write_single(sep);
        write_single(h);
        write<true>(t...);
    }
    template <char sep = ' ', class... T> void writeln(const T&... t) {
        write<sep>(t...);
        write_single('\n');
    }

    Printer(FILE* _fp) : fd(fileno(_fp)) {}
    ~Printer() { flush(); }

    int close() {
        flush();
        return ::close(fd);
    }

    void flush() {
        if (pos) {
            auto res = ::write(fd, line.data(), pos);
            assert(res != -1);
            pos = 0;
        }
    }

  private:
    static std::array<std::array<char, 2>, 100> small;
    static std::array<unsigned long long, 20> tens;

    static constexpr size_t SIZE = 1 << 15;
    int fd;
    std::array<char, SIZE> line;
    size_t pos = 0;
    std::stringstream ss;

    template <class T,
              std::enable_if_t<std::is_same<char, T>::value>* = nullptr>
    void write_single(const T& val) {
        if (pos == SIZE) flush();
        line[pos++] = val;
    }

    template <class T,
              internal::is_signed_int_t<T>* = nullptr,
              std::enable_if_t<!std::is_same<char, T>::value>* = nullptr>
    void write_single(const T& val) {
        using U = internal::to_unsigned_t<T>;
        if (val == 0) {
            write_single('0');
            return;
        }
        if (pos > SIZE - 50) flush();
        U uval = val;
        if (val < 0) {
            write_single('-');
            uval = -uval;
        }
        write_unsigned(uval);
    }

    template <class U,
              internal::is_unsigned_int_t<U>* = nullptr,
              std::enable_if_t<!std::is_same<char, U>::value>* = nullptr>
    void write_single(U uval) {
        if (uval == 0) {
            write_single('0');
            return;
        }
        if (pos > SIZE - 50) flush();

        write_unsigned(uval);
    }

    static int calc_len(uint64_t x) {
        int i = ((63 - std::countl_zero(x)) * 3 + 3) / 10;
        if (x < tens[i])
            return i;
        else
            return i + 1;
    }

    template <class U,
              internal::is_unsigned_int_t<U>* = nullptr,
              std::enable_if_t<2 >= sizeof(U)>* = nullptr>
    void write_unsigned(U uval) {
        size_t len = calc_len(uval);
        pos += len;

        char* ptr = line.data() + pos;
        while (uval >= 100) {
            ptr -= 2;
            memcpy(ptr, small[uval % 100].data(), 2);
            uval /= 100;
        }
        if (uval >= 10) {
            memcpy(ptr - 2, small[uval].data(), 2);
        } else {
            *(ptr - 1) = char('0' + uval);
        }
    }

    template <class U,
              internal::is_unsigned_int_t<U>* = nullptr,
              std::enable_if_t<4 == sizeof(U)>* = nullptr>
    void write_unsigned(U uval) {
        std::array<char, 8> buf;
        memcpy(buf.data() + 6, small[uval % 100].data(), 2);
        memcpy(buf.data() + 4, small[uval / 100 % 100].data(), 2);
        memcpy(buf.data() + 2, small[uval / 10000 % 100].data(), 2);
        memcpy(buf.data() + 0, small[uval / 1000000 % 100].data(), 2);

        if (uval >= 100000000) {
            if (uval >= 1000000000) {
                memcpy(line.data() + pos, small[uval / 100000000 % 100].data(),
                       2);
                pos += 2;
            } else {
                line[pos] = char('0' + uval / 100000000);
                pos++;
            }
            memcpy(line.data() + pos, buf.data(), 8);
            pos += 8;
        } else {
            size_t len = calc_len(uval);
            memcpy(line.data() + pos, buf.data() + (8 - len), len);
            pos += len;
        }
    }

    template <class U,
              internal::is_unsigned_int_t<U>* = nullptr,
              std::enable_if_t<8 == sizeof(U)>* = nullptr>
    void write_unsigned(U uval) {
        size_t len = calc_len(uval);
        pos += len;

        char* ptr = line.data() + pos;
        while (uval >= 100) {
            ptr -= 2;
            memcpy(ptr, small[uval % 100].data(), 2);
            uval /= 100;
        }
        if (uval >= 10) {
            memcpy(ptr - 2, small[uval].data(), 2);
        } else {
            *(ptr - 1) = char('0' + uval);
        }
    }

    template <
        class U,
        std::enable_if_t<internal::is_unsigned_int128<U>::value>* = nullptr>
    void write_unsigned(U uval) {
        static std::array<char, 50> buf;
        size_t len = 0;
        while (uval > 0) {
            buf[len++] = char((uval % 10) + '0');
            uval /= 10;
        }
        std::reverse(buf.begin(), buf.begin() + len);
        memcpy(line.data() + pos, buf.data(), len);
        pos += len;
    }

    void write_single(const std::string& s) {
        for (char c : s) write_single(c);
    }
    void write_single(const char* s) {
        size_t len = strlen(s);
        for (size_t i = 0; i < len; i++) write_single(s[i]);
    }
    template <class T> void write_single(const std::vector<T>& val) {
        auto n = val.size();
        for (size_t i = 0; i < n; i++) {
            if (i) write_single(' ');
            write_single(val[i]);
        }
    }
};

inline std::array<std::array<char, 2>, 100> Printer::small = [] {
    std::array<std::array<char, 2>, 100> table;
    for (int i = 0; i <= 99; i++) {
        table[i][1] = char('0' + (i % 10));
        table[i][0] = char('0' + (i / 10 % 10));
    }
    return table;
}();
inline std::array<unsigned long long, 20> Printer::tens = [] {
    std::array<unsigned long long, 20> table;
    for (int i = 0; i < 20; i++) {
        table[i] = 1;
        for (int j = 0; j < i; j++) {
            table[i] *= 10;
        }
    }
    return table;
}();

}  // namespace yosupo
#line 2 "/home/vscode/yosupo-library/src/yosupo/random.hpp"

#line 6 "/home/vscode/yosupo-library/src/yosupo/random.hpp"
#include <chrono>
#line 8 "/home/vscode/yosupo-library/src/yosupo/random.hpp"
#include <random>
#line 10 "/home/vscode/yosupo-library/src/yosupo/random.hpp"

namespace yosupo {

struct Xoshiro256StarStar {
  public:
    using result_type = uint64_t;
    Xoshiro256StarStar() : Xoshiro256StarStar(0) {}
    explicit Xoshiro256StarStar(uint64_t seed) {
        // use splitmix64
        // Reference: http://xoshiro.di.unimi.it/splitmix64.c
        for (int i = 0; i < 4; i++) {
            uint64_t z = (seed += 0x9e3779b97f4a7c15);
            z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9;
            z = (z ^ (z >> 27)) * 0x94d049bb133111eb;
            s[i] = z ^ (z >> 31);
        }
    }

    static constexpr result_type min() { return 0; }
    static constexpr result_type max() { return -1; }

    result_type operator()() {
        const uint64_t result_starstar = rotl(s[1] * 5, 7) * 9;

        const uint64_t t = s[1] << 17;

        s[2] ^= s[0];
        s[3] ^= s[1];
        s[1] ^= s[2];
        s[0] ^= s[3];

        s[2] ^= t;

        s[3] = rotl(s[3], 45);

        return result_starstar;
    }

  private:
    // Use xoshiro256**
    // Refereces: http://xoshiro.di.unimi.it/xoshiro256starstar.c
    static uint64_t rotl(const uint64_t x, int k) {
        return (x << k) | (x >> (64 - k));
    }

    std::array<uint64_t, 4> s;
};

// https://github.com/wangyi-fudan/wyhash
struct WYRand {
  public:
    using result_type = uint64_t;
    explicit WYRand(uint64_t seed) : s(seed) {}

    static constexpr result_type min() { return 0; }
    static constexpr result_type max() { return -1; }

    result_type operator()() {
        s += 0x2d358dccaa6c78a5;
        auto x = (unsigned __int128)s * (s ^ 0x8bb84b93962eacc9);
        return (uint64_t)(x ^ (x >> 64));
    }

  private:
    uint64_t s;
};
using Random = WYRand;
inline Random& global_gen() {
    static Random gen(
        std::chrono::steady_clock::now().time_since_epoch().count());
    return gen;
}

template <class G>
concept random_64 = std::uniform_random_bit_generator<G> &&
                    std::same_as<uint64_t, std::invoke_result_t<G&>> &&
                    G::min() == uint64_t(0) && G::max() == uint64_t(-1);

namespace internal {

// random choice from [0, upper]
template <random_64 G> uint64_t uniform_u64(uint64_t upper, G& gen) {
    if (!(upper & (upper + 1))) {
        // b = 00..0011..11
        return gen() & upper;
    }
    int log = 63 - std::countl_zero(upper);
    uint64_t mask = (log == 63) ? ~0ULL : (1ULL << (log + 1)) - 1;
    while (true) {
        uint64_t r = gen() & mask;
        if (r <= upper) return r;
    }
}

// random choice from [0, upper], faster than uniform_u64
template <random_64 G> uint64_t random_u64(uint64_t upper, G& gen) {
    return (uint64_t)(((unsigned __int128)(upper) + 1) * gen() >> 64);
}

}  // namespace internal

template <class T, random_64 G> T uniform(T lower, T upper, G& gen) {
    return T(lower +
             internal::uniform_u64(uint64_t(upper) - uint64_t(lower), gen));
}
template <class T> T uniform(T lower, T upper) {
    return uniform(lower, upper, global_gen());
}
template <class T, random_64 G> T random(T lower, T upper, G& gen) {
    return T(lower +
             internal::random_u64(uint64_t(upper) - uint64_t(lower), gen));
}
template <class T> T random(T lower, T upper) {
    return random(lower, upper, global_gen());
}

template <random_64 G> bool uniform_bool(G& gen) { return gen() & 1; }
inline bool uniform_bool() { return uniform_bool(global_gen()); }

// select 2 elements from [lower, uppper]
template <class T, random_64 G>
std::pair<T, T> uniform_pair(T lower, T upper, G& gen) {
    assert(upper - lower >= 1);
    T a, b;
    do {
        a = uniform(lower, upper, gen);
        b = uniform(lower, upper, gen);
    } while (a == b);
    if (a > b) std::swap(a, b);
    return {a, b};
}
template <class T> std::pair<T, T> uniform_pair(T lower, T upper) {
    return uniform_pair(lower, upper, global_gen());
}

// random value in the interval (0.0, 1.0]
template <class G> inline double open_closed_01(G& gen) {
    union {
        uint64_t i;
        double f;
    } u = {0xbff0000000000000 | (gen() >> 12)};
    return 2.0 + u.f;
}
inline double open_closed_01() {
    return open_closed_01(global_gen());
}

}  // namespace yosupo
#line 6 "ucup3-27/F/main.cpp"
using namespace yosupo;

#line 2 "ucup3-27/F/base.hpp"

#ifdef YOSUPO_AVX2_PRAGMA
#line 5 "ucup3-27/F/base.hpp"
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#endif

#line 11 "ucup3-27/F/base.hpp"
#include <bitset>
#line 13 "ucup3-27/F/base.hpp"
#include <cmath>
#include <cstdio>
#line 16 "ucup3-27/F/base.hpp"
#include <iostream>
#include <map>
#include <queue>
#include <ranges>
#include <set>
#line 22 "ucup3-27/F/base.hpp"
#include <utility>
#line 24 "ucup3-27/F/base.hpp"

using std::abs, std::pow, std::sqrt;
using std::array, std::vector, std::string, std::queue, std::deque;
using std::countl_zero, std::countl_one, std::countr_zero, std::countr_one;
using std::istream, std::ostream, std::cerr, std::endl;
using std::min, std::max, std::swap;
using std::pair, std::tuple, std::bitset;
using std::popcount;
using std::priority_queue, std::set, std::multiset, std::map;
using std::views::iota, std::views::reverse;

namespace ranges = std::ranges;
using ranges::sort, ranges::copy_n;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

#ifdef YOSUPO_LOCAL

inline ostream& operator<<(ostream& os, __int128_t x) {
    if (x < 0) {
        os << "-";
        x *= -1;
    }
    if (x == 0) {
        return os << "0";
    }
    string s;
    while (x) {
        s += char(x % 10 + '0');
        x /= 10;
    }
    ranges::reverse(s);
    return os << s;
}
inline ostream& operator<<(ostream& os, __uint128_t x) {
    if (x == 0) {
        return os << "0";
    }
    string s;
    while (x) {
        s += char(x % 10 + '0');
        x /= 10;
    }
    ranges::reverse(s);
    return os << s;
}

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p);
template <class T> ostream& operator<<(ostream& os, const V<T>& v);
template <class T> ostream& operator<<(ostream& os, const deque<T>& v);
template <class T, size_t N>
ostream& operator<<(ostream& os, const array<T, N>& a);
template <class T> ostream& operator<<(ostream& os, const set<T>& s);
template <class T, class U>
ostream& operator<<(ostream& os, const map<T, U>& m);

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    return os << "P(" << p.first << ", " << p.second << ")";
}

template <class T> ostream& operator<<(ostream& os, const V<T>& v) {
    os << "[";
    bool f = false;
    for (auto d : v) {
        if (f) os << ", ";
        f = true;
        os << d;
    }
    return os << "]";
}

template <class T> ostream& operator<<(ostream& os, const deque<T>& v) {
    os << "[";
    bool f = false;
    for (auto d : v) {
        if (f) os << ", ";
        f = true;
        os << d;
    }
    return os << "]";
}
template <class T, size_t N>
ostream& operator<<(ostream& os, const array<T, N>& a) {
    os << "[";
    bool f = false;
    for (auto d : a) {
        if (f) os << ", ";
        f = true;
        os << d;
    }
    return os << "]";
}

template <class T> ostream& operator<<(ostream& os, const set<T>& s) {
    os << "{";
    bool f = false;
    for (auto d : s) {
        if (f) os << ", ";
        f = true;
        os << d;
    }
    return os << "}";
}
template <class T> ostream& operator<<(ostream& os, const multiset<T>& s) {
    os << "{";
    bool f = false;
    for (auto d : s) {
        if (f) os << ", ";
        f = true;
        os << d;
    }
    return os << "}";
}

template <class T, class U>
ostream& operator<<(ostream& os, const map<T, U>& s) {
    os << "{";
    bool f = false;
    for (auto p : s) {
        if (f) os << ", ";
        f = true;
        os << p.first << ": " << p.second;
    }
    return os << "}";
}

struct PrettyOS {
    ostream& os;
    bool first;

    template <class T> auto operator<<(T&& x) {
        if (!first) os << ", ";
        first = false;
        os << x;
        return *this;
    }
};
template <class... T> void dbg0(T&&... t) {
    (PrettyOS{cerr, true} << ... << t);
}
#define dbg(...)                                            \
    do {                                                    \
        cerr << __LINE__ << " : " << #__VA_ARGS__ << " = "; \
        dbg0(__VA_ARGS__);                                  \
        cerr << endl;                                       \
    } while (false);
#else
#define dbg(...)
#endif
#line 9 "ucup3-27/F/main.cpp"

Scanner sc = Scanner(stdin);
Printer pr = Printer(stdout);

struct HL {
    // inside index of HL
    struct I {
        int i;
    };
    V<int> _ord;          // int -> I
    V<int> _rord;         // I -> int
    V<int> _big, _small;  // I -> I
    // optionals
    V<int> dps;       // node depth(int -> int)
    int pc = 0;       // path count(optional)
    V<int> pid, psz;  // path id, size (optional)
    V<int> _out;      // ouv[i] is end of subtree(I -> I)
    HL() {}
    HL(size_t n)
        : _ord(n), _rord(n), _big(n), _small(n), dps(n), pid(n), _out(n) {}
    I ord(int v) const { return v == -1 ? I{-1} : I{_ord[v]}; }
    int rord(I i) const { return i.i == -1 ? -1 : _rord[i.i]; }
    I par(I i) const { return I{_small[i.i] == i.i ? _big[i.i] : i.i - 1}; }
    I subtree_out(int v) const { return I{_out[ord(v).i]}; };
    int par(int v) const { return rord(par(ord(v))); }
    int lca(int a, int b) const {
        int ai = ord(a).i;
        int bi = ord(b).i;
        while (ai != bi) {
            if (ai > bi) swap(ai, bi);
            if (_small[bi] <= ai)
                break;
            else
                bi = _big[bi];
        }
        return rord(I{ai});
    }
    // aの直前までbから登る、f(I, I)の引数は両閉区間
    template <class F> void get_path(int a, int b, F f) const {
        int ai = ord(a).i;
        int bi = ord(b).i;
        while (ai < bi) {
            if (_small[bi] <= ai)
                f(I{ai + 1}, I{bi});
            else
                f(I{_small[bi]}, I{bi});
            bi = _big[bi];
        }
    }
    int to(int a, int b) {  // aからbの方向へ1移動する
        int ai = ord(a).i;
        int bi = ord(b).i;
        assert(ai < bi);
        while (true) {
            if (_small[bi] <= ai)
                return rord(I{ai + 1});
            else if (_big[bi] == ai)
                return rord(I{_small[bi]});
            bi = _big[bi];
        }
        assert(false);
    }
    int dist(int a, int b) const {
        int c = lca(a, b);
        return dps[a] + dps[b] - 2 * dps[c];
    }
};

template <class E> struct HLExec : HL {
    const VV<E>& g;
    V<int> tch;
    int id = 0;
    HLExec(const VV<E>& _g, int r) : HL(_g.size()), g(_g), tch(g.size(), -1) {
        assert(dfs_sz(r, -1) == int(g.size()));
        dfs(r, -1);
        init_extra();
    }
    void init_extra() {
        // ord, rord, big, small以外を使わないなら不要
        int n = int(g.size());

        // dps
        dps[rord(I{0})] = 0;
        for (int i = 1; i < n; i++) {
            dps[rord(I{i})] = dps[rord(par(I{i}))] + 1;
        }

        // pid, psz, pc
        int l = 0;
        while (l < n) {
            int r = l + 1;
            while (r < n && _small[r] == l) r++;
            psz.push_back(r - l);
            for (int i = l; i < r; i++) {
                pid[i] = pc;
            }
            l = r;
            pc++;
        }

        // out
        for (int i = n - 1; i >= 0; i--) {
            _out[i] = max(_out[i], i + 1);
            int p = ord(par(rord(I{i}))).i;
            if (p != -1) _out[p] = max(_out[p], _out[i]);
        }
    }
    int dfs_sz(int p, int b) {
        int sz = 1, msz = -1;
        for (auto e : g[p]) {
            if (e.to == b) continue;
            int u = dfs_sz(e.to, p);
            sz += u;
            if (msz < u) std::tie(tch[p], msz) = std::make_pair(e.to, u);
        }
        return sz;
    }
    void dfs(int p, int b) {
        int q = id++, bq = ord(b).i;
        _ord[p] = q;
        _rord[q] = p;
        if (b == -1 || bq != q - 1) {
            _small[q] = q;
            _big[q] = bq;
        } else {
            _small[q] = _small[bq];
            _big[q] = _big[bq];
        }
        if (tch[p] == -1) return;
        dfs(tch[p], p);
        for (auto e : g[p]) {
            if (e.to == b || e.to == tch[p]) continue;
            dfs(e.to, p);
        }
    }
};

template <class E> HL get_hl(const VV<E>& g, int r) { return HLExec<E>(g, r); }


int main() {
    int n, q;
    sc.read(n, q);
    //n = 100000;
    //q = n;

    struct E { int to; };
    VV<E> g(n);
    for (int _ : iota(0, n - 1)) {
        int u, v;
        sc.read(u, v);
        u--; v--;

        //u = _;
        //v = _ + 1;

        g[u].push_back({v});
        g[v].push_back({u});
    }
    auto hl = get_hl(g, 0);

    V<uint> a(n);
    for (int i : iota(0, n)) {
        a[hl.ord(i).i] = i + 1;
    }

    for (int _ : iota(0, q)) {
        string s;
        sc.read(s);
        int u, v;
        sc.read(u, v);
        u--; v--;

        // std::tie(u, v) = uniform_pair(0, n - 1);
        
        int w = hl.lca(u, v);

        int ty = s == "?" ? 0 : 1;
        //int ty = uniform(0, 1);

        if (ty == 0) {
            uint x = 0;
            hl.get_path(w, u, [&](auto l, auto r) {
                for (int i : iota(l.i, r.i + 1)) {
                    x ^= a[i];
                }
            });
            hl.get_path(hl.par(w), v, [&](auto l, auto r) {
                for (int i : iota(l.i, r.i + 1)) {
                    x ^= a[i];
                }
            });

            pr.writeln(x);
        } else {
            uint x;
            sc.read(x);
            // x = uniform(0, 10000);

            hl.get_path(w, u, [&](auto l, auto r) {
                for (int i : iota(l.i, r.i + 1)) {
                    a[i] += x;
                }
            });
            hl.get_path(hl.par(w), v, [&](auto l, auto r) {
                for (int i : iota(l.i, r.i + 1)) {
                    a[i] += x;
                }
            });
        }
    }
    return 0;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5 6
1 2
1 3
3 4
3 5
? 2 5
+ 1 4 1
? 2 5
+ 4 5 2
? 4 5
? 1 1

output:

5
1
6
2

result:

ok 4 number(s): "5 1 6 2"

Test #2:

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

input:

100 100
6 74
6 93
7 46
7 78
10 77
11 9
11 19
11 37
11 51
11 65
12 57
13 15
13 81
13 100
14 2
14 31
16 11
16 24
16 43
16 82
18 4
18 8
21 56
24 29
24 96
26 22
27 32
28 59
29 6
29 94
32 33
35 54
35 80
35 88
37 66
37 71
37 84
38 17
39 64
39 92
40 49
43 7
43 13
43 44
43 79
44 35
44 60
44 63
44 73
46 75
4...

output:

106
66
23766
20394
16388
3365
12076
7844
43127
56700
59
34700
24083
1164
24068
18776
3375
17495
21576
63126
11157
108177
63127
99162
105173
10715
110921
18320
19725
30958
120179
81226
107525
15669
21804
31071
63099
8313
191380
232240
84531
89146
173181
5447
160027
228651
98075
32595
109808
221822
11...

result:

ok 51 numbers

Test #3:

score: 0
Accepted
time: 3ms
memory: 4412kb

input:

10000 10000
1 8776
3 1597
3 8333
4 675
4 6993
4 7587
5 3379
5 6733
7 2440
7 6480
7 9506
10 4545
10 6664
12 1476
12 5343
14 1340
14 4167
14 5990
14 9910
15 5118
15 9423
16 8106
17 3856
20 5201
23 1138
24 3431
24 5578
25 251
26 3219
26 4156
26 6668
27 3795
28 6282
28 8196
34 9595
35 3919
36 5893
37 58...

output:

9911
12310
4793
31764
2730
42301
62944
16978
8306
25311
3011
1327
48224
8407
15662
38117
42837
59074
40600
39018
126441
21755
24519
51286
121187
4335
8349
10553
60726
86675
10797
3883
90069
95477
129342
37777
42339
124045
94323
16858
217612
79454
258856
118337
257945
196316
170121
216631
168616
1663...

result:

ok 5012 numbers

Test #4:

score: 0
Accepted
time: 17ms
memory: 7808kb

input:

50000 50000
1 1362
3 3371
3 13803
3 41794
3 47253
5 6227
5 42748
5 47841
6 28509
6 47395
7 8651
8 35909
10 24241
10 31205
10 33574
10 44109
10 48982
12 31361
12 44645
13 42041
15 20480
16 9467
16 11685
16 16024
16 28894
16 30759
19 3485
19 23470
19 24714
22 14239
25 44841
31 20447
35 5378
35 45983
3...

output:

5042
36803
61033
62216
64370
9744
33748
43519
25564
87892
120265
52351
36778
1507
81138
124599
19620
169852
82219
106112
38410
47506
214605
229380
175036
184353
71808
135637
195043
213707
60790
86453
31176
26740
107180
117349
64903
55397
245841
33362
73881
227391
227333
52027
217335
146795
51029
100...

result:

ok 24888 numbers

Test #5:

score: 0
Accepted
time: 39ms
memory: 12392kb

input:

100000 100000
4 6907
4 36895
4 37669
4 43936
4 99352
5 70501
10 29516
11 2844
11 77315
13 67782
13 72511
14 17273
14 52833
16 97869
19 29567
20 150
20 22843
20 40110
20 55549
20 70574
22 19544
25 43083
26 6781
28 16286
31 54186
33 6987
33 30861
33 98931
35 1140
35 21137
35 26681
35 59133
35 68440
35...

output:

81605
93578
30029
52473
57143
63629
77074
53264
71956
49059
16958
120352
93046
80080
67928
99557
182425
198595
36952
180370
156161
98094
56273
28969
34287
146511
31057
171228
128057
13930
81021
69266
100431
118091
249004
63451
147951
223183
255240
173677
30490
137681
135801
8441
205904
32855
66449
2...

result:

ok 50026 numbers

Test #6:

score: 0
Accepted
time: 58ms
memory: 12528kb

input:

100000 100000
1 484
1 23605
4 29115
5 78235
6 41049
7 17427
7 59118
7 73639
8 11499
8 21824
11 1488
11 34365
11 46659
15 1670
15 18862
16 88552
17 6551
17 18453
17 22090
18 90500
19 7369
19 40175
19 88031
19 89418
20 82312
22 36035
22 37511
22 90587
24 26545
25 99359
26 9713
26 19360
26 23939
27 145...

output:

118339
49557
8069
129295
8844
117076
73582
44568
123694
84080
220459
65210
20353
78112
178132
238977
76360
242837
177610
55964
146913
258846
46783
101598
210987
130886
215693
137264
91070
47636
222290
212175
70753
64509
143987
258750
63355
124572
249779
144712
237288
64472
32941
26055
220986
221734
...

result:

ok 50004 numbers

Test #7:

score: 0
Accepted
time: 334ms
memory: 16112kb

input:

100000 100000
2 96325
3 2625
3 19305
3 23547
3 33880
4 34351
4 80895
6 81122
7 8449
8 33132
9 6805
10 66297
12 40279
15 97995
17 28489
17 58943
17 63155
18 16755
19 36111
19 48497
20 73429
21 58028
22 23782
23 23210
25 43059
25 98782
28 96774
29 13371
30 18348
30 33119
31 91098
32 20761
34 19579
34 ...

output:

127926
27191
52198
17494
136
89133
88302
171
53017
111240
104493
80525
30736
39514
30186
242564
127960
116595
77217
181066
78202
117647
65124
5801
23054
231346
224212
101596
208931
56567
153986
225153
98732
39206
196696
201593
49107
59019
227567
23907
240224
47177
110143
93337
12687
16281
91369
7419...

result:

ok 49756 numbers

Test #8:

score: 0
Accepted
time: 488ms
memory: 18320kb

input:

100000 100000
1 18235
1 18934
2 89403
2 90291
3 31647
3 35123
4 14885
5 62625
6 75214
6 78206
6 86462
8 68147
10 73927
12 70742
13 18440
13 52686
14 486
15 38714
17 22417
19 10945
20 65914
22 168
24 72860
24 77513
25 43311
28 65572
31 24246
31 59430
32 26581
33 50532
35 41198
35 50438
38 10180
39 26...

output:

22351
118753
109047
88534
43548
60668
10313
43770
93628
94411
177029
257319
102775
45279
115695
72012
192085
82192
95036
247561
261897
165855
165273
226260
148341
25180
217815
163115
16411
218342
48666
2097
28168
215064
103606
87112
56628
51686
160381
172733
114741
224702
118590
202031
122700
81734
...

result:

ok 50083 numbers

Test #9:

score: 0
Accepted
time: 640ms
memory: 20156kb

input:

100000 100000
1 11525
1 89745
2 67284
3 9976
4 50748
5 77041
6 78293
7 56148
8 96259
9 89843
10 27797
11 16227
12 42015
13 68712
14 79151
15 28737
16 12689
16 46963
17 28758
17 97100
18 9035
18 45786
19 90894
20 6079
21 74811
22 59751
24 46439
25 61997
26 49256
27 47844
27 94562
28 36184
28 66803
29...

output:

27686
112778
112901
88910
1259
100292
96264
120935
67017
16105
254118
72138
79696
90798
240510
79481
58592
122335
35752
50037
4041
228323
26517
261989
101035
109710
124017
214226
78961
147898
227267
88759
232759
3546
176037
13839
58194
199727
72664
208807
235932
95313
72316
175531
185967
46635
25389...

result:

ok 50026 numbers

Test #10:

score: 0
Accepted
time: 932ms
memory: 22416kb

input:

100000 100000
1 8418
2 20507
3 79696
4 480
5 96826
6 39218
7 33218
8 91962
9 61011
10 76027
11 51859
12 47310
13 9311
14 62652
15 54337
16 37358
17 8695
18 30671
19 48794
20 60657
21 52785
22 67049
23 53237
24 89488
25 75316
26 59632
27 67663
28 64116
29 55756
30 9293
31 94163
32 68737
33 19549
34 2...

output:

59881
78759
127664
105428
29216
107850
23544
72603
31268
104150
10678
99895
191639
208183
143507
28071
112078
206140
244014
94502
180431
86547
228779
253881
114121
78644
211819
183217
3147
260855
252995
92807
134492
222747
179363
178012
163544
6300
56553
216082
135851
241124
54901
160545
83866
34670...

result:

ok 50161 numbers

Test #11:

score: 0
Accepted
time: 939ms
memory: 19576kb

input:

100000 100000
1 65542
2 44999
3 44775
4 53755
5 91414
6 88642
7 43743
8 66023
9 81924
10 33144
11 16238
12 69557
13 88380
14 14104
15 1590
16 22493
17 76223
18 2992
19 59612
20 19262
21 44547
22 9268
23 12883
24 8940
25 89232
26 83134
27 39177
28 25894
29 66905
30 75897
31 68348
32 31913
33 37824
34...

output:

85995
93714
48766
33134
15475
33702
26879
252344
91559
31139
32105
17681
214842
50526
179
127372
79021
215907
232859
150665
37612
228872
251465
221167
238269
143930
94966
193052
240279
70502
210689
5253
244204
197389
79884
65172
23165
26916
135637
44849
246604
184554
131027
12149
145820
236776
27224...

result:

ok 49916 numbers

Test #12:

score: 0
Accepted
time: 880ms
memory: 25744kb

input:

100000 100000
1 20244
2 70573
3 10436
4 38605
5 82242
6 7959
7 41794
8 6055
9 31572
10 18325
11 47705
12 92257
13 84847
14 29103
15 56455
16 78786
17 15635
18 46887
19 42925
20 73042
21 13655
22 17805
23 79078
24 2264
25 75041
26 20673
27 67835
28 26420
29 43093
30 18005
31 30599
32 67822
33 74865
3...

output:

57973
49029
120357
260910
16992
270917
140712
61400
151081
193091
45372
245217
372812
730619
84632
443274
274702
287820
414375
965786
802481
1047701
620743
227679
563632
989174
510166
711609
1202310
1778396
696203
940565
166128
1123056
1109958
1219135
89745
975640
1434947
1480887
1051570
1795047
219...

result:

ok 5037 numbers

Test #13:

score: 0
Accepted
time: 995ms
memory: 20156kb

input:

100000 100000
1 49702
2 2333
3 57831
4 12821
5 62769
6 86649
7 42954
8 30845
9 6944
10 85242
11 29311
12 5403
13 41153
14 2035
15 93153
16 81418
17 11087
18 12973
19 43286
20 9192
21 26723
22 55297
23 69360
24 78933
25 69855
26 33093
27 36813
28 99089
29 46016
30 31662
31 21406
32 91918
33 75022
34 ...

output:

116023
74250
12533
23051
52968
29149
10175
3442
19482
110017
81204
46160
87223
6212
112117
46650
8708
41872
113753
21588
42133
118956
82183
41958
50964
67881
106887
70982
61306
47670
2186
57415
113171
117211
32700
77284
106361
121708
98751
107296
66647
51878
94513
15650
34650
107171
100594
125147
30...

result:

ok 94964 numbers

Test #14:

score: 0
Accepted
time: 2734ms
memory: 19568kb

input:

100000 100000
1 51281
2 98534
3 56890
4 91069
5 13958
6 53488
7 85023
8 36325
9 53644
10 51148
11 40287
12 22074
13 71930
14 42072
15 26952
16 97057
17 38720
18 18348
19 55081
20 46329
21 6145
22 96670
23 17563
24 63818
25 33264
26 89453
27 4561
28 8807
29 90035
30 50901
31 76224
32 63425
33 64586
3...

output:

48966
34949
100005
115783
90664
101369
86978
68458
124455
60125
720
162086
197800
46796
33398
187834
19882
136944
40634
187939
207446
218823
12321
205875
63213
7354
91929
104422
44719
49354
225170
123331
90704
129455
65861
194543
456311
164926
246119
166606
10928
404670
246844
136232
51411
149969
19...

result:

ok 49756 numbers

Test #15:

score: 0
Accepted
time: 2580ms
memory: 23200kb

input:

100000 100000
1 92615
2 88373
3 88745
4 58354
5 24241
6 70117
7 7474
8 47980
9 6849
10 9192
11 66174
12 88815
13 50287
14 60656
15 11112
16 48531
17 69958
18 53839
19 71335
20 10861
21 15521
22 67298
23 61906
24 34513
25 74665
26 31182
27 77910
28 39425
29 13475
30 29380
31 36965
32 71970
33 28150
3...

output:

238801
120555
164488
98713
2599
122503
405454
177726
330455
441985
228138
270151
149692
239460
58748
85861
1527370
1278580
2080749
187336
925428
767180
859833
1016615
780947
21643
1213833
1194783
1960577
1896675
869390
3610735
297981
1420255
2596004
4151506
2371827
2701564
621389
381816
584791
31707...

result:

ok 5005 numbers

Test #16:

score: 0
Accepted
time: 2887ms
memory: 23160kb

input:

100000 100000
1 34291
2 31226
3 1756
4 67460
5 46349
6 4923
7 97346
8 68889
9 39438
10 52280
11 53924
12 52709
13 89517
14 65425
15 58125
16 90680
17 19878
18 57533
19 86396
20 57326
21 77690
22 15600
23 13138
24 52111
25 21607
26 11387
27 98786
28 67947
29 90338
30 67334
31 9684
32 58446
33 94828
3...

output:

37670
69685
92969
5958
66654
73849
1961
100898
24685
93282
114575
93770
128991
22741
89985
94025
115600
85797
114687
51826
42881
95166
781
74173
34457
79306
69052
115127
7799
64463
54387
73689
126906
105702
23781
11098
103084
59293
85954
79852
1087
29204
128722
87608
23226
40972
66104
4696
56425
125...

result:

ok 94974 numbers

Test #17:

score: 0
Accepted
time: 40ms
memory: 12224kb

input:

100000 100000
2 16628
2 42347
5 38078
5 78073
8 56835
8 82731
10 36762
10 40527
15 15921
15 98834
16 71994
16 73602
21 26399
21 30847
22 59237
22 83483
23 50340
23 72830
26 59592
26 85979
27 9155
27 48315
30 24915
30 41832
31 23423
31 46868
34 11550
34 77075
35 32539
35 56959
37 31142
37 70317
39 83...

output:

82295
34770
34513
76200
74677
94149
29596
110385
222713
114227
59308
145028
238690
1993
128822
42915
261832
243896
235537
238652
157217
132330
131218
125090
62488
63851
130328
283973
143173
84739
404652
417760
120968
513339
335285
155288
308498
119567
437033
312669
197741
427965
227379
366315
364571...

result:

ok 50064 numbers

Test #18:

score: 0
Accepted
time: 39ms
memory: 12268kb

input:

100000 100000
1 63272
1 74378
2 35896
2 47165
5 27124
5 75486
6 23920
6 42369
7 30723
7 68872
12 40796
12 74665
13 73307
13 98082
15 7692
15 17887
17 50304
17 76015
19 9799
19 32584
22 15627
22 41601
23 40084
23 80453
24 40697
24 67981
32 74574
32 89369
33 28858
33 97177
37 63959
37 83917
39 92594
3...

output:

182833
55416
141122
212682
398324
412391
120693
133385
385923
48459
387405
260785
82827
920378
319195
106117
97042
208009
273065
938864
498439
34661
1076790
54128
400368
1851993
1883704
2060917
1682291
1076504
680314
65613
456425
381107
1640250
2736123
816151
3853639
2109219
1854984
635710
1114699
6...

result:

ok 5094 numbers

Test #19:

score: 0
Accepted
time: 39ms
memory: 12264kb

input:

100000 100000
1 28081
1 40384
4 46373
4 57859
5 12751
5 75064
6 63225
6 75904
7 33121
7 71235
8 45828
8 94885
10 24848
10 62132
11 51003
11 84531
12 88911
12 90115
13 16438
13 47065
16 66491
16 67166
18 17906
18 46108
19 53743
19 95153
20 74078
20 84657
21 64634
21 97091
22 16667
22 57846
24 4887
24...

output:

19969
19039
55632
113398
26306
114033
99291
87412
30437
29205
41547
118972
115696
52637
64163
122932
88711
9940
29874
15789
59567
85637
59564
1958
76079
100634
28903
94491
124455
18371
14930
42369
4563
3259
75943
11708
39561
85097
34292
34228
56418
107164
65388
96977
73589
18153
37330
91697
35505
13...

result:

ok 94959 numbers

Test #20:

score: 0
Accepted
time: 26ms
memory: 12264kb

input:

100000 100000
2 41009
2 89419
3 37786
3 48191
5 20739
5 43618
6 6698
6 25388
8 16276
8 31755
10 1943
10 84171
11 3414
11 59373
12 41245
12 57213
15 61433
15 69702
19 326
19 82337
23 10413
23 68840
24 27365
24 85099
25 25914
25 74444
31 42385
31 93147
34 23782
34 41355
35 85273
35 85385
38 1976
38 38...

output:

18786
69264
85718
55098
31717
98265
8155
125183
42410
102561
55161
66149
196054
241767
144235
230982
199649
131532
149417
166599
177631
186973
242951
71476
141793
184053
25606
103371
55751
24067
167791
162786
42127
86323
163308
116045
16630
255197
117317
228214
125554
451708
313297
396329
75245
8994...

result:

ok 50165 numbers

Test #21:

score: 0
Accepted
time: 23ms
memory: 12144kb

input:

100000 100000
1 75183
1 96071
2 3574
2 56914
3 16386
3 53207
7 10719
7 68635
8 4236
8 91788
11 5535
11 48395
15 111
15 48732
17 12543
17 98162
20 37821
20 99969
21 25245
21 50020
23 39645
23 90435
25 23673
25 92707
26 40203
26 65347
28 53584
28 59747
30 9477
30 13509
31 75432
31 84102
39 26470
39 78...

output:

115573
919112
980375
827811
317281
749855
1660853
2046555
1675945
1601941
1291621
1226943
1217005
1076598
1240149
803460
1553808
1829055
626555
41280
982234
782408
1155375
361404
982647
2614889
2392589
2297793
3268185
3062312
2854915
1537078
2158718
2819103
3981328
1518211
1077114
3894990
473221
366...

result:

ok 4955 numbers

Test #22:

score: 0
Accepted
time: 24ms
memory: 12268kb

input:

100000 100000
1 44888
1 87108
2 15136
2 36405
4 22248
4 60400
5 43770
5 54925
9 3781
9 9178
10 20024
10 35843
12 3595
12 23607
13 70105
13 85220
14 64846
14 74929
15 10615
15 61824
17 19762
17 26290
19 53530
19 63524
23 2425
23 90167
24 37838
24 58898
25 66936
25 95231
27 23
27 43828
29 4708
29 1730...

output:

119584
74915
75188
95884
34595
62099
108191
116294
130911
34800
58156
95765
45849
69700
47984
125379
89560
6568
113667
10837
30498
34405
122090
75188
23401
18217
3713
91838
46127
91973
122372
123015
110924
89418
91760
64196
27630
33944
85232
34806
95180
91319
108759
87714
85013
11313
53093
88922
100...

result:

ok 94907 numbers

Test #23:

score: 0
Accepted
time: 38ms
memory: 11972kb

input:

100000 100000
1 63909
2 25576
3 67761
4 86974
5 37852
6 93325
7 39925
8 40165
9 61221
10 61984
11 32109
12 26745
13 39106
14 33622
15 92371
16 73977
17 20720
18 87920
19 5927
20 15899
21 16575
22 95831
23 85607
24 52255
25 5382
26 9176
27 10939
28 88414
29 30256
30 79301
31 27653
32 41666
33 6084
34...

output:

3753
125585
86307
99120
182448
252118
228852
157291
217492
192166
261349
253439
219747
176013
176018
158766
209250
141612
247098
177253
181349
261397
197884
235976
187715
204761
145706
238024
185933
135609
182456
159815
322899
328258
287844
325573
374461
344695
301149
333749
313093
293245
371369
371...

result:

ok 50056 numbers

Test #24:

score: 0
Accepted
time: 36ms
memory: 12020kb

input:

100000 100000
1 49556
2 48814
3 79745
4 86999
5 2873
6 25415
7 56780
8 37118
9 22374
10 85290
11 64057
12 15259
13 871
14 98582
15 34135
16 98616
17 54366
18 85350
19 76927
20 17733
21 49450
22 73968
23 92915
24 40541
25 68621
26 28017
27 97569
28 26605
29 47483
30 75985
31 30805
32 65922
33 14900
3...

output:

122111
53447
287719
290451
410830
513074
535464
586241
610818
753965
943273
936165
1022163
951293
1117442
1342416
1386202
1430222
1696772
1627002
1682428
1894222
2029028
2361030
2408558
2448467
2591386
2758901
3530476
3528305
3418050
3595267
3545489
3767294
3787324
3897435
4008406
4049566
3993809
41...

result:

ok 4939 numbers

Test #25:

score: 0
Accepted
time: 35ms
memory: 12016kb

input:

100000 100000
1 74313
2 50210
3 83254
4 91937
5 17875
6 38846
7 54015
8 45988
9 47568
10 67419
11 73977
12 56
13 20994
14 30051
15 14131
16 56983
17 50746
18 52937
19 73314
20 68907
21 64127
22 27279
23 23339
24 24575
25 89472
26 60812
27 7728
28 74340
29 18759
30 18690
31 76550
32 38261
33 36842
34...

output:

66476
60779
38304
93134
56685
96886
32078
87598
121660
82629
57971
102660
65194
620
64533
25940
102671
29778
17490
77399
7236
32611
117636
17063
79006
97642
32635
75914
36265
127584
39813
110873
43809
12732
82988
107610
112219
23302
88674
110154
82277
115921
47260
99945
6772
93959
49317
112153
21949...

result:

ok 94981 numbers

Test #26:

score: 0
Accepted
time: 47ms
memory: 11884kb

input:

100000 100000
1 51489
2 15423
3 4013
4 38503
5 13916
6 49240
7 52434
8 71509
9 6080
10 71043
11 14712
12 20338
13 83811
14 77939
15 64364
16 69867
17 54005
18 28176
19 45526
20 8649
21 24797
22 147
23 44128
24 75489
25 80256
26 24921
27 57514
28 67878
29 58114
30 30420
31 16423
32 60528
33 75174
34 ...

output:

80136
87960
114810
24012
21036
77665
106156
25986
86407
46666
62275
35660
27784
19235
221170
248027
139950
253263
194328
6804
71337
89429
228130
126177
83558
46477
155193
208355
104319
57269
96961
40986
146011
93657
248994
213447
150322
113333
121729
73373
129130
31280
129619
81448
337402
209270
547...

result:

ok 49969 numbers

Test #27:

score: 0
Accepted
time: 45ms
memory: 11792kb

input:

100000 100000
1 13196
2 64570
3 31090
4 33618
5 86347
6 11414
7 53859
8 75678
9 8455
10 1552
11 47496
12 72401
13 98450
14 39992
15 46323
16 17641
17 8541
18 49071
19 98843
20 73494
21 30839
22 65569
23 74192
24 6573
25 29493
26 50770
27 88420
28 92219
29 67068
30 82008
31 23006
32 4926
33 26998
34 ...

output:

179125
17487
126960
455931
207877
218429
371124
808063
754222
244425
955380
335670
44469
578052
98089
872015
707015
503203
240714
2016785
1542444
2066116
1505444
1707754
1469575
1495735
829501
151246
1425451
12033
526040
1395450
3453118
4155144
3076351
3851654
3882783
1459468
652230
553288
3926376
1...

result:

ok 5084 numbers

Test #28:

score: 0
Accepted
time: 47ms
memory: 11976kb

input:

100000 100000
1 24219
2 91637
3 20573
4 79650
5 25897
6 40454
7 34870
8 97711
9 65333
10 99787
11 2796
12 18702
13 97314
14 55710
15 14672
16 67004
17 34400
18 37093
19 99643
20 85853
21 638
22 50648
23 85994
24 34218
25 17228
26 70597
27 92359
28 12294
29 99275
30 21115
31 90770
32 83706
33 81481
3...

output:

50751
124297
76605
76605
67852
55290
60713
55372
50655
76431
15723
72828
50243
65096
6331
8472
122300
48300
83974
29902
113978
125304
98066
9539
31116
53571
40926
12435
35882
60181
130395
4736
25394
8269
125032
105063
8556
49081
92063
45617
73988
90225
44148
115212
86648
31324
5995
39350
40226
98149...

result:

ok 94983 numbers

Test #29:

score: 0
Accepted
time: 1943ms
memory: 20440kb

input:

100000 100000
1 69809
1 72053
3 18119
4 71520
4 72157
5 23064
6 17925
7 64302
8 69294
9 27615
10 92682
11 40558
11 42400
12 58859
14 95774
15 89968
16 58994
18 23722
18 92731
19 42845
19 51911
20 35561
21 12754
22 26211
23 81737
25 34694
26 83965
27 19587
28 8639
28 49036
30 96478
32 940
33 61960
33...

output:

30556
72522
78124
113843
57144
126435
30550
90143
87376
119320
84369
49882
82286
99853
82100
101960
71575
97867
10732
18710
46133
109569
11709
7742
70237
78260
16664
118225
11251
100953
90459
112503
119689
57156
96429
26710
34545
122592
14546
49014
19283
66995
116470
47607
121906
60796
129405
123214...

result:

ok 98989 numbers

Test #30:

score: 0
Accepted
time: 1812ms
memory: 20724kb

input:

100000 100000
1 49379
3 28083
3 70229
5 39660
6 57058
6 94746
7 20565
7 96414
8 69298
8 90490
10 58404
11 48085
12 44444
13 15352
13 17767
15 28303
16 5904
19 19925
19 69021
20 42206
21 44028
22 18679
22 24264
23 83413
24 69791
25 57003
25 85140
26 29837
27 61451
27 96958
28 29930
30 88286
31 46363
...

output:

10059
87475
103350
92838
17396
105705
247922
227528
182487
202220
185760
148546
248371
143696
74057
230554
51286
253129
218422
90027
44913
4369
210079
219795
9213
173161
108679
184721
200918
12495
88343
88690
197516
522997
444014
156616
491317
471256
516066
414848
370909
294867
515425
503962
242303
...

result:

ok 45951 numbers

Test #31:

score: 0
Accepted
time: 1732ms
memory: 17816kb

input:

100000 100000
1 18987
3 32781
4 53391
4 64585
6 24116
6 86686
7 48312
7 79846
8 2157
8 82604
9 52043
10 89716
11 72688
13 3189
13 97723
14 73096
15 88218
16 35107
17 4652
18 70743
19 60724
20 30426
21 11969
21 86182
22 79698
23 23614
23 34154
24 15159
24 86579
26 61054
27 81158
28 65486
28 90798
29 ...

output:

66373
56736
65376
162381
3646501
178322
6936441
29843
7085828
2590794
7714034
2435706
13710467
44392
9262874
15340549
327674
16390921
11009184
8442606
13516534
9519882
210912
1268923
3646400
9115444
6848067
5836725
7226964
6673191
5968274
179808
29273105
31788549
11811452
10648554
23761451
24423543
...

result:

ok 976 numbers

Test #32:

score: 0
Accepted
time: 2901ms
memory: 24096kb

input:

100000 100000
1 11079
2 15995
3 47924
4 3591
5 8411
6 13882
7 29334
8 24186
9 27196
10 63732
11 3279
12 19768
13 83481
14 31031
15 35999
16 83873
17 96469
18 98413
19 22211
20 37831
21 50379
22 31619
23 28565
24 6593
25 26727
26 14711
27 628
28 54984
29 73509
30 28502
31 29359
32 42855
33 80984
34 7...

output:

103023
102984
15449
65856
24512
84058
40026
69305
92020
47570
44376
55764
76665
33689
69884
79999
24986
72356
115651
118242
31107
2657
103062
27461
113048
112755
128490
17316
55764
80350
21341
59452
119447
85121
97864
123723
123740
15376
88408
126315
53317
47754
64394
68368
42516
114575
71703
58150
...

result:

ok 98958 numbers

Test #33:

score: 0
Accepted
time: 2892ms
memory: 23740kb

input:

100000 100000
1 79482
2 30443
3 86716
4 53779
5 2947
6 2682
7 47316
8 76299
9 38662
10 72356
11 42679
12 12508
13 73634
14 73321
15 9316
16 17645
17 95041
18 22831
19 24877
20 33916
21 34881
22 31420
23 18063
24 47597
25 43580
26 84520
27 49348
28 93730
29 10513
30 28484
31 83350
32 89085
33 73522
3...

output:

70445
21630
86198
58579
48621
113999
34089
49674
94541
34089
28165
42711
94541
24856
117597
18524
62928
17994
23603
88387
104301
125546
17293
81490
72867
76825
60200
62267
56180
101471
93618
5411
66094
59585
130381
94780
76130
40389
4595
43011
75662
90487
1493
4375
53205
83581
35969
38707
75403
6553...

result:

ok 97981 numbers

Test #34:

score: 0
Accepted
time: 2902ms
memory: 23000kb

input:

100000 100000
1 35173
2 11056
3 59311
4 5517
5 37901
6 85538
7 64307
8 71136
9 69734
10 62124
11 77416
12 74833
13 24398
14 70920
15 25462
16 71596
17 41087
18 65795
19 40432
20 76216
21 90164
22 35420
23 35467
24 27451
25 65116
26 63395
27 52583
28 94957
29 64031
30 57250
31 63560
32 22215
33 56291...

output:

75504
116088
74722
104039
92354
90397
29006
64063
105592
53125
16009
76539
22339
77359
95682
97231
78668
93901
97987
69818
12044
67066
32678
51619
42721
81399
49877
86421
25592
124908
63516
27505
107693
81800
115346
39067
15894
82543
20540
86337
63388
119459
32131
20831
78354
117064
109328
48607
125...

result:

ok 96996 numbers

Test #35:

score: 0
Accepted
time: 2890ms
memory: 19608kb

input:

100000 100000
1 55301
2 408
3 25872
4 35066
5 79999
6 34236
7 95891
8 17003
9 78406
10 69677
11 93491
12 9619
13 12202
14 44866
15 91935
16 5140
17 42286
18 60362
19 5038
20 55997
21 57034
22 87113
23 34495
24 7828
25 77032
26 90799
27 67187
28 73174
29 91610
30 8287
31 71774
32 56584
33 63771
34 93...

output:

70349
114541
82096
111400
73348
125556
83466
84397
31184
111888
30427
101878
26095
46671
100049
50796
115295
86094
25931
106839
129432
91012
114520
12898
50513
112997
121012
8432
33340
11349
49863
70511
129038
37872
61454
129432
22967
69869
96429
130888
41493
107934
124
60566
1585
53418
57373
80245
...

result:

ok 96024 numbers

Test #36:

score: 0
Accepted
time: 2901ms
memory: 25652kb

input:

100000 100000
1 70213
2 95777
3 67917
4 1388
5 97937
6 63139
7 30594
8 62612
9 7143
10 8251
11 6263
12 19868
13 57236
14 20804
15 41143
16 44161
17 99674
18 29925
19 1370
20 84598
21 43543
22 64234
23 36345
24 91787
25 25679
26 96792
27 67054
28 59686
29 10933
30 39783
31 18010
32 69906
33 43314
34 ...

output:

49534
22645
108086
62928
56042
6596
48300
8304
92559
127783
65485
10901
58219
89865
59682
95105
5640
72748
17081
93819
47157
111330
55133
35971
59233
45083
66508
69659
17627
99888
95785
108407
78627
1507
122496
94777
56288
19233
120752
22700
59641
75075
14594
42226
9234
29644
72748
115669
124482
454...

result:

ok 99895 numbers

Extra Test:

score: 0
Extra Test Passed