QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#789445 | #9608. 皮鞋的多项式 | grass8cow | 100 ✓ | 1490ms | 228232kb | C++17 | 64.9kb | 2024-11-27 20:22:32 | 2024-11-27 20:22:37 |
Judging History
answer
#include <algorithm>
#include <array>
#include <cassert>
#include <type_traits>
#include <vector>
#ifdef _MSC_VER
#include <intrin.h>
#endif
#if __cplusplus >= 202002L
#include <bit>
#endif
namespace atcoder {
namespace internal {
#if __cplusplus >= 202002L
using std::bit_ceil;
#else
unsigned int bit_ceil(unsigned int n) {
unsigned int x = 1;
while (x < (unsigned int)(n)) x *= 2;
return x;
}
#endif
int countr_zero(unsigned int n) {
#ifdef _MSC_VER
unsigned long index;
_BitScanForward(&index, n);
return index;
#else
return __builtin_ctz(n);
#endif
}
constexpr int countr_zero_constexpr(unsigned int n) {
int x = 0;
while (!(n & (1 << x))) x++;
return x;
}
} // namespace internal
} // namespace atcoder
#include <cassert>
#include <numeric>
#include <type_traits>
#ifdef _MSC_VER
#include <intrin.h>
#endif
#include <utility>
#ifdef _MSC_VER
#include <intrin.h>
#endif
namespace atcoder {
namespace internal {
constexpr long long safe_mod(long long x, long long m) {
x %= m;
if (x < 0) x += m;
return x;
}
struct barrett {
unsigned int _m;
unsigned long long im;
explicit barrett(unsigned int m) : _m(m), im((unsigned long long)(-1) / m + 1) {}
unsigned int umod() const { return _m; }
unsigned int mul(unsigned int a, unsigned int b) const {
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 long long y = x * _m;
return (unsigned int)(z - y + (z < y ? _m : 0));
}
};
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;
}
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;
constexpr long long bases[3] = {2, 7, 61};
for (long long a : bases) {
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);
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};
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
auto tmp = s;
s = t;
t = tmp;
tmp = m0;
m0 = m1;
m1 = tmp;
}
if (m0 < 0) m0 += b / s;
return {s, m0};
}
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);
unsigned long long floor_sum_unsigned(unsigned long long n,
unsigned long long m,
unsigned long long a,
unsigned long long b) {
unsigned long long ans = 0;
while (true) {
if (a >= m) {
ans += n * (n - 1) / 2 * (a / m);
a %= m;
}
if (b >= m) {
ans += n * (b / m);
b %= m;
}
unsigned long long y_max = a * n + b;
if (y_max < m) break;
n = (unsigned long long)(y_max / m);
b = (unsigned long long)(y_max % m);
std::swap(m, a);
}
return ans;
}
} // namespace internal
} // namespace atcoder
#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
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());
}
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());
}
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
namespace atcoder {
namespace internal {
template <class mint,
int g = internal::primitive_root<mint::mod()>,
internal::is_static_modint_t<mint>* = nullptr>
struct fft_info {
static constexpr int rank2 = countr_zero_constexpr(mint::mod() - 1);
std::array<mint, rank2 + 1> root; // root[i]^(2^i) == 1
std::array<mint, rank2 + 1> iroot; // root[i] * iroot[i] == 1
std::array<mint, std::max(0, rank2 - 2 + 1)> rate2;
std::array<mint, std::max(0, rank2 - 2 + 1)> irate2;
std::array<mint, std::max(0, rank2 - 3 + 1)> rate3;
std::array<mint, std::max(0, rank2 - 3 + 1)> irate3;
fft_info() {
root[rank2] = mint(g).pow((mint::mod() - 1) >> rank2);
iroot[rank2] = root[rank2].inv();
for (int i = rank2 - 1; i >= 0; i--) {
root[i] = root[i + 1] * root[i + 1];
iroot[i] = iroot[i + 1] * iroot[i + 1];
}
{
mint prod = 1, iprod = 1;
for (int i = 0; i <= rank2 - 2; i++) {
rate2[i] = root[i + 2] * prod;
irate2[i] = iroot[i + 2] * iprod;
prod *= iroot[i + 2];
iprod *= root[i + 2];
}
}
{
mint prod = 1, iprod = 1;
for (int i = 0; i <= rank2 - 3; i++) {
rate3[i] = root[i + 3] * prod;
irate3[i] = iroot[i + 3] * iprod;
prod *= iroot[i + 3];
iprod *= root[i + 3];
}
}
}
};
template <class mint, internal::is_static_modint_t<mint>* = nullptr>
void butterfly(std::vector<mint>& a) {
int n = int(a.size());
int h = internal::countr_zero((unsigned int)n);
static const fft_info<mint> info;
int len = 0; // a[i, i+(n>>len), i+2*(n>>len), ..] is transformed
while (len < h) {
if (h - len == 1) {
int p = 1 << (h - len - 1);
mint rot = 1;
for (int s = 0; s < (1 << len); s++) {
int offset = s << (h - len);
for (int i = 0; i < p; i++) {
auto l = a[i + offset];
auto r = a[i + offset + p] * rot;
a[i + offset] = l + r;
a[i + offset + p] = l - r;
}
if (s + 1 != (1 << len))
rot *= info.rate2[countr_zero(~(unsigned int)(s))];
}
len++;
} else {
int p = 1 << (h - len - 2);
mint rot = 1, imag = info.root[2];
for (int s = 0; s < (1 << len); s++) {
mint rot2 = rot * rot;
mint rot3 = rot2 * rot;
int offset = s << (h - len);
for (int i = 0; i < p; i++) {
auto mod2 = 1ULL * mint::mod() * mint::mod();
auto a0 = 1ULL * a[i + offset].val();
auto a1 = 1ULL * a[i + offset + p].val() * rot.val();
auto a2 = 1ULL * a[i + offset + 2 * p].val() * rot2.val();
auto a3 = 1ULL * a[i + offset + 3 * p].val() * rot3.val();
auto a1na3imag =
1ULL * mint(a1 + mod2 - a3).val() * imag.val();
auto na2 = mod2 - a2;
a[i + offset] = a0 + a2 + a1 + a3;
a[i + offset + 1 * p] = a0 + a2 + (2 * mod2 - (a1 + a3));
a[i + offset + 2 * p] = a0 + na2 + a1na3imag;
a[i + offset + 3 * p] = a0 + na2 + (mod2 - a1na3imag);
}
if (s + 1 != (1 << len))
rot *= info.rate3[countr_zero(~(unsigned int)(s))];
}
len += 2;
}
}
}
template <class mint, internal::is_static_modint_t<mint>* = nullptr>
void butterfly_inv(std::vector<mint>& a) {
int n = int(a.size());
int h = internal::countr_zero((unsigned int)n);
static const fft_info<mint> info;
int len = h; // a[i, i+(n>>len), i+2*(n>>len), ..] is transformed
while (len) {
if (len == 1) {
int p = 1 << (h - len);
mint irot = 1;
for (int s = 0; s < (1 << (len - 1)); s++) {
int offset = s << (h - len + 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()) *
irot.val();
;
}
if (s + 1 != (1 << (len - 1)))
irot *= info.irate2[countr_zero(~(unsigned int)(s))];
}
len--;
} else {
int p = 1 << (h - len);
mint irot = 1, iimag = info.iroot[2];
for (int s = 0; s < (1 << (len - 2)); s++) {
mint irot2 = irot * irot;
mint irot3 = irot2 * irot;
int offset = s << (h - len + 2);
for (int i = 0; i < p; i++) {
auto a0 = 1ULL * a[i + offset + 0 * p].val();
auto a1 = 1ULL * a[i + offset + 1 * p].val();
auto a2 = 1ULL * a[i + offset + 2 * p].val();
auto a3 = 1ULL * a[i + offset + 3 * p].val();
auto a2na3iimag =
1ULL *
mint((mint::mod() + a2 - a3) * iimag.val()).val();
a[i + offset] = a0 + a1 + a2 + a3;
a[i + offset + 1 * p] =
(a0 + (mint::mod() - a1) + a2na3iimag) * irot.val();
a[i + offset + 2 * p] =
(a0 + a1 + (mint::mod() - a2) + (mint::mod() - a3)) *
irot2.val();
a[i + offset + 3 * p] =
(a0 + (mint::mod() - a1) + (mint::mod() - a2na3iimag)) *
irot3.val();
}
if (s + 1 != (1 << (len - 2)))
irot *= info.irate3[countr_zero(~(unsigned int)(s))];
}
len -= 2;
}
}
}
template <class mint, internal::is_static_modint_t<mint>* = nullptr>
std::vector<mint> convolution_naive(const std::vector<mint>& a,
const std::vector<mint>& b) {
int n = int(a.size()), m = int(b.size());
std::vector<mint> ans(n + m - 1);
if (n < m) {
for (int j = 0; j < m; j++) {
for (int i = 0; i < n; i++) {
ans[i + j] += a[i] * b[j];
}
}
} else {
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
ans[i + j] += a[i] * b[j];
}
}
}
return ans;
}
template <class mint, internal::is_static_modint_t<mint>* = nullptr>
std::vector<mint> convolution_fft(std::vector<mint> a, std::vector<mint> b) {
int n = int(a.size()), m = int(b.size());
int z = (int)internal::bit_ceil((unsigned int)(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;
}
} // 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 {};
int z = (int)internal::bit_ceil((unsigned int)(n + m - 1));
assert((mint::mod() - 1) % z == 0);
if (std::min(n, m) <= 60) return convolution_naive(a, b);
return internal::convolution_fft(a, b);
}
template <class mint, internal::is_static_modint_t<mint>* = nullptr>
std::vector<mint> convolution(const std::vector<mint>& a,
const std::vector<mint>& b) {
int n = int(a.size()), m = int(b.size());
if (!n || !m) return {};
int z = (int)internal::bit_ceil((unsigned int)(n + m - 1));
assert((mint::mod() - 1) % z == 0);
if (std::min(n, m) <= 60) return convolution_naive(a, b);
return internal::convolution_fft(a, b);
}
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>;
int z = (int)internal::bit_ceil((unsigned int)(n + m - 1));
assert((mint::mod() - 1) % z == 0);
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(std::move(a2), std::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;
static constexpr int MAX_AB_BIT = 24;
static_assert(MOD1 % (1ull << MAX_AB_BIT) == 1, "MOD1 isn't enough to support an array length of 2^24.");
static_assert(MOD2 % (1ull << MAX_AB_BIT) == 1, "MOD2 isn't enough to support an array length of 2^24.");
static_assert(MOD3 % (1ull << MAX_AB_BIT) == 1, "MOD3 isn't enough to support an array length of 2^24.");
assert(n + m - 1 <= (1 << MAX_AB_BIT));
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;
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
#include <algorithm>
#include <cassert>
#include <vector>
namespace atcoder {
struct dsu {
public:
dsu() : _n(0) {}
explicit dsu(int n) : _n(n), parent_or_size(n, -1) {}
int merge(int a, int b) {
assert(0 <= a && a < _n);
assert(0 <= b && b < _n);
int x = leader(a), y = leader(b);
if (x == y) return x;
if (-parent_or_size[x] < -parent_or_size[y]) std::swap(x, y);
parent_or_size[x] += parent_or_size[y];
parent_or_size[y] = x;
return x;
}
bool same(int a, int b) {
assert(0 <= a && a < _n);
assert(0 <= b && b < _n);
return leader(a) == leader(b);
}
int leader(int a) {
assert(0 <= a && a < _n);
if (parent_or_size[a] < 0) return a;
return parent_or_size[a] = leader(parent_or_size[a]);
}
int size(int a) {
assert(0 <= a && a < _n);
return -parent_or_size[leader(a)];
}
std::vector<std::vector<int>> groups() {
std::vector<int> leader_buf(_n), group_size(_n);
for (int i = 0; i < _n; i++) {
leader_buf[i] = leader(i);
group_size[leader_buf[i]]++;
}
std::vector<std::vector<int>> result(_n);
for (int i = 0; i < _n; i++) {
result[i].reserve(group_size[i]);
}
for (int i = 0; i < _n; i++) {
result[leader_buf[i]].push_back(i);
}
result.erase(
std::remove_if(result.begin(), result.end(),
[&](const std::vector<int>& v) { return v.empty(); }),
result.end());
return result;
}
private:
int _n;
std::vector<int> parent_or_size;
};
} // namespace atcoder
#include <cassert>
#include <vector>
namespace atcoder {
template <class T> struct fenwick_tree {
using U = internal::to_unsigned_t<T>;
public:
fenwick_tree() : _n(0) {}
explicit fenwick_tree(int n) : _n(n), data(n) {}
void add(int p, T x) {
assert(0 <= p && p < _n);
p++;
while (p <= _n) {
data[p - 1] += U(x);
p += p & -p;
}
}
T sum(int l, int r) {
assert(0 <= l && l <= r && r <= _n);
return sum(r) - sum(l);
}
private:
int _n;
std::vector<U> data;
U sum(int r) {
U s = 0;
while (r > 0) {
s += data[r - 1];
r -= r & -r;
}
return s;
}
};
} // namespace atcoder
#include <algorithm>
#include <cassert>
#include <functional>
#include <vector>
namespace atcoder {
#if __cplusplus >= 201703L
template <class S,
auto op,
auto e,
class F,
auto mapping,
auto composition,
auto id>
struct lazy_segtree {
static_assert(std::is_convertible_v<decltype(op), std::function<S(S, S)>>,
"op must work as S(S, S)");
static_assert(std::is_convertible_v<decltype(e), std::function<S()>>,
"e must work as S()");
static_assert(
std::is_convertible_v<decltype(mapping), std::function<S(F, S)>>,
"mapping must work as F(F, S)");
static_assert(
std::is_convertible_v<decltype(composition), std::function<F(F, F)>>,
"compostiion must work as F(F, F)");
static_assert(std::is_convertible_v<decltype(id), std::function<F()>>,
"id must work as F()");
#else
template <class S,
S (*op)(S, S),
S (*e)(),
class F,
S (*mapping)(F, S),
F (*composition)(F, F),
F (*id)()>
struct lazy_segtree {
#endif
public:
lazy_segtree() : lazy_segtree(0) {}
explicit lazy_segtree(int n) : lazy_segtree(std::vector<S>(n, e())) {}
explicit lazy_segtree(const std::vector<S>& v) : _n(int(v.size())) {
size = (int)internal::bit_ceil((unsigned int)(_n));
log = internal::countr_zero((unsigned int)size);
d = std::vector<S>(2 * size, e());
lz = std::vector<F>(size, id());
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;
for (int i = log; i >= 1; i--) push(p >> i);
d[p] = x;
for (int i = 1; i <= log; i++) update(p >> i);
}
S get(int p) {
assert(0 <= p && p < _n);
p += size;
for (int i = log; i >= 1; i--) push(p >> i);
return d[p];
}
S prod(int l, int r) {
assert(0 <= l && l <= r && r <= _n);
if (l == r) return e();
l += size;
r += size;
for (int i = log; i >= 1; i--) {
if (((l >> i) << i) != l) push(l >> i);
if (((r >> i) << i) != r) push((r - 1) >> i);
}
S sml = e(), smr = e();
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]; }
void apply(int p, F f) {
assert(0 <= p && p < _n);
p += size;
for (int i = log; i >= 1; i--) push(p >> i);
d[p] = mapping(f, d[p]);
for (int i = 1; i <= log; i++) update(p >> i);
}
void apply(int l, int r, F f) {
assert(0 <= l && l <= r && r <= _n);
if (l == r) return;
l += size;
r += size;
for (int i = log; i >= 1; i--) {
if (((l >> i) << i) != l) push(l >> i);
if (((r >> i) << i) != r) push((r - 1) >> i);
}
{
int l2 = l, r2 = r;
while (l < r) {
if (l & 1) all_apply(l++, f);
if (r & 1) all_apply(--r, f);
l >>= 1;
r >>= 1;
}
l = l2;
r = r2;
}
for (int i = 1; i <= log; i++) {
if (((l >> i) << i) != l) update(l >> i);
if (((r >> i) << i) != r) update((r - 1) >> i);
}
}
template <bool (*g)(S)> int max_right(int l) {
return max_right(l, [](S x) { return g(x); });
}
template <class G> int max_right(int l, G g) {
assert(0 <= l && l <= _n);
assert(g(e()));
if (l == _n) return _n;
l += size;
for (int i = log; i >= 1; i--) push(l >> i);
S sm = e();
do {
while (l % 2 == 0) l >>= 1;
if (!g(op(sm, d[l]))) {
while (l < size) {
push(l);
l = (2 * l);
if (g(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 (*g)(S)> int min_left(int r) {
return min_left(r, [](S x) { return g(x); });
}
template <class G> int min_left(int r, G g) {
assert(0 <= r && r <= _n);
assert(g(e()));
if (r == 0) return 0;
r += size;
for (int i = log; i >= 1; i--) push((r - 1) >> i);
S sm = e();
do {
r--;
while (r > 1 && (r % 2)) r >>= 1;
if (!g(op(d[r], sm))) {
while (r < size) {
push(r);
r = (2 * r + 1);
if (g(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;
std::vector<F> lz;
void update(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); }
void all_apply(int k, F f) {
d[k] = mapping(f, d[k]);
if (k < size) lz[k] = composition(f, lz[k]);
}
void push(int k) {
all_apply(2 * k, lz[k]);
all_apply(2 * k + 1, lz[k]);
lz[k] = id();
}
};
} // namespace atcoder
#include <algorithm>
#include <cassert>
#include <tuple>
#include <vector>
namespace atcoder {
long long pow_mod(long long x, long long n, int m) {
assert(0 <= n && 1 <= m);
if (m == 1) return 0;
internal::barrett bt((unsigned int)(m));
unsigned int r = 1, y = (unsigned int)(internal::safe_mod(x, m));
while (n) {
if (n & 1) r = bt.mul(r, y);
y = bt.mul(y, y);
n >>= 1;
}
return r;
}
long long inv_mod(long long x, long long m) {
assert(1 <= m);
auto z = internal::inv_gcd(x, m);
assert(z.first == 1);
return z.second;
}
std::pair<long long, long long> crt(const std::vector<long long>& r,
const std::vector<long long>& m) {
assert(r.size() == m.size());
int n = int(r.size());
long long r0 = 0, m0 = 1;
for (int i = 0; i < n; i++) {
assert(1 <= m[i]);
long long r1 = internal::safe_mod(r[i], m[i]), m1 = m[i];
if (m0 < m1) {
std::swap(r0, r1);
std::swap(m0, m1);
}
if (m0 % m1 == 0) {
if (r0 % m1 != r1) return {0, 0};
continue;
}
long long g, im;
std::tie(g, im) = internal::inv_gcd(m0, m1);
long long u1 = (m1 / g);
if ((r1 - r0) % g) return {0, 0};
long long x = (r1 - r0) / g % u1 * im % u1;
r0 += x * m0;
m0 *= u1; // -> lcm(m0, m1)
if (r0 < 0) r0 += m0;
}
return {r0, m0};
}
long long floor_sum(long long n, long long m, long long a, long long b) {
assert(0 <= n && n < (1LL << 32));
assert(1 <= m && m < (1LL << 32));
unsigned long long ans = 0;
if (a < 0) {
unsigned long long a2 = internal::safe_mod(a, m);
ans -= 1ULL * n * (n - 1) / 2 * ((a2 - a) / m);
a = a2;
}
if (b < 0) {
unsigned long long b2 = internal::safe_mod(b, m);
ans -= 1ULL * n * ((b2 - b) / m);
b = b2;
}
return ans + internal::floor_sum_unsigned(n, m, a, b);
}
} // namespace atcoder
#include <algorithm>
#include <cassert>
#include <limits>
#include <queue>
#include <vector>
#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
namespace atcoder {
template <class Cap> struct mf_graph {
public:
mf_graph() : _n(0) {}
explicit mf_graph(int n) : _n(n), g(n) {}
int add_edge(int from, int to, Cap cap) {
assert(0 <= from && from < _n);
assert(0 <= to && to < _n);
assert(0 <= cap);
int m = int(pos.size());
pos.push_back({from, int(g[from].size())});
int from_id = int(g[from].size());
int to_id = int(g[to].size());
if (from == to) to_id++;
g[from].push_back(_edge{to, to_id, cap});
g[to].push_back(_edge{from, from_id, 0});
return m;
}
struct edge {
int from, to;
Cap cap, flow;
};
edge get_edge(int i) {
int m = int(pos.size());
assert(0 <= i && i < m);
auto _e = g[pos[i].first][pos[i].second];
auto _re = g[_e.to][_e.rev];
return edge{pos[i].first, _e.to, _e.cap + _re.cap, _re.cap};
}
std::vector<edge> edges() {
int m = int(pos.size());
std::vector<edge> result;
for (int i = 0; i < m; i++) {
result.push_back(get_edge(i));
}
return result;
}
void change_edge(int i, Cap new_cap, Cap new_flow) {
int m = int(pos.size());
assert(0 <= i && i < m);
assert(0 <= new_flow && new_flow <= new_cap);
auto& _e = g[pos[i].first][pos[i].second];
auto& _re = g[_e.to][_e.rev];
_e.cap = new_cap - new_flow;
_re.cap = new_flow;
}
Cap flow(int s, int t) {
return flow(s, t, std::numeric_limits<Cap>::max());
}
Cap flow(int s, int t, Cap flow_limit) {
assert(0 <= s && s < _n);
assert(0 <= t && t < _n);
assert(s != t);
std::vector<int> level(_n), iter(_n);
internal::simple_queue<int> que;
auto bfs = [&]() {
std::fill(level.begin(), level.end(), -1);
level[s] = 0;
que.clear();
que.push(s);
while (!que.empty()) {
int v = que.front();
que.pop();
for (auto e : g[v]) {
if (e.cap == 0 || level[e.to] >= 0) continue;
level[e.to] = level[v] + 1;
if (e.to == t) return;
que.push(e.to);
}
}
};
auto dfs = [&](auto self, int v, Cap up) {
if (v == s) return up;
Cap res = 0;
int level_v = level[v];
for (int& i = iter[v]; i < int(g[v].size()); i++) {
_edge& e = g[v][i];
if (level_v <= level[e.to] || g[e.to][e.rev].cap == 0) continue;
Cap d =
self(self, e.to, std::min(up - res, g[e.to][e.rev].cap));
if (d <= 0) continue;
g[v][i].cap += d;
g[e.to][e.rev].cap -= d;
res += d;
if (res == up) return res;
}
level[v] = _n;
return res;
};
Cap flow = 0;
while (flow < flow_limit) {
bfs();
if (level[t] == -1) break;
std::fill(iter.begin(), iter.end(), 0);
Cap f = dfs(dfs, t, flow_limit - flow);
if (!f) break;
flow += f;
}
return flow;
}
std::vector<bool> min_cut(int s) {
std::vector<bool> visited(_n);
internal::simple_queue<int> que;
que.push(s);
while (!que.empty()) {
int p = que.front();
que.pop();
visited[p] = true;
for (auto e : g[p]) {
if (e.cap && !visited[e.to]) {
visited[e.to] = true;
que.push(e.to);
}
}
}
return visited;
}
private:
int _n;
struct _edge {
int to, rev;
Cap cap;
};
std::vector<std::pair<int, int>> pos;
std::vector<std::vector<_edge>> g;
};
} // namespace atcoder
#include <algorithm>
#include <cassert>
#include <limits>
#include <queue>
#include <vector>
#include <algorithm>
#include <utility>
#include <vector>
namespace atcoder {
namespace internal {
template <class E> struct csr {
std::vector<int> start;
std::vector<E> elist;
explicit 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;
}
}
};
} // namespace internal
} // namespace atcoder
namespace atcoder {
template <class Cap, class Cost> struct mcf_graph {
public:
mcf_graph() {}
explicit mcf_graph(int n) : _n(n) {}
int add_edge(int from, int to, Cap cap, Cost cost) {
assert(0 <= from && from < _n);
assert(0 <= to && to < _n);
assert(0 <= cap);
assert(0 <= cost);
int m = int(_edges.size());
_edges.push_back({from, to, cap, 0, cost});
return m;
}
struct edge {
int from, to;
Cap cap, flow;
Cost cost;
};
edge get_edge(int i) {
int m = int(_edges.size());
assert(0 <= i && i < m);
return _edges[i];
}
std::vector<edge> edges() { return _edges; }
std::pair<Cap, Cost> flow(int s, int t) {
return flow(s, t, std::numeric_limits<Cap>::max());
}
std::pair<Cap, Cost> flow(int s, int t, Cap flow_limit) {
return slope(s, t, flow_limit).back();
}
std::vector<std::pair<Cap, Cost>> slope(int s, int t) {
return slope(s, t, std::numeric_limits<Cap>::max());
}
std::vector<std::pair<Cap, Cost>> slope(int s, int t, Cap flow_limit) {
assert(0 <= s && s < _n);
assert(0 <= t && t < _n);
assert(s != t);
int m = int(_edges.size());
std::vector<int> edge_idx(m);
auto g = [&]() {
std::vector<int> degree(_n), redge_idx(m);
std::vector<std::pair<int, _edge>> elist;
elist.reserve(2 * m);
for (int i = 0; i < m; i++) {
auto e = _edges[i];
edge_idx[i] = degree[e.from]++;
redge_idx[i] = degree[e.to]++;
elist.push_back({e.from, {e.to, -1, e.cap - e.flow, e.cost}});
elist.push_back({e.to, {e.from, -1, e.flow, -e.cost}});
}
auto _g = internal::csr<_edge>(_n, elist);
for (int i = 0; i < m; i++) {
auto e = _edges[i];
edge_idx[i] += _g.start[e.from];
redge_idx[i] += _g.start[e.to];
_g.elist[edge_idx[i]].rev = redge_idx[i];
_g.elist[redge_idx[i]].rev = edge_idx[i];
}
return _g;
}();
auto result = slope(g, s, t, flow_limit);
for (int i = 0; i < m; i++) {
auto e = g.elist[edge_idx[i]];
_edges[i].flow = _edges[i].cap - e.cap;
}
return result;
}
private:
int _n;
std::vector<edge> _edges;
struct _edge {
int to, rev;
Cap cap;
Cost cost;
};
std::vector<std::pair<Cap, Cost>> slope(internal::csr<_edge>& g,
int s,
int t,
Cap flow_limit) {
std::vector<std::pair<Cost, Cost>> dual_dist(_n);
std::vector<int> prev_e(_n);
std::vector<bool> vis(_n);
struct Q {
Cost key;
int to;
bool operator<(Q r) const { return key > r.key; }
};
std::vector<int> que_min;
std::vector<Q> que;
auto dual_ref = [&]() {
for (int i = 0; i < _n; i++) {
dual_dist[i].second = std::numeric_limits<Cost>::max();
}
std::fill(vis.begin(), vis.end(), false);
que_min.clear();
que.clear();
size_t heap_r = 0;
dual_dist[s].second = 0;
que_min.push_back(s);
while (!que_min.empty() || !que.empty()) {
int v;
if (!que_min.empty()) {
v = que_min.back();
que_min.pop_back();
} else {
while (heap_r < que.size()) {
heap_r++;
std::push_heap(que.begin(), que.begin() + heap_r);
}
v = que.front().to;
std::pop_heap(que.begin(), que.end());
que.pop_back();
heap_r--;
}
if (vis[v]) continue;
vis[v] = true;
if (v == t) break;
Cost dual_v = dual_dist[v].first, dist_v = dual_dist[v].second;
for (int i = g.start[v]; i < g.start[v + 1]; i++) {
auto e = g.elist[i];
if (!e.cap) continue;
Cost cost = e.cost - dual_dist[e.to].first + dual_v;
if (dual_dist[e.to].second - dist_v > cost) {
Cost dist_to = dist_v + cost;
dual_dist[e.to].second = dist_to;
prev_e[e.to] = e.rev;
if (dist_to == dist_v) {
que_min.push_back(e.to);
} else {
que.push_back(Q{dist_to, e.to});
}
}
}
}
if (!vis[t]) {
return false;
}
for (int v = 0; v < _n; v++) {
if (!vis[v]) continue;
dual_dist[v].first -= dual_dist[t].second - dual_dist[v].second;
}
return true;
};
Cap flow = 0;
Cost cost = 0, prev_cost_per_flow = -1;
std::vector<std::pair<Cap, Cost>> result = {{Cap(0), Cost(0)}};
while (flow < flow_limit) {
if (!dual_ref()) break;
Cap c = flow_limit - flow;
for (int v = t; v != s; v = g.elist[prev_e[v]].to) {
c = std::min(c, g.elist[g.elist[prev_e[v]].rev].cap);
}
for (int v = t; v != s; v = g.elist[prev_e[v]].to) {
auto& e = g.elist[prev_e[v]];
e.cap += c;
g.elist[e.rev].cap -= c;
}
Cost d = -dual_dist[s].first;
flow += c;
cost += c * d;
if (prev_cost_per_flow == d) {
result.pop_back();
}
result.push_back({flow, cost});
prev_cost_per_flow = d;
}
return result;
}
};
} // namespace atcoder
#include <algorithm>
#include <cassert>
#include <vector>
#include <algorithm>
#include <utility>
#include <vector>
namespace atcoder {
namespace internal {
struct scc_graph {
public:
explicit scc_graph(int n) : _n(n) {}
int num_vertices() { return _n; }
void add_edge(int from, int to) { edges.push_back({from, {to}}); }
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
namespace atcoder {
struct scc_graph {
public:
scc_graph() : internal(0) {}
explicit scc_graph(int n) : internal(n) {}
void add_edge(int from, int to) {
int n = internal.num_vertices();
assert(0 <= from && from < n);
assert(0 <= to && to < n);
internal.add_edge(from, to);
}
std::vector<std::vector<int>> scc() { return internal.scc(); }
private:
internal::scc_graph internal;
};
} // namespace atcoder
#include <algorithm>
#include <cassert>
#include <functional>
#include <vector>
namespace atcoder {
#if __cplusplus >= 201703L
template <class S, auto op, auto e> struct segtree {
static_assert(std::is_convertible_v<decltype(op), std::function<S(S, S)>>,
"op must work as S(S, S)");
static_assert(std::is_convertible_v<decltype(e), std::function<S()>>,
"e must work as S()");
#else
template <class S, S (*op)(S, S), S (*e)()> struct segtree {
#endif
public:
segtree() : segtree(0) {}
explicit segtree(int n) : segtree(std::vector<S>(n, e())) {}
explicit segtree(const std::vector<S>& v) : _n(int(v.size())) {
size = (int)internal::bit_ceil((unsigned int)(_n));
log = internal::countr_zero((unsigned int)size);
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) const {
assert(0 <= p && p < _n);
return d[p + size];
}
S prod(int l, int r) const {
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() const { return d[1]; }
template <bool (*f)(S)> int max_right(int l) const {
return max_right(l, [](S x) { return f(x); });
}
template <class F> int max_right(int l, F f) const {
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) const {
return min_left(r, [](S x) { return f(x); });
}
template <class F> int min_left(int r, F f) const {
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
#include <algorithm>
#include <cassert>
#include <numeric>
#include <string>
#include <vector>
namespace atcoder {
namespace internal {
std::vector<int> sa_naive(const std::vector<int>& s) {
int n = int(s.size());
std::vector<int> sa(n);
std::iota(sa.begin(), sa.end(), 0);
std::sort(sa.begin(), sa.end(), [&](int l, int r) {
if (l == r) return false;
while (l < n && r < n) {
if (s[l] != s[r]) return s[l] < s[r];
l++;
r++;
}
return l == n;
});
return sa;
}
std::vector<int> sa_doubling(const std::vector<int>& s) {
int n = int(s.size());
std::vector<int> sa(n), rnk = s, tmp(n);
std::iota(sa.begin(), sa.end(), 0);
for (int k = 1; k < n; k *= 2) {
auto cmp = [&](int x, int y) {
if (rnk[x] != rnk[y]) return rnk[x] < rnk[y];
int rx = x + k < n ? rnk[x + k] : -1;
int ry = y + k < n ? rnk[y + k] : -1;
return rx < ry;
};
std::sort(sa.begin(), sa.end(), cmp);
tmp[sa[0]] = 0;
for (int i = 1; i < n; i++) {
tmp[sa[i]] = tmp[sa[i - 1]] + (cmp(sa[i - 1], sa[i]) ? 1 : 0);
}
std::swap(tmp, rnk);
}
return sa;
}
template <int THRESHOLD_NAIVE = 10, int THRESHOLD_DOUBLING = 40>
std::vector<int> sa_is(const std::vector<int>& s, int upper) {
int n = int(s.size());
if (n == 0) return {};
if (n == 1) return {0};
if (n == 2) {
if (s[0] < s[1]) {
return {0, 1};
} else {
return {1, 0};
}
}
if (n < THRESHOLD_NAIVE) {
return sa_naive(s);
}
if (n < THRESHOLD_DOUBLING) {
return sa_doubling(s);
}
std::vector<int> sa(n);
std::vector<bool> ls(n);
for (int i = n - 2; i >= 0; i--) {
ls[i] = (s[i] == s[i + 1]) ? ls[i + 1] : (s[i] < s[i + 1]);
}
std::vector<int> sum_l(upper + 1), sum_s(upper + 1);
for (int i = 0; i < n; i++) {
if (!ls[i]) {
sum_s[s[i]]++;
} else {
sum_l[s[i] + 1]++;
}
}
for (int i = 0; i <= upper; i++) {
sum_s[i] += sum_l[i];
if (i < upper) sum_l[i + 1] += sum_s[i];
}
auto induce = [&](const std::vector<int>& lms) {
std::fill(sa.begin(), sa.end(), -1);
std::vector<int> buf(upper + 1);
std::copy(sum_s.begin(), sum_s.end(), buf.begin());
for (auto d : lms) {
if (d == n) continue;
sa[buf[s[d]]++] = d;
}
std::copy(sum_l.begin(), sum_l.end(), buf.begin());
sa[buf[s[n - 1]]++] = n - 1;
for (int i = 0; i < n; i++) {
int v = sa[i];
if (v >= 1 && !ls[v - 1]) {
sa[buf[s[v - 1]]++] = v - 1;
}
}
std::copy(sum_l.begin(), sum_l.end(), buf.begin());
for (int i = n - 1; i >= 0; i--) {
int v = sa[i];
if (v >= 1 && ls[v - 1]) {
sa[--buf[s[v - 1] + 1]] = v - 1;
}
}
};
std::vector<int> lms_map(n + 1, -1);
int m = 0;
for (int i = 1; i < n; i++) {
if (!ls[i - 1] && ls[i]) {
lms_map[i] = m++;
}
}
std::vector<int> lms;
lms.reserve(m);
for (int i = 1; i < n; i++) {
if (!ls[i - 1] && ls[i]) {
lms.push_back(i);
}
}
induce(lms);
if (m) {
std::vector<int> sorted_lms;
sorted_lms.reserve(m);
for (int v : sa) {
if (lms_map[v] != -1) sorted_lms.push_back(v);
}
std::vector<int> rec_s(m);
int rec_upper = 0;
rec_s[lms_map[sorted_lms[0]]] = 0;
for (int i = 1; i < m; i++) {
int l = sorted_lms[i - 1], r = sorted_lms[i];
int end_l = (lms_map[l] + 1 < m) ? lms[lms_map[l] + 1] : n;
int end_r = (lms_map[r] + 1 < m) ? lms[lms_map[r] + 1] : n;
bool same = true;
if (end_l - l != end_r - r) {
same = false;
} else {
while (l < end_l) {
if (s[l] != s[r]) {
break;
}
l++;
r++;
}
if (l == n || s[l] != s[r]) same = false;
}
if (!same) rec_upper++;
rec_s[lms_map[sorted_lms[i]]] = rec_upper;
}
auto rec_sa =
sa_is<THRESHOLD_NAIVE, THRESHOLD_DOUBLING>(rec_s, rec_upper);
for (int i = 0; i < m; i++) {
sorted_lms[i] = lms[rec_sa[i]];
}
induce(sorted_lms);
}
return sa;
}
} // namespace internal
std::vector<int> suffix_array(const std::vector<int>& s, int upper) {
assert(0 <= upper);
for (int d : s) {
assert(0 <= d && d <= upper);
}
auto sa = internal::sa_is(s, upper);
return sa;
}
template <class T> std::vector<int> suffix_array(const std::vector<T>& s) {
int n = int(s.size());
std::vector<int> idx(n);
iota(idx.begin(), idx.end(), 0);
sort(idx.begin(), idx.end(), [&](int l, int r) { return s[l] < s[r]; });
std::vector<int> s2(n);
int now = 0;
for (int i = 0; i < n; i++) {
if (i && s[idx[i - 1]] != s[idx[i]]) now++;
s2[idx[i]] = now;
}
return internal::sa_is(s2, now);
}
std::vector<int> suffix_array(const std::string& s) {
int n = int(s.size());
std::vector<int> s2(n);
for (int i = 0; i < n; i++) {
s2[i] = s[i];
}
return internal::sa_is(s2, 255);
}
template <class T>
std::vector<int> lcp_array(const std::vector<T>& s,
const std::vector<int>& sa) {
int n = int(s.size());
assert(n >= 1);
std::vector<int> rnk(n);
for (int i = 0; i < n; i++) {
rnk[sa[i]] = i;
}
std::vector<int> lcp(n - 1);
int h = 0;
for (int i = 0; i < n; i++) {
if (h > 0) h--;
if (rnk[i] == 0) continue;
int j = sa[rnk[i] - 1];
for (; j + h < n && i + h < n; h++) {
if (s[j + h] != s[i + h]) break;
}
lcp[rnk[i] - 1] = h;
}
return lcp;
}
std::vector<int> lcp_array(const std::string& s, const std::vector<int>& sa) {
int n = int(s.size());
std::vector<int> s2(n);
for (int i = 0; i < n; i++) {
s2[i] = s[i];
}
return lcp_array(s2, sa);
}
template <class T> std::vector<int> z_algorithm(const std::vector<T>& s) {
int n = int(s.size());
if (n == 0) return {};
std::vector<int> z(n);
z[0] = 0;
for (int i = 1, j = 0; i < n; i++) {
int& k = z[i];
k = (j + z[j] <= i) ? 0 : std::min(j + z[j] - i, z[i - j]);
while (i + k < n && s[k] == s[i + k]) k++;
if (j + z[j] < i + z[i]) j = i;
}
z[0] = n;
return z;
}
std::vector<int> z_algorithm(const std::string& s) {
int n = int(s.size());
std::vector<int> s2(n);
for (int i = 0; i < n; i++) {
s2[i] = s[i];
}
return z_algorithm(s2);
}
} // namespace atcoder
#include <cassert>
#include <vector>
namespace atcoder {
struct two_sat {
public:
two_sat() : _n(0), scc(0) {}
explicit two_sat(int n) : _n(n), _answer(n), scc(2 * n) {}
void add_clause(int i, bool f, int j, bool g) {
assert(0 <= i && i < _n);
assert(0 <= j && j < _n);
scc.add_edge(2 * i + (f ? 0 : 1), 2 * j + (g ? 1 : 0));
scc.add_edge(2 * j + (g ? 0 : 1), 2 * i + (f ? 1 : 0));
}
bool satisfiable() {
auto id = scc.scc_ids().second;
for (int i = 0; i < _n; i++) {
if (id[2 * i] == id[2 * i + 1]) return false;
_answer[i] = id[2 * i] < id[2 * i + 1];
}
return true;
}
std::vector<bool> answer() { return _answer; }
private:
int _n;
std::vector<bool> _answer;
internal::scc_graph scc;
};
} // namespace atcoder
using namespace std;
using mint = atcoder::modint998244353;
int n,q;
const int B=2000,N=1e5+10;
vector<int>g[N];int fa[N];
vector<mint>a[N],z[N],e[N];
int cn[N],wh[N];
vector<mint>fz[N];int O,fz_[N];
void dfs(int x){
int ca=0,wq=0;
ca=a[x].size()-1;
for(int v:g[x])
if(v!=fa[x]){
fa[v]=x,dfs(v);
ca+=z[v].size()-1;
wq+=(wh[v]>0);
}
if(wq<=1&&ca<=B){
z[x]=a[x];
for(int v:g[x])if(v!=fa[x]){
if(wh[v]!=v)z[x]=convolution(z[x],z[v]);
if(wh[v])wh[x]=wh[v];
}
}
else{
wh[x]=x,z[x]={1};
O=1,fz[1]=a[x];
for(int v:g[x])if(v!=fa[x]){
if(wh[v]!=v)fz[++O]=z[v];
if(wh[v])fz[++O]=e[wh[v]];
}
#define pi pair<int,int>
priority_queue<pi>Q;
for(int i=1;i<=O;i++)fz_[i]=-(fz[i].size()-1),Q.push({fz_[i],i});
while(Q.size()>1){
pi a=Q.top();Q.pop();
pi b=Q.top();Q.pop();
int x=a.second,y=b.second;
fz[x]=convolution(fz[x],fz[y]);
fz_[x]+=fz_[y];
Q.push({fz_[x],x});
}
e[x]=fz[Q.top().second];
}
}
int main() {
scanf("%d%d",&n,&q);
for(int i=1;i<=n;i++){
int sz;scanf("%d",&sz);
a[i].resize(sz+1);
for(int j=0;j<=sz;j++)scanf("%d",&a[i][j]);
}
for(int i=1;i<n;i++){
int u,v;scanf("%d%d",&u,&v);
g[u].push_back(v),g[v].push_back(u);
}
dfs(1);
for(int i=1;i<=n;i++)if(wh[i]==i){
int sz=e[i].size();
for(int j=1;j<sz;j++)e[i][j]+=e[i][j-1];
}
e[0]={1};int lans=0;
for(int pp=1,i,l,r;pp<=q;pp++){
scanf("%d%d%d",&i,&l,&r);
i^=lans,l^=lans,r^=lans;
int sz=z[i].size(),sz2=e[wh[i]].size();
mint ans=0;
for(int j=0;j<sz;j++){
int pl=max(0,l-j),pr=min(sz2-1,r-j);
if(pl<=pr){
ans+=e[wh[i]][pr]*z[i][j];
if(pl)ans-=e[wh[i]][pl-1]*z[i][j];
}
}
printf("%d\n",lans=ans.val());
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 7
Accepted
Test #1:
score: 7
Accepted
time: 52ms
memory: 17292kb
input:
1977 200000 0 883734638 1 497045124 50605999 0 467033353 8 514303373 873913661 21585656 827572829 831599042 669912647 980444584 921677622 90967524 0 111009203 0 980468811 1 965285721 647475291 0 55665482 0 810210109 5 99482052 915734955 536563337 860629716 489661090 127640528 4 452261176 414532348 8...
output:
0 0 0 1462214 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 709010908 0 0 0 0 0 0 0 0 0 0 0 0 0 0 362560754 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 887205253 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 532388854 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 200000 numbers
Test #2:
score: 7
Accepted
time: 54ms
memory: 17648kb
input:
1969 200000 1 928278040 49291189 0 106316044 7 355985609 701602147 528629206 472008316 626845782 871506163 793475066 634852555 0 193911795 1 498772599 387035156 2 244940676 15788848 225049996 8 257966353 171785747 687353797 643745787 25069581 248781417 212047281 295151595 525248876 2 606862291 21936...
output:
0 0 702752596 0 0 0 564436252 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 539882987 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 421207407 0 0 0 0 0 ...
result:
ok 200000 numbers
Test #3:
score: 7
Accepted
time: 56ms
memory: 17432kb
input:
2000 200000 0 230695610 4 400302240 129755410 740309716 633048240 594259574 2 261261651 610028309 279096898 0 306295327 1 411519353 880936332 4 458323735 111990362 693959473 50334178 49499787 0 451592459 1 114402580 931927324 4 639243873 254122580 669324541 571247271 275880979 0 440954066 1 43964805...
output:
0 0 801713754 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 807839363 0 845789441 0 0 0 0 0 0 0 0 180971215 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 791867965 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 514100741 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 995968989 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 8782...
result:
ok 200000 numbers
Test #4:
score: 7
Accepted
time: 124ms
memory: 19272kb
input:
1978 200000 1 191987956 540466676 1 120742551 206257774 2 744430486 875250521 181042024 0 103091601 0 304724279 0 649017453 0 145685556 0 599144446 0 364188280 0 57833875 3 414338956 791946816 770890256 830048461 0 819249191 0 755199883 1 758814940 693449562 1 280052104 142092003 0 214207528 0 85521...
output:
0 0 0 0 0 0 0 0 0 0 0 0 574798441 0 0 551851346 0 0 0 0 0 0 298923018 0 0 0 0 0 706319639 0 0 932127532 0 0 0 0 506810290 0 0 375480684 0 0 0 0 0 575707276 0 769974190 0 0 0 0 0 0 0 0 0 255132253 234643792 0 436442475 0 0 0 0 0 0 770777820 0 0 0 0 382421721 0 0 10702740 0 0 912641116 0 679541132 0 0...
result:
ok 200000 numbers
Test #5:
score: 7
Accepted
time: 51ms
memory: 17408kb
input:
1997 200000 1 609381747 833571580 1 102342468 526127035 1 880931004 909374728 2 103826707 729151512 34293902 1 273372046 293953096 0 554926428 0 676458000 1 401799287 357803550 1 695810053 794616522 0 748711966 1 967175820 34877055 2 257806263 264285746 818013686 1 576641758 75701100 0 795476926 0 7...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 996352329 0 0 0 0 61024835 0 0 424430639 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 392760029 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 442026045...
result:
ok 200000 numbers
Subtask #2:
score: 3
Accepted
Test #6:
score: 3
Accepted
time: 104ms
memory: 27296kb
input:
98154 200000 0 948053956 0 149079029 0 871940052 0 888807640 0 284687863 0 760258916 0 916765457 0 121680504 0 210430381 0 162441114 0 640680402 0 269559148 0 706423649 0 619089994 0 776236890 0 44769489 0 863235377 0 283984837 0 251593760 0 863377054 0 40488948 0 100272768 0 628132233 0 18841959 0 ...
output:
0 160622568 939846745 221659137 0 312930382 620657950 975124531 0 241389446 233242086 656904774 0 666641212 127400637 0 0 61866892 388266897 17714856 158666308 181172732 0 231863345 0 0 993493871 0 945624744 0 53582097 0 553931157 940627115 0 864491900 0 0 910285591 0 0 0 0 810021023 0 957355731 870...
result:
ok 200000 numbers
Test #7:
score: 3
Accepted
time: 108ms
memory: 27256kb
input:
98566 200000 0 209181684 0 889317979 0 925862494 0 861680823 0 629292192 0 781545895 0 58892045 0 300501945 0 510137985 0 764792857 0 551445762 0 771899874 0 828696971 0 260462870 0 535761660 0 532161459 0 187099 0 691412616 0 891055462 0 283180276 0 446617517 0 928434806 0 974119517 0 895921491 0 8...
output:
0 541915644 0 0 0 344789573 37160095 0 0 378148422 0 27407348 0 510146116 0 0 593724632 308323897 0 208041958 834526238 308130263 413718362 0 0 452600858 215844992 0 0 138748183 0 597752749 0 0 0 131857104 0 0 583969453 644145934 277456647 0 730806159 210434799 329144450 0 271266199 0 0 532721033 33...
result:
ok 200000 numbers
Subtask #3:
score: 20
Accepted
Test #8:
score: 20
Accepted
time: 1082ms
memory: 108984kb
input:
97330 200000 2 356080749 854511831 888131963 0 533633039 0 260190631 0 217335008 2 998111375 903316988 891866314 0 507509609 0 556810297 1 190927168 988903728 1 270553180 387224380 0 360295480 0 775464651 0 755424805 0 71030175 0 690904984 0 702271750 0 360541906 0 903384679 0 769283169 0 6990072 0 ...
output:
977291091 128984561 364900240 670134422 109312967 116219802 633246879 791832029 188822171 313954797 872698950 326842267 58045309 613915890 34453063 626081681 891712143 675586354 509834775 529836633 409512272 657071096 11862851 695651906 98170281 194125828 955037714 807908792 212191825 825295990 2244...
result:
ok 200000 numbers
Test #9:
score: 20
Accepted
time: 314ms
memory: 64136kb
input:
96880 200000 0 155849542 1 895865131 748889613 0 28666287 0 959676113 0 436568647 0 514279644 1 636928010 199253041 1 806543723 563843226 0 296862731 1 617330202 619480133 0 832224863 1 207080707 411689441 1 550833908 670195492 0 980814251 0 685006368 0 558249647 0 20614515 1 412246213 873717215 0 9...
output:
440357773 924848770 340312385 268399218 703705351 283032621 527143532 527723719 936920505 815914636 237227259 965189344 992799087 987559316 196769340 130556674 652234120 950203104 295087063 429164775 959998385 480555801 559603216 617304409 636888726 251764185 734722233 932706757 260865681 154570949 ...
result:
ok 200000 numbers
Test #10:
score: 20
Accepted
time: 728ms
memory: 67624kb
input:
99119 200000 1 193445750 73279632 0 159943777 0 741212402 0 433101693 0 492169150 0 295804258 1 875516477 748591364 1 847628456 521055346 0 720470433 0 550284345 0 645519907 0 749938197 0 728894207 0 14951672 0 929957765 0 738265973 0 856320168 1 663420785 638700238 0 779605078 1 862023258 913300109...
output:
107826286 763543631 427034420 121557813 640560432 778202723 103828218 293968965 588012467 317760045 345087369 219212550 836926992 376387667 550043054 728607728 282292412 228698918 347936331 249473140 667006058 385530595 234024405 524452029 871686154 73351486 115718734 415219796 6724454 728022916 226...
result:
ok 200000 numbers
Test #11:
score: 20
Accepted
time: 1490ms
memory: 113008kb
input:
91157 200000 0 391787528 0 128755192 3 417616809 157059090 109145241 105518767 4 168117201 184583673 611518413 449165163 785494567 0 335176806 0 767105706 6 197456690 26613590 508404062 688256680 114381875 509628059 822034065 1 134962121 111013253 0 273868329 0 995896690 0 727430687 4 52157529 93530...
output:
487041619 893275322 142402824 686731750 294920099 62183929 203079049 439067611 576528554 1804420 325046088 569012939 705848070 441856702 186405396 545740489 381312300 369454907 220000496 165233678 885597752 351769009 923484288 312188024 490873204 137214518 826339916 76816562 934429093 978384021 5417...
result:
ok 200000 numbers
Test #12:
score: 20
Accepted
time: 870ms
memory: 64044kb
input:
99054 200000 5 254591921 45593960 652041376 677254663 473209153 872993623 2 971834440 872618713 873774372 2 972786941 469418722 54936289 0 81056452 2 19714994 377576837 670989944 0 576526565 1 386619382 254596911 0 556584884 0 660262022 2 695328773 305942756 847812140 3 481581243 889943689 200600389...
output:
71125289 915873767 805882401 172961705 778575612 745456836 142968723 651540653 62367309 595540188 481360743 493180227 29659645 130302698 499160808 175915570 885742426 369665055 759536493 373302350 748795932 868454695 156649635 515858502 343254972 915736493 855732654 833555582 267541889 927511069 635...
result:
ok 200000 numbers
Subtask #4:
score: 20
Accepted
Test #13:
score: 20
Accepted
time: 315ms
memory: 38456kb
input:
50000 50000 1 610345459 691411093 1 476654936 529767753 1 8856530 640833948 1 961473497 456987897 1 462733802 114971681 1 662244461 415955667 1 717992437 907944693 1 346097988 176526535 1 805826501 182409272 1 33105050 971783530 1 45972429 258997374 1 964103067 796756441 1 958668755 735146502 1 9543...
output:
0 0 0 0 0 0 0 610268301 297428232 729194415 0 0 506964543 0 198345028 778136423 0 89695571 651093422 174709 799469987 0 0 0 0 374762615 64155221 0 644085102 355318236 625240586 0 0 0 0 611217681 0 246858712 0 946363040 766457000 0 0 0 0 0 0 0 885388926 324657374 0 0 608041499 0 0 0 595311003 0 0 790...
result:
ok 50000 numbers
Test #14:
score: 20
Accepted
time: 353ms
memory: 75700kb
input:
50000 50000 1 284188823 730123812 1 578529655 782975708 1 682107201 169640319 1 504919829 297067490 1 126340369 681480864 1 702290552 331608873 1 89823300 900339069 1 661791786 696739097 1 146107507 457302386 1 309885170 133384173 1 1601509 445278250 1 82308245 611577805 1 575317 145972663 1 3340187...
output:
118484783 20950737 827095992 192485904 949696395 760932709 0 827083836 737333618 0 0 936633428 869751868 21893026 0 0 700825516 0 0 140717292 495143473 757971245 71851829 758042728 168032853 336898224 82834617 0 50295595 473191194 0 603695852 88648030 191908163 0 0 347045240 304736441 10279888 28050...
result:
ok 50000 numbers
Test #15:
score: 20
Accepted
time: 239ms
memory: 36484kb
input:
50000 50000 1 908905842 879908939 1 69131120 893333490 1 766104239 502577285 1 598541702 20672714 1 19129534 562935613 1 17855501 931751363 1 817552765 924309216 1 601703730 928273412 1 280909912 198946276 1 259187488 350711225 1 460175073 829804287 1 142301100 182462131 1 440043596 503299121 1 4954...
output:
608336339 0 479640409 0 0 0 304101361 575455842 631421870 0 921143438 0 0 614891272 920725723 987924343 0 0 944939021 0 842440434 0 0 219630310 595973439 303974010 0 0 0 0 266178665 352670733 355014561 0 0 0 15870579 900144368 490797433 594447900 0 521603348 0 0 763764981 0 0 238461206 0 0 22187316 ...
result:
ok 50000 numbers
Test #16:
score: 20
Accepted
time: 224ms
memory: 41644kb
input:
50000 50000 1 132666924 481468407 1 233104347 925423798 1 196520221 188340478 1 880316330 347865528 1 362038740 586184357 1 260977445 869456691 1 413836428 997205621 1 925267833 389145261 1 412474208 605923400 1 275275170 580329557 1 248067291 201190325 1 267032222 546518461 1 60371460 731907388 1 2...
output:
284858974 0 521392986 0 0 419555545 0 279474735 869174793 0 0 0 0 327341031 0 887506929 253382960 0 549720153 0 470223182 448985266 0 0 0 571599922 0 0 0 0 687095778 0 0 523720173 340816378 0 927700876 0 0 0 117671213 493623216 0 269849900 992438456 0 233002506 0 875191758 582797638 0 0 222273961 0 ...
result:
ok 50000 numbers
Test #17:
score: 20
Accepted
time: 161ms
memory: 41660kb
input:
50000 50000 1 570249482 963041872 1 164483403 404765803 1 181145508 416450528 1 536381689 716629517 1 19355006 80481263 1 627992141 65443806 1 185587289 129800096 1 667577148 11179897 1 512133278 870239643 1 135475895 124891452 1 917154463 721424462 1 243207295 964207791 1 348452088 67572040 1 16668...
output:
76593910 267735832 0 0 379967837 128237686 782639460 0 0 155844091 934345203 666090547 241913187 0 0 884593508 0 199971361 0 876108660 362635493 0 0 0 0 93781856 635645613 903201788 0 794166948 108363160 0 0 937730015 0 641371731 0 836048882 0 584024075 0 0 0 0 169018859 0 0 0 0 984231395 0 0 102506...
result:
ok 50000 numbers
Test #18:
score: 20
Accepted
time: 312ms
memory: 52724kb
input:
50000 50000 1 374439028 76801984 1 198570918 279646664 1 738529796 230017198 1 93739509 610640325 1 525884738 858818589 1 949692556 761814293 1 235726510 7565628 1 45230953 841809717 1 624654181 697155421 1 56572048 898846486 1 181498104 803293558 1 123843798 593520342 1 590491409 791005242 1 888374...
output:
864276436 440159890 536780052 321076766 468541452 986423750 663920928 988866764 260419539 0 0 0 0 917177790 340374136 783267120 861409101 702416442 365736645 250814244 0 889464570 0 158883242 778105434 403578126 718091928 0 110804297 685559904 0 17649876 0 811219235 0 320574087 469972593 932031629 3...
result:
ok 50000 numbers
Test #19:
score: 20
Accepted
time: 285ms
memory: 37956kb
input:
50000 50000 1 33459023 378743148 1 649009512 322497285 1 4159024 354205478 1 635048826 663468389 1 822658913 27307310 1 195454131 803172665 1 875401287 11624886 1 289967362 733461614 1 251177354 546439677 1 600412174 876096433 1 230834162 878747260 1 269956920 918423510 1 254773805 746291985 1 29210...
output:
144329675 0 937010808 0 387987066 256520687 0 415222201 574050902 0 0 78330661 774146527 545659020 0 0 676856924 0 0 0 371281553 0 724389591 180883171 60120880 758706582 260395535 86733354 0 0 454943744 866940819 213813873 343349330 781027374 265021034 322573212 71290236 0 0 333346154 117482220 1005...
result:
ok 50000 numbers
Test #20:
score: 20
Accepted
time: 385ms
memory: 228232kb
input:
50000 50000 1 740199008 613475557 1 922880359 842126974 1 451019859 922790230 1 178429894 72393602 1 569458862 898768795 1 834271550 7640899 1 645877613 459724785 1 15126535 700620044 1 546332191 981494527 1 693370057 48191032 1 599613461 710991225 1 560674975 816111048 1 324902849 638444457 1 41924...
output:
874743447 472418696 893475459 768083962 844890219 0 491167288 0 662057644 33125578 0 0 0 380253379 790862397 453081406 0 0 64445999 613775426 0 0 0 669660760 597392638 0 37758869 0 11684083 11431232 0 827641705 191050687 39123082 0 821861901 0 658965581 0 107926632 720677708 0 0 240074723 949362284 ...
result:
ok 50000 numbers
Subtask #5:
score: 20
Accepted
Test #21:
score: 20
Accepted
time: 49ms
memory: 27556kb
input:
19854 20000 1 150513542 240180212 0 987796281 0 90054116 1 191708494 438440429 0 192815969 0 867402303 1 531762469 210966860 2 95662022 345368425 199338548 0 269135053 0 816253511 0 66854944 0 319745952 0 202288549 0 492853777 0 410846691 0 824737426 0 821545014 0 72050044 0 534080091 1 542636124 52...
output:
913323334 0 0 0 0 0 0 0 0 0 0 0 901017606 0 0 0 0 0 954099396 0 0 432419999 0 0 0 0 0 0 0 761082946 259729654 0 0 0 0 790235355 933098570 356668385 125624181 0 0 0 0 917034405 0 321407524 0 671256345 39032345 0 0 676929142 0 0 0 0 0 0 0 0 910494481 0 0 0 733125978 0 0 835461650 0 154343024 690428959...
result:
ok 20000 numbers
Test #22:
score: 20
Accepted
time: 42ms
memory: 24696kb
input:
19416 20000 1 813812350 62928444 2 446931520 455152410 865811291 1 483245225 719509880 0 10630578 1 722267364 499990463 0 978295677 0 524126644 2 398577038 701788899 939255653 0 945953310 0 358029034 1 54632159 541649711 0 714215963 0 760637762 1 792667329 540131052 1 336329275 197811762 0 594815129...
output:
0 0 0 0 0 0 0 0 691960524 0 0 0 0 0 0 0 0 0 0 917519575 0 0 0 0 457906160 686627668 0 263875204 0 0 0 860458574 0 0 197732443 0 0 0 0 0 0 0 0 0 0 0 0 0 619069496 0 0 145464796 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 409777622 309523189 862407937 0 0 954411456 0 0 0 0 0 0 304719397 0 548777971 176155...
result:
ok 20000 numbers
Test #23:
score: 20
Accepted
time: 35ms
memory: 25816kb
input:
19645 20000 1 738216072 655062389 0 478261419 28 38522218 205802590 608351714 423733656 368037127 943951223 529243126 691493532 378826276 32699256 849862664 799709335 113704178 671006657 736000878 683394539 338518052 850384023 536423162 225738416 276528868 965415989 455460104 274736758 547583027 423...
output:
0 710035374 349663621 61124181 0 0 0 0 0 0 0 0 0 0 0 0 0 0 694466943 0 0 0 0 103025366 0 0 108158012 0 0 898653012 0 0 0 0 124734988 0 628306562 0 0 0 0 0 829055370 0 942321667 0 0 0 0 100614270 0 666765805 277413825 0 0 0 0 492192785 0 0 0 0 517011159 0 0 0 0 172598073 0 258513717 233404540 8590182...
result:
ok 20000 numbers
Test #24:
score: 20
Accepted
time: 36ms
memory: 24216kb
input:
19847 20000 4 815026590 930615671 256423615 192058090 553677398 0 854407447 3 121205405 14847480 141687199 287623506 2 379798536 291209656 593839232 1 352031200 841240984 0 295186159 0 841042115 0 679392127 0 420742492 2 891756622 260075296 417909411 0 645458804 0 681889229 0 29119165 0 99142741 3 7...
output:
470171472 213398321 0 0 55462715 0 338144412 0 0 0 0 0 0 0 698725184 0 0 0 0 47366191 0 317326831 0 0 0 239746199 214366720 0 0 0 0 0 279091720 0 86836316 0 0 0 35432299 0 308555884 0 319326811 0 0 0 305535605 0 358646410 0 0 131375996 0 0 0 0 0 0 0 0 570823027 0 0 80022023 0 954809219 0 0 0 0 26917...
result:
ok 20000 numbers
Test #25:
score: 20
Accepted
time: 42ms
memory: 23528kb
input:
19990 20000 3 575964327 889968526 762346953 464212918 0 91433877 0 762285092 1 703259059 61874142 2 130773960 696187633 280576635 1 163442506 294293968 0 134582456 0 525908094 2 981613234 494831823 871173319 0 320232487 0 951459253 0 725136632 2 48590419 631199232 992008959 1 860836891 867326137 1 6...
output:
90336621 0 741001438 326700634 0 0 0 0 0 0 925215064 0 0 863889195 0 0 0 0 0 576304546 0 0 0 0 583889751 0 0 0 0 0 0 813389361 0 0 0 0 0 0 0 108311310 0 0 653689603 0 0 0 91295650 0 347062400 0 0 0 0 620038417 846141331 99345412 0 581988923 0 0 0 0 365053652 29464872 917029396 788177507 288943414 0 ...
result:
ok 20000 numbers
Test #26:
score: 20
Accepted
time: 52ms
memory: 24608kb
input:
19302 20000 1 140879209 815790450 0 263312184 2 357492390 407721624 927753023 17 329030216 687250506 904721674 66559073 150996400 582272412 140464848 806623151 989399143 916248414 596527559 964780629 802988469 182625819 764316767 594475067 203564894 275476377 0 547777698 0 34169169 0 93303556 0 5807...
output:
0 0 132910965 0 127962650 0 453633700 0 0 451482843 0 0 0 388743057 0 0 293560154 874329518 0 0 0 0 0 0 0 0 0 0 766081674 0 0 234642116 0 0 669563153 0 748448386 0 0 0 0 0 0 0 0 0 670410122 87350607 0 416323263 174794844 0 0 0 0 0 0 196859095 0 0 0 0 644332981 0 0 0 0 0 0 0 0 0 469599960 0 0 0 0 931...
result:
ok 20000 numbers
Test #27:
score: 20
Accepted
time: 48ms
memory: 27588kb
input:
19653 20000 1 906614788 500628713 0 988012762 0 284902421 0 704468047 0 872560811 1 907887753 600402772 0 767950811 0 118754288 0 290736011 0 217729487 1 190172852 683598286 0 723859834 0 220112811 0 448174595 0 39653265 0 770732977 0 458450918 0 438730398 0 183195813 0 191514564 0 2928127 0 3007322...
output:
0 244727120 0 0 132988676 354295625 0 667761790 0 0 0 0 0 822615931 0 0 0 0 0 0 504618092 0 973780962 0 0 0 0 737475269 0 0 0 383245743 0 0 10261578 551768502 0 835642191 0 0 69015099 0 0 773914454 0 0 0 0 0 193232063 0 0 0 0 0 230203189 0 0 0 0 0 0 0 0 120778708 0 949822563 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 20000 numbers
Test #28:
score: 20
Accepted
time: 43ms
memory: 24196kb
input:
19072 20000 0 910136763 1 809343877 577693489 0 805540439 0 728993500 0 234081004 1 891104112 210354669 0 262384318 0 568913493 0 376708574 1 145377149 421745582 0 108964429 0 697119989 0 615671424 0 697025092 0 222804661 0 927317484 1 66775292 771115618 0 405877157 1 977355316 502648356 1 218406564...
output:
0 0 0 558272462 0 0 0 0 0 0 0 328733917 446478844 0 0 0 0 0 0 848724549 0 0 980511070 0 0 597411269 0 127279175 0 0 0 0 0 739852501 0 0 0 0 0 0 568449517 589452941 0 0 0 0 791777304 0 0 0 0 114744131 322763812 613885875 52417149 0 0 0 0 149449664 0 0 644257795 0 725958460 276312482 499158209 8075964...
result:
ok 20000 numbers
Test #29:
score: 20
Accepted
time: 15ms
memory: 22620kb
input:
20000 20000 0 614936162 0 182986322 0 40697275 0 824161988 0 240412566 0 287310162 0 63000758 0 958628891 0 139827408 0 971860786 0 325782161 0 726800064 0 392930207 0 911604309 0 904980384 0 508941069 0 641836609 0 759719860 0 732767740 0 94630498 0 390558752 0 764408563 0 40013248 0 414628626 0 87...
output:
664811563 788614780 974744409 578158051 972633254 83874056 204528292 473798071 213046046 429307018 595958938 227031150 671368761 461998185 115917717 744731293 465171055 551785804 318236143 171800659 801541585 707676156 58721393 116249265 334321741 90511883 550891644 284752711 828872978 231691412 450...
result:
ok 20000 numbers
Test #30:
score: 20
Accepted
time: 43ms
memory: 24028kb
input:
19446 20000 1 701024899 61691599 0 459112272 0 605953973 0 852714844 0 174821235 1 313026866 19060724 0 553043793 1 837260834 209473757 0 445224261 0 18895399 1 976728020 509710102 0 332645932 0 661618262 0 204178386 0 269435005 0 736889829 0 397995492 0 866964923 0 132403278 0 596284173 0 958984850...
output:
534451823 0 0 607037735 558413343 0 0 0 0 0 0 0 0 0 0 0 673258724 0 869080507 506727857 9843331 0 85465239 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 398060444 882747749 0 0 0 0 0 0 214087586 0 0 0 0 0 0 0 0 0 0 0 0 733471287 0 636321624 0 351918892 0 0 856397457 0 0 0 0 0 0 0 0 91532953 0 0 0 0 0 237024413 63...
result:
ok 20000 numbers
Subtask #6:
score: 30
Accepted
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
100%
Accepted
Dependency #4:
100%
Accepted
Dependency #5:
100%
Accepted
Test #31:
score: 30
Accepted
time: 423ms
memory: 90096kb
input:
99594 200000 0 792083461 0 914312025 0 34350651 0 767686614 0 126625954 1 469369269 944342533 0 612174706 0 659144535 0 980769871 0 11719240 0 686570452 0 557384020 0 775725208 1 206987845 317493823 0 549993972 0 243134305 0 50842360 2 694278935 105006374 564812234 0 273854368 0 949758784 0 80244234...
output:
109399968 0 0 0 448463153 0 0 818361960 238762152 489879263 532197351 0 0 0 0 0 143357594 0 0 0 0 0 0 0 0 0 0 737808980 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 848155620 0 788868258 0 0 0 547711349 0 0 0 0 0 0 0 0 0 0 0 0 0 0 338269278 0 575775483 0 532938132 0 0 0 0 611122990 718119560 0 0 0 ...
result:
ok 200000 numbers
Test #32:
score: 30
Accepted
time: 465ms
memory: 83572kb
input:
99035 200000 0 516279412 0 412939901 0 606838540 0 387878075 1 262965855 768053906 5 19202246 37691309 63031387 385686181 758382124 552090450 2 971931101 451423603 833655477 2 420564093 201427455 744193012 0 562042321 0 244312780 1 793149487 305896859 0 270808962 2 141955607 783349908 417999654 0 42...
output:
0 0 0 0 0 0 0 0 993301929 0 0 0 0 0 0 737055174 406546071 0 0 666458859 0 0 0 0 507321872 169036937 0 0 0 0 0 0 0 967598644 182481323 0 0 0 0 0 0 0 0 0 450225917 0 364239472 0 0 0 0 0 184083094 898158431 0 737677208 0 0 0 47593713 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 996953495 0 0 0 8084585...
result:
ok 200000 numbers
Test #33:
score: 30
Accepted
time: 364ms
memory: 62868kb
input:
99083 200000 9 812519718 737365909 60790048 110734972 345456242 716203655 119077807 648818873 468118712 147036529 1 297548567 794303861 5 641870110 181984618 69051204 758849582 714652096 396595861 1 560530303 275242004 0 574153100 0 317052463 0 480726959 3 110710840 830240927 248270237 978423303 0 5...
output:
0 0 567845892 29922025 0 0 0 0 134770615 0 0 0 0 0 0 0 0 0 471511799 0 0 0 0 0 0 0 0 0 0 0 0 0 85185078 0 0 581149537 0 540973163 0 0 0 747061501 751392383 0 0 594973285 0 123772660 0 0 0 0 0 0 0 0 304308252 260946625 121532287 0 340335526 0 0 0 0 0 0 0 0 0 0 0 148043643 0 0 0 0 575135327 0 54065753...
result:
ok 200000 numbers
Test #34:
score: 30
Accepted
time: 554ms
memory: 156800kb
input:
99785 200000 0 280332852 0 463734447 0 171818841 0 299075569 0 863711022 0 907616285 0 234302886 1 977699188 129280311 0 460473318 0 570409123 0 29676746 0 906924939 0 929635560 0 444520539 0 61650377 1 176555744 745995937 0 767706179 0 697499158 1 968035736 79077206 0 853004807 0 669726083 0 917877...
output:
0 480380633 100067255 0 0 736885183 0 0 960940710 0 579705665 0 0 0 0 598371980 0 0 0 0 0 693279318 0 0 22276414 0 0 0 0 0 806866513 990455994 585969490 381728870 0 428502384 890759743 0 0 0 0 0 797184734 0 0 914101649 0 442980166 0 0 699124593 0 0 226141455 0 765484286 156198071 0 0 0 723454355 0 0...
result:
ok 200000 numbers
Test #35:
score: 30
Accepted
time: 403ms
memory: 70568kb
input:
99006 200000 2 697598318 566784456 782231144 0 637183338 3 892921153 312022999 614093234 489700823 6 565253346 400806749 352924076 615575261 636132162 769385558 185304555 1 354998163 679380727 0 808808987 0 914852081 0 609747589 4 53572246 687372077 109442084 787697001 647385656 4 212951526 24244475...
output:
873398887 0 908891814 0 0 0 0 854361978 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 681498313 0 0 0 0 0 0 0 0 192671131 0 0 0 0 0 0 775815056 0 886750665 0 0 0 0 256584318 170858682 0 0 0 0 0 61850051 0 0 0 0 0 0 0 0 0 29520959 0 0 866066650 0 0 0 895412488 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 200000 numbers
Test #36:
score: 30
Accepted
time: 316ms
memory: 60672kb
input:
98985 200000 0 969193375 0 511357294 0 328085529 1 205258866 499880016 0 933319732 0 609835434 0 135107485 0 781419224 0 620351326 0 740789220 0 179692891 1 505604147 785232172 0 748252583 1 963799862 977536089 0 946638152 0 503453397 0 783885375 0 243538347 1 358016785 386995362 0 282713402 0 29462...
output:
0 0 0 0 0 401910156 0 0 0 0 0 0 0 0 0 0 601764437 0 0 0 0 0 0 753618471 0 0 305995424 0 0 0 0 0 0 0 0 0 0 0 431722758 0 0 0 0 798679245 773158656 0 0 0 0 0 0 0 0 0 0 0 0 0 0 170839700 0 0 0 0 0 0 0 0 0 0 0 0 0 0 156648441 0 0 0 0 0 0 0 439657527 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 347352285 0 0 0 0 0 ...
result:
ok 200000 numbers
Test #37:
score: 30
Accepted
time: 363ms
memory: 67676kb
input:
99106 200000 0 536357478 1 248797118 129050430 1 106948594 292418714 0 510102794 1 133026708 722417074 0 180653240 0 446667653 0 287445048 0 661059497 0 594996611 0 819285540 0 783212723 0 210212100 0 693574734 0 112477560 0 674105046 0 248594760 1 158166781 850888375 0 497357910 1 640562644 6835468...
output:
0 0 0 0 0 0 0 0 957985443 0 0 0 0 0 0 0 966288616 0 520774584 0 0 0 321026238 0 0 0 0 0 513903889 162689619 0 0 0 0 0 265617770 0 97712317 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 953800844 0 0 0 0 0 0 0 0 0 0 424167855 0 0 0...
result:
ok 200000 numbers
Test #38:
score: 30
Accepted
time: 257ms
memory: 52988kb
input:
99337 200000 1 498475374 77807972 0 710939325 0 257489757 0 366384158 1 489698229 751337044 0 633357139 1 830049927 866194558 2 341614269 142470787 621653008 1 673980230 442738390 1 366325112 428366642 1 26626735 639931615 0 764633730 0 474395039 0 135657003 0 722380645 0 319814064 0 984404609 1 665...
output:
978464904 0 0 503368730 0 0 0 0 0 0 0 0 479532558 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 645577386 0 0 0 0 0 0 0 0 0 0 0 0 0 255376668 0 0 453568313 0 496966692 0 0 0 0 0 0 0 46766572 0 0 0 0 0 0 0 0 0 0 0 0 0 963187989...
result:
ok 200000 numbers
Test #39:
score: 30
Accepted
time: 398ms
memory: 69060kb
input:
99397 200000 1 908659187 39931868 0 672134567 2 102740510 36677225 150007181 2 471908611 266747812 357960206 0 136686904 1 551385776 27154055 6 897495677 293831234 982707521 723038522 356184574 855103517 336715204 0 60799780 0 77841372 3 798508674 561483859 147801908 665942476 0 545064278 1 19419329...
output:
0 0 0 0 0 0 0 347981445 556682855 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 708396072 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 209956118 0 0 0 0 0 0 0 0 606367784 0 0 0 0 0 0 0 0 0 0 368648402 0 0 0 0 0 65368737 634556670 0 0 0 467587270 0 877360716 0 0 0 518078588 0 0 0 0 0 476405426 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 15193...
result:
ok 200000 numbers
Test #40:
score: 30
Accepted
time: 364ms
memory: 66024kb
input:
99251 200000 0 837618356 0 469241097 0 304116169 0 750862544 2 26173593 953672229 151599840 0 271279589 0 403113292 0 333427913 1 97867997 556460649 0 943168531 1 509903042 94841079 0 796070535 0 14009153 0 146895987 0 946947992 0 919251812 0 284637821 1 753226123 593010004 0 628694067 0 653161546 0...
output:
0 0 0 0 671158217 0 0 0 0 0 0 0 0 541497228 0 0 0 0 0 0 0 0 0 0 0 0 0 451481615 0 137067247 0 0 0 0 919959487 0 0 0 0 0 0 0 0 0 0 380863721 0 271452193 0 0 768517272 0 0 0 0 0 0 0 0 493731090 0 0 0 0 0 0 0 17031558 0 0 0 0 0 0 0 591218400 0 0 0 0 0 0 0 0 0 0 0 0 241982234 0 0 0 0 0 0 0 0 564614622 0...
result:
ok 200000 numbers
Test #41:
score: 30
Accepted
time: 362ms
memory: 70596kb
input:
99630 200000 0 5339176 0 183460101 0 78628974 0 71182183 1 821234975 144067318 0 956592536 0 82564025 1 334026285 237551854 0 154265800 0 260692099 0 260062211 1 456318703 276854147 1 587509429 4330857 0 381073041 0 675959015 0 965036457 0 283513233 2 316566027 40169150 897149637 2 770213563 2846924...
output:
309884962 263648364 548342103 189447330 403042313 0 164867241 51305764 463138099 0 0 63741792 0 42511729 0 486791755 0 102254495 0 0 0 0 656480709 0 0 0 680530049 686273532 998139721 0 0 0 783513253 720932489 0 812024439 938247438 847540531 669361421 0 601802190 0 990014943 517648770 672809095 96241...
result:
ok 200000 numbers
Test #42:
score: 30
Accepted
time: 767ms
memory: 101400kb
input:
99457 200000 0 520433982 0 600033942 0 597120011 1 131160787 64001098 1 573895343 649276549 0 195519651 0 475243851 0 289757468 0 804871132 0 666098884 1 231714454 628830730 0 890957706 0 83693875 0 301651579 0 291625927 0 404424239 0 181052960 1 536789543 288778943 0 166973270 1 345291754 449612874...
output:
0 0 0 0 304528688 0 0 766584610 0 0 0 0 656906535 777040558 0 269231403 0 757347049 0 0 447594777 0 881831292 914091245 0 0 0 403266514 741683002 526265855 0 0 0 0 967262076 0 856159414 0 0 0 782919249 327891282 0 572486461 0 0 179183639 735080713 682386725 0 0 0 0 0 0 0 8042811 82897394 446711502 1...
result:
ok 200000 numbers
Test #43:
score: 30
Accepted
time: 859ms
memory: 136348kb
input:
99862 200000 0 329513920 0 456692223 0 389322229 0 711051456 1 621965494 55887520 0 787567565 0 84446280 0 826368108 1 453561473 162705929 0 468696179 0 57014528 1 423197442 911428275 1 331659854 508452048 0 47732231 0 510804785 0 620213653 0 403025819 0 14580380 0 901519255 0 283742795 1 181801236 ...
output:
0 839931845 157764911 0 0 215894684 46271392 44093675 493597065 400043755 456226878 178843285 0 0 0 125583360 556511446 782225218 336159443 0 48437262 91755146 356318949 0 982396681 325921161 888415778 237790380 670546292 0 0 217544729 0 859956339 441975647 0 759366102 0 28623977 849837651 238938530...
result:
ok 200000 numbers
Test #44:
score: 30
Accepted
time: 621ms
memory: 70016kb
input:
99826 200000 1 323757533 870721963 2 904066510 788467099 240486432 2 180249005 71060394 53648532 0 164816460 0 468389437 0 258522341 1 182854620 988856023 0 139155677 0 858918287 1 578115690 581264910 1 848138916 498790873 0 817795940 1 629829076 517122055 1 131196258 513843426 0 281344156 1 5802285...
output:
510251661 322843343 253640725 175763102 708684462 0 0 0 309152124 420069658 913416863 0 38362214 0 263332631 642129577 0 0 871646207 298848615 0 329074227 301650376 0 0 394836751 0 0 0 0 0 293433700 0 0 0 0 0 800387736 13640879 738620452 923035045 0 626487991 973833608 0 830455251 0 316717789 0 0 56...
result:
ok 200000 numbers
Test #45:
score: 30
Accepted
time: 839ms
memory: 72068kb
input:
99664 200000 1 670597153 137196970 0 448037909 2 395548978 50888515 225301038 1 906680594 111745385 0 645929612 0 376568237 0 996010090 0 312802967 1 241662879 805185907 0 137707642 0 574859364 0 21632077 0 350124558 0 761906213 1 413353455 722297338 1 105639958 81668975 1 442545161 130820256 0 9458...
output:
0 13298333 796411980 717176960 427401440 859158010 0 0 554287565 0 6804644 0 837333422 850263412 749968216 21290770 716013140 0 0 0 609035567 419341980 574978215 229688216 205887830 173899597 79717147 620548356 156657047 0 0 549142000 7967802 0 744725557 381309597 0 0 152201862 191766672 0 870908035...
result:
ok 200000 numbers
Test #46:
score: 30
Accepted
time: 523ms
memory: 65332kb
input:
99936 200000 1 838410326 559781352 1 15519661 512473228 0 686587663 0 652469143 0 961809442 0 902588805 2 520910408 493321502 493526367 0 307197602 0 512061775 0 463074640 0 795071099 0 448849408 0 522272325 0 867669253 0 791911631 0 796271393 0 800296456 0 285955113 1 743247418 779908196 0 51017333...
output:
0 0 0 305107306 379150599 42011282 0 0 0 161166073 0 0 864848153 295413953 0 0 256383330 699111476 0 364923213 0 0 0 381145587 0 210879721 0 466483292 0 228632730 781776361 0 609583689 38035139 0 0 766392384 496307425 872071527 327088206 0 901406598 0 82575915 0 186066196 976518077 838408449 0 34449...
result:
ok 200000 numbers
Test #47:
score: 30
Accepted
time: 946ms
memory: 86460kb
input:
99088 200000 0 364832553 0 178745750 0 835029198 1 279742807 102370162 0 834347368 0 612774133 0 180761166 1 379950497 157310301 0 29363731 0 509494437 0 700030867 1 935402282 883975840 0 982734964 0 279823368 0 654117002 0 396925115 0 8330908 0 8204127 0 175734468 0 292209557 0 530551196 0 24939281...
output:
84290885 172473711 320359781 0 686175639 997982871 739107336 0 70395054 651442000 212364566 606189810 340398452 369355651 0 0 753033235 0 0 241596491 31250190 937363693 657293623 0 283648025 863116720 740290686 0 703070193 0 0 649865908 260970173 628279215 0 0 552350281 692378378 829193962 26701348 ...
result:
ok 200000 numbers
Test #48:
score: 30
Accepted
time: 670ms
memory: 91560kb
input:
99145 200000 0 143560353 0 708439926 0 701452428 0 637315652 0 10858266 1 324024099 421464572 1 7867270 718774170 0 464413576 0 182983498 1 311377044 986639223 0 490148621 0 543909721 0 102531250 0 483589345 2 88597038 552846483 990387576 0 993560233 0 546852218 0 791201835 0 696249807 0 246306695 0...
output:
0 739694884 433769957 584558975 885259821 0 0 0 843472324 655955792 931400009 0 314207102 486068606 0 0 0 132839733 375394984 0 18557269 528832436 0 0 0 947710310 0 377197977 0 196747374 0 703143919 0 0 593537487 5538491 430096964 0 0 0 0 738126639 770283456 0 422226849 341610677 469499040 0 3008630...
result:
ok 200000 numbers
Test #49:
score: 30
Accepted
time: 561ms
memory: 115276kb
input:
99917 200000 1 606379853 230564505 0 861782624 1 166045839 446984409 2 262143347 271529930 75070248 1 764120674 560497036 0 493657528 0 60011341 0 384737505 0 485851690 0 59804027 0 272031503 0 101931073 0 887059536 0 202260726 0 777511966 0 834899633 0 27259216 0 449327211 0 45993148 0 460191658 0 ...
output:
605186308 597933348 865908650 0 494051001 833085633 765000024 317367680 231872632 80637105 0 114289353 0 945516164 0 668977591 549708654 300760382 0 194940063 0 0 0 149218300 0 0 627379931 0 421969276 181354550 0 0 0 943014191 0 0 0 206946838 0 0 751545512 840917385 0 455228946 0 0 295557208 0 40024...
result:
ok 200000 numbers
Test #50:
score: 30
Accepted
time: 373ms
memory: 77560kb
input:
99626 200000 0 543722507 0 832417757 0 634572868 0 523056298 0 604006305 0 105205567 0 642477632 0 273861057 0 159049568 0 278889755 0 534451219 0 215637712 1 496543777 850957896 0 527887191 0 797572231 2 351423761 279337124 419541603 0 138972236 0 742639412 0 727952849 0 810781862 0 249581579 0 536...
output:
112541029 161741932 287403817 0 438982353 0 31544875 936722186 751598883 597267944 328798533 745429287 419961835 165995330 576022299 231729203 0 0 0 686554191 0 0 399196180 984422139 580466621 0 0 752262932 529783655 68016352 0 649283329 0 837279914 162398064 160608005 0 0 0 142098038 0 0 0 0 0 0 0 ...
result:
ok 200000 numbers
Test #51:
score: 30
Accepted
time: 717ms
memory: 56120kb
input:
100000 200000 0 613643917 0 835910163 0 418097458 1 813106042 240507736 0 563154711 2 915116833 242569780 645436195 1 983291419 722923451 2 275095780 639835018 487159272 0 363502753 0 864558407 0 52697997 1 99815226 844841329 0 174326710 1 806922141 55304067 2 804584045 470065735 376654165 0 3357850...
output:
0 314701272 301367246 0 0 0 307274596 0 979251102 0 0 0 0 0 0 0 0 0 0 429196314 0 0 0 0 105273277 0 0 950508916 306261739 247158638 0 0 443091520 0 0 0 778682554 0 0 0 149346952 0 871501201 0 0 0 127247196 0 0 0 0 0 198153970 893188252 0 841579618 24284813 537727232 616030760 0 0 0 860476381 5104688...
result:
ok 200000 numbers
Test #52:
score: 30
Accepted
time: 474ms
memory: 75924kb
input:
100000 200000 0 654076004 0 384031444 0 119374495 0 277579093 1 85876027 638148431 0 936480874 0 337004560 0 601574248 2 841095919 465239266 978449729 0 612063963 0 944928965 0 677239581 0 381653436 0 840246095 0 88260192 0 494499583 1 651377177 499867035 0 43926530 0 835699069 0 100921766 0 5710994...
output:
659159881 0 0 244713927 0 38053686 0 370345134 0 676351040 195874172 331050819 0 311975954 0 0 0 0 547003239 0 0 784593602 10749736 810352369 281275711 0 849350910 0 0 0 0 0 860912575 499058071 0 0 0 0 472871922 0 0 0 0 0 0 0 0 382020240 0 0 0 0 0 501714412 489877411 677514091 0 382886760 0 0 0 0 0 ...
result:
ok 200000 numbers
Test #53:
score: 30
Accepted
time: 507ms
memory: 58644kb
input:
100000 200000 0 767950655 0 819206798 0 632776873 0 615458376 0 748952719 0 164743123 0 484317825 0 364077066 0 416857111 0 21162008 0 892795892 0 54757732 0 501046447 0 795792626 0 18991377 0 37548129 0 522283271 0 522400896 0 27035995 0 207431962 0 960915263 0 289342447 0 903308477 0 986811346 1 5...
output:
0 0 0 0 320911640 0 0 0 835380661 0 101129300 0 0 436510016 0 721709531 0 0 532297750 910683734 0 0 0 482614108 0 0 0 404027771 0 0 0 472509567 0 421942867 0 813473143 175018943 0 0 139332966 0 0 0 0 0 831264950 0 0 956587496 479700944 0 0 0 472306267 0 0 896405196 0 0 0 0 0 0 0 44420065 674247742 0...
result:
ok 200000 numbers
Test #54:
score: 30
Accepted
time: 736ms
memory: 84568kb
input:
100000 200000 80 975550954 194913535 93700686 603729067 514440779 5168754 493927441 225485222 367936123 66713098 693546661 995088484 849731735 241941370 756949641 477954618 773614993 153565165 321282091 75959417 436627529 864112020 870058819 110164879 875241154 473099607 381812633 879132931 95273234...
output:
0 421673387 618293885 0 569777033 761083826 0 0 143262552 0 252024071 168883593 625390897 0 0 885716630 446743153 0 748901923 0 0 958947377 381449865 0 0 0 0 0 0 338243090 0 0 306769426 0 492995267 642640342 0 625868541 0 264120975 0 601461549 528185255 762292312 0 0 0 193716429 0 235099016 0 0 9188...
result:
ok 200000 numbers
Test #55:
score: 30
Accepted
time: 771ms
memory: 152412kb
input:
100000 200000 1 370861671 597066317 1 279824219 835160176 2 890487447 312744954 293454271 0 256787799 0 525148622 0 310156426 1 30788965 106411304 0 860888126 0 13034841 0 91907701 0 96687299 0 448250210 1 316241974 721488419 2 317152672 491377577 192877359 0 830289753 0 769751867 0 119369072 0 2154...
output:
0 495342720 0 932168052 0 597533739 0 0 95979658 0 589148997 271163162 861440993 0 38549103 868360666 89387346 0 0 378468426 0 0 0 0 0 549989891 839865697 0 733467239 0 0 740630196 575730895 221141247 0 223984070 417737077 0 0 0 383572216 727210228 0 996006344 0 0 0 0 0 0 115192594 99462280 0 209476...
result:
ok 200000 numbers
Test #56:
score: 30
Accepted
time: 637ms
memory: 72616kb
input:
100000 200000 0 855935515 0 503029155 0 530279261 0 946473936 0 32581962 0 601598388 0 288273127 0 425515309 0 728814403 0 797556500 0 70386731 0 693458131 0 178352976 0 934593143 0 810333890 0 650702505 0 132404762 0 557444214 0 187801602 0 713129003 0 206777009 0 579160604 0 51113448 0 786951044 0...
output:
439964729 0 101250422 377604701 0 928328203 0 311197502 0 761687584 0 0 365258170 0 939530105 191412194 0 0 879112407 536002240 0 369080761 695996586 464890584 0 0 0 0 0 860862436 0 0 791830786 52010983 0 0 0 0 0 903621456 340505284 0 0 0 0 0 0 0 0 157762756 730657042 406293120 247221862 0 0 0 0 0 8...
result:
ok 200000 numbers
Test #57:
score: 30
Accepted
time: 477ms
memory: 128952kb
input:
100000 200000 0 957889022 0 214078695 1 483864879 225025140 0 272321791 1 186288580 21482959 0 837319618 0 63552234 0 124514667 0 266485699 0 681756899 1 73283727 713211035 0 208369034 0 527424469 0 853819875 1 318538042 411538896 0 238374843 1 401815602 35413471 0 679451288 0 721170212 0 237460435 ...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 29283727 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
result:
ok 200000 numbers
Test #58:
score: 30
Accepted
time: 625ms
memory: 51940kb
input:
100000 200000 0 237677757 0 445038744 1 48499603 865005690 0 80453651 1 872325575 771904118 0 357606035 0 35698382 0 670168087 1 68812218 129958009 0 727178484 3 669452613 594874653 257476740 684536854 0 933422955 2 26415111 487769382 950606834 0 822838477 0 395410818 1 464093805 146648967 0 5402800...
output:
0 142431692 0 0 64525901 487482466 0 0 623335869 0 0 0 44757631 0 0 0 377565055 258331352 69775601 653608658 0 0 0 616970041 0 0 686456182 0 0 0 0 0 654294845 0 314063149 0 669527678 257486799 0 784911411 0 116961556 0 0 265128386 0 0 0 786118866 0 839678272 0 0 0 0 886976855 754239384 0 379664936 5...
result:
ok 200000 numbers
Test #59:
score: 30
Accepted
time: 829ms
memory: 77840kb
input:
100000 200000 0 564710724 0 208139081 84 824126092 287147669 859164352 91151335 630815103 51548342 878003285 701830355 258617205 894838138 961514745 511239843 848675884 55652377 908595648 210679303 878326125 349020875 810714103 246980554 33781344 344616238 841820124 279994891 579099712 812328036 667...
output:
33767043 0 114715016 0 0 689242238 0 0 0 0 29286069 249435181 0 0 0 111465282 830221170 0 571082250 0 0 710434908 0 0 0 820068292 562220327 0 233440294 0 0 0 0 0 289233587 0 102216699 0 557677325 0 629810979 0 0 0 670602664 0 626612356 0 0 0 0 975935882 937193482 791983888 560865529 0 171942466 0 0 ...
result:
ok 200000 numbers
Test #60:
score: 30
Accepted
time: 354ms
memory: 67000kb
input:
100000 200000 0 158275260 1 287953086 578797831 0 474574496 0 190421636 1 828207062 780536839 0 73629262 0 127353181 0 399256593 2 581386154 715563215 268353972 1 387565681 225637914 1 640238681 118929274 0 297084940 1 557699324 177235182 0 25121062 0 722998173 1 597523931 149714293 0 108543196 1 72...
output:
931454750 0 741621372 0 508359232 0 0 0 268403560 0 317163570 0 0 0 0 417499296 0 857602890 0 0 769309753 712999564 0 243212495 169057700 405270682 0 456986014 0 0 0 0 0 253419485 0 703169565 17102526 0 611555671 607560013 0 458232888 0 0 0 0 0 0 15394385 0 137706560 334513057 0 0 0 633320663 129680...
result:
ok 200000 numbers