QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#688744 | #6435. Paimon Segment Tree | Starrykiller | AC ✓ | 1154ms | 14944kb | C++23 | 57.2kb | 2024-10-30 13:18:24 | 2024-10-30 13:18:25 |
Judging History
answer
// Homura Akemi a.k.a. Starrykiller (/user/235125)
// I love Madoka Kaname forever!
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast,unroll-loops")
#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 <bits/stdc++.h>
using namespace std;
template<typename L, typename R>
auto range(L l, R r) { return views::iota(l,r); }
auto rev=views::reverse;
template<typename T>
_GLIBCXX_ALWAYS_INLINE void chmax(T &a, T b) { a=max(a,b); }
template<typename T>
_GLIBCXX_ALWAYS_INLINE void chmin(T &a, T b) { a=min(a,b); }
using ll=atcoder::modint1000000007;
constexpr int N=4;
using S=array<ll,N>;
using F=array<array<ll,N>,N>;
S op(S a, S b) {
S c=a;
for (int i=0; i<N; ++i) c[i]+=b[i];
return c;
}
S e() {
S c{};
return c;
}
F composition(F a, F b) {
// swap(a,b);
F c{};
for (int k=0; k<N; ++k)
for (int i=0; i<N; ++i)
for (int j=0; j<N; ++j)
c[i][j]+=a[i][k]*b[k][j];
return c;
}
S mapping (F a, S b) {
S c{};
for (int k=0; k<N; ++k)
for (int i=0; i<N; ++i)
c[i]+=a[i][k]*b[k];
return c;
}
F id() {
F c{};
for (int i=0; i<N; ++i) c[i][i]=1;
return c;
}
S get(int x) {
S c{};
c[0]=ll(x)*x;
c[1]=x;
c[2]=1;
c[3]=0;
return c;
}
struct Q {
int l, r, c, id;
};
struct OP {
int l, r, k;
};
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
// int T; cin>>T;
int T=1;
while (T--) []{
int n, m, q; cin>>n>>m>>q;
vector<int> a(n); for (auto &i: a) cin>>i;
atcoder::lazy_segtree<S,op,e,F,mapping,composition,id> sg;
vector<S> s; for (auto i: a) s.push_back(get(i));
sg=decltype(sg)(s);
vector<ll> ans(q);
vector<OP> op(m+1);
vector<vector<Q>> qry(m+1);
op[0]={0,n,0};
for (int i=1,l,r,x; i<=m; ++i) {
cin>>l>>r>>x;
--l;
op[i]={l,r,x};
}
for (int i=0,l,r,x,y; i<q; ++i) {
cin>>l>>r>>x>>y; l--;
if (x) qry[x-1].push_back({l,r,-1,i});
qry[y].push_back({l,r,1,i});
}
for (int i=0; i<=m; ++i) {
{
auto [l,r,k]=op[i];
auto f=id();
f[0][1]=ll(2)*k;
f[0][2]=ll(k)*k;
f[1][2]=k;
sg.apply(l,r,f);
f=id();
f[3][0]=1; sg.apply(0,n,f);
}
for (auto [x,y,c,id]: qry[i])
ans[id]+=c*sg.prod(x,y)[3];
}
for (int i=0; i<q; ++i) cout<<ans[i].val()<<'\n';
}();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3644kb
input:
3 1 1 8 1 6 2 3 2 2 2 0 0
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3660kb
input:
4 3 3 2 3 2 2 1 1 6 1 3 3 1 3 6 2 2 2 3 1 4 1 3 4 4 2 3
output:
180 825 8
result:
ok 3 number(s): "180 825 8"
Test #3:
score: 0
Accepted
time: 2ms
memory: 3960kb
input:
100 107 180 -280960553 266308104 -997644864 856103777 592874377 674379235 -946339772 641750362 642418716 -360811715 -555543246 206614021 358239245 349842656 983198973 807518446 -66612455 -980932737 109826132 -109676067 51226145 452115561 -42729559 -950621304 -87009773 714026474 375317493 693260053 -...
output:
400489222 480617351 531108525 254983761 446689548 764223236 142229431 307405789 39817281 66225912 247029353 46506707 529135498 578008236 201809860 674078444 746060191 171471121 722471473 657196163 861551838 606551808 360903956 401221326 767571915 669762004 163759234 141144218 579174939 276557168 518...
result:
ok 180 numbers
Test #4:
score: 0
Accepted
time: 3ms
memory: 3720kb
input:
295 269 129 -210918287 343352194 936488821 -682920910 944685019 677819690 -913857474 643356008 215752838 -582778677 735744580 307969642 807954422 388654459 761031712 -978166251 65058102 236039317 -205619898 -79984863 977152006 79198370 -999053192 -933631858 -776338105 -988909566 -427172257 -83477275...
output:
618251287 899907228 531858556 882858895 725455126 938410366 816431580 6908535 24554323 39964258 545169468 118739750 324108277 57969570 909045869 771733081 78663884 765348479 855417630 840946863 849560917 792963883 68199493 607258525 976267825 554521243 921526613 189188489 544501166 169313970 7657692...
result:
ok 129 numbers
Test #5:
score: 0
Accepted
time: 2ms
memory: 3716kb
input:
290 130 153 467014672 -187494410 -834410250 -221945583 -113569812 976227414 823657567 644961655 -718120549 900287103 634923088 999259803 -742330414 114542837 -69026244 941181808 998903438 650836591 381792036 -50293659 -391889416 -588686091 44623189 -916642412 -368524388 505979642 770338007 734336505...
output:
205306195 913174634 627098553 583511289 53628555 776119748 741459303 361721232 792181766 998349032 63183274 449140540 772865125 869222155 83821401 342565107 772194112 208578315 473166159 924882996 534863573 359442652 252396430 259427632 357792582 605715971 225467777 31224502 410770535 77000480 73685...
result:
ok 153 numbers
Test #6:
score: 0
Accepted
time: 3ms
memory: 3620kb
input:
184 292 178 -560085111 986691728 196865471 -958795491 238240831 979667868 -848892877 351600031 -849819158 973287410 -73789099 492724730 509559542 743289180 3773764 -844502889 -869426018 770666596 66346005 -20602454 534036445 135538767 -911700444 -604685696 942147293 -607021858 -32151743 -793696299 -...
output:
858202984 433975321 69198683 98775914 749936095 716134874 281147731 186709890 903234421 920600352 323335030 69435264 896305275 257633690 55255202 182091822 935500760 726305425 381037995 804018605 478673738 484297808 286861521 10149069 594778768 547188580 540808257 427373166 853802061 768386487 90138...
result:
ok 178 numbers
Test #7:
score: 0
Accepted
time: 0ms
memory: 3908kb
input:
179 152 127 117847849 -936264195 130999142 -202852895 885018743 -721924420 -816410579 353205678 -686550496 751320448 -174610592 889047621 959274719 469177558 -826284192 779877900 64419317 -814536143 -249100025 -793086029 262137073 -237378424 739866630 -587696250 -42148309 887867350 -834641493 -26761...
output:
505009166 348176298 768846383 639656852 767297876 334028836 672141959 865320262 32468111 824990615 935878450 39788029 776229057 745398975 622480518 927354339 667485118 767183633 797234162 637335006 725843572 397083849 891541202 474690368 807830014 546532554 370859947 512952106 797356109 977040750 56...
result:
ok 127 numbers
Test #8:
score: 0
Accepted
time: 3ms
memory: 3684kb
input:
173 215 251 482857384 237921943 65132814 -644735533 -173236088 -423516696 921104462 -742330725 886783639 -862755834 -883322779 677479818 -591010117 -902076112 951548559 994193216 -706768090 697403181 338311909 -763394825 -811937079 799769858 -216457003 -570706804 660632678 -520101420 657836040 -4576...
output:
532409264 425334301 297106918 497679015 766180735 997240773 876619970 775627119 369095265 141725042 860632646 806561262 693330436 844811627 533129631 666137230 797776768 349015941 304013406 366877046 285656333 796617951 263787451 188404775 795402622 368862072 922591321 853125733 448636483 903008737 ...
result:
ok 251 numbers
Test #9:
score: 0
Accepted
time: 2ms
memory: 3940kb
input:
168 151 100 -544242399 314966033 -903591478 -478727476 178574554 -420076241 -751445982 -740725078 -47089749 915277216 112997778 778835439 -141294940 -863264310 121490604 -791491481 834967940 -887799557 22865879 971329122 -475945758 426852667 827219378 -553717358 -28695654 71929823 758204255 14314631...
output:
352187626 704247599 53684196 147547097 652201927 257200097 626135496 49775525 672820311 189599120 469216129 487715787 155787875 856115710 757497826 561926086 567295451 568260936 378849834 906105482 480823862 527730971 133376678 862463926 443893047 318620602 549415798 799707998 458453406 462381509 43...
result:
ok 100 numbers
Test #10:
score: 0
Accepted
time: 3ms
memory: 3984kb
input:
163 213 224 133690560 -215880572 -674490536 -625642844 825352466 -121668517 -718963684 -739119431 -178788357 693310253 307143555 567267636 308420237 862624082 -100676658 -872143435 63780533 -767969553 -587547422 -96121722 155012833 53935476 773753709 560414138 987008757 -433180982 -44285495 48628183...
output:
747432440 517227949 996821749 805271519 840593989 22089777 153536567 999462554 483313583 174809962 671096506 911407220 301225235 350791783 414302958 610922065 348064356 221620487 622546838 251737080 930284090 787053181 512448105 483900137 418446165 774811006 614925836 789232720 98746705 671256184 88...
result:
ok 224 numbers
Test #11:
score: 0
Accepted
time: 2ms
memory: 4004kb
input:
258 174 173 -893409223 958305567 -740356864 -459634788 -527869635 176739208 -981448656 967518958 -15519695 176376021 -991503172 668623257 758135414 -508629589 -930734614 -657828118 -707406874 743969771 -902993452 -66430518 -919061319 -613948985 -772504464 577403584 -310210269 158850261 -846775245 55...
output:
763779848 971203287 417629333 128055735 17327247 15630176 25359233 62738585 361956876 281789376 957004306 7982723 694276684 450550861 225480663 650754963 57977660 889194726 638963520 880818703 608956290 276560765 718925350 342938575 243384787 865317875 569251525 302758871 232054208 811410731 1124094...
result:
ok 173 numbers
Test #12:
score: 0
Accepted
time: 0ms
memory: 3680kb
input:
224 261 183 321076468 14144917 -964309122 -998152041 -233777241 498830290 -124389333 152924562 100565362 -951633735 -51153541 -539047258 -158691246 266759044 -656520429 -577382886 -383476274 -274905450 -161914533 -572427748 644517420 376447356 -227879896 -972623510 702539156 -675224598 698346506 -17...
output:
322262446 309629779 753522996 746794296 331484522 808430979 727359918 533145896 642265099 611737090 791371384 936246806 480013565 761553227 859970290 114739196 147749092 992690312 222043170 425264912 61368448 532877858 131993381 347759625 310385807 693085135 594668938 342481048 673051834 663459641 1...
result:
ok 183 numbers
Test #13:
score: 0
Accepted
time: 6ms
memory: 3692kb
input:
500 500 500 702413239 -895672661 513406482 -706023315 -811668957 -735208181 -537176715 118033401 207303475 203060235 -140437061 -31133246 -878633428 945167015 -142724367 291023931 895505386 218454358 -658034840 845336331 139891825 -182393293 -837703814 -429556732 -291437105 -281345565 -660666794 132...
output:
799094138 146472194 58171908 40775791 547185279 571631473 320570241 279864315 784754669 36384176 647854975 369168115 86332530 547176983 240323948 240924775 72654152 69035557 647102037 39065205 809733534 122261401 419058965 996509642 840422954 505500073 254560823 567513427 197957750 174710109 8980857...
result:
ok 500 numbers
Test #14:
score: 0
Accepted
time: 6ms
memory: 3816kb
input:
500 500 500 -124873923 -862644826 -949273940 266876915 -439657598 -801074509 -979059352 -940221430 505711199 -59424737 -138831414 -965006634 899399622 -860687221 -649259440 740739108 621393765 291254366 -443719524 -220818346 -348168865 -497839324 -513045340 201401859 -959321566 762330816 -643677348 ...
output:
726058600 157394298 6026295 626157799 473455503 836929915 65432281 223447620 258103506 201786082 245837249 839381477 776736180 495914531 234139152 826978202 609481390 609186653 448424325 37801505 772356936 176131960 94645367 507234205 491293083 51500902 336742281 8572500 581656090 337181638 19093229...
result:
ok 500 numbers
Test #15:
score: 0
Accepted
time: 6ms
memory: 3996kb
input:
500 500 500 -952161085 875415752 980154970 336919180 734528541 525168482 -813051296 -293443518 804118924 -26942438 157741502 608327501 382465389 135633335 -252936549 -809545728 660205567 -538803590 -229404208 -89147789 -228338860 89572610 419503829 224469756 -235096708 -488960087 -626687902 -2683037...
output:
948178708 63043518 412562474 979471847 632004126 197149770 44765001 333070147 209208490 245340835 327984181 86381120 108549140 206693435 696566524 692690063 761978712 63394241 115659288 133306357 949561112 412838504 951662013 614320278 450808891 653747562 528431330 653894325 459172133 26721646 92240...
result:
ok 500 numbers
Test #16:
score: 0
Accepted
time: 7ms
memory: 3744kb
input:
500 500 500 220551766 318509048 -482525453 -985147873 -91285334 164334884 -959966664 58367124 807559378 300507130 -135620121 771596163 160498427 34811843 -759471622 -64863281 -711048103 -466003581 -310056161 844697547 186458414 -225873420 449195033 855428348 -608013899 -837393026 -609698455 13950992...
output:
862364241 846328796 782119369 279661198 954588064 332802857 198320732 828750538 842000005 545677700 631170861 739609232 88580357 709394833 410740136 881387963 388869353 282008286 748754853 160380786 98885674 125774059 463282867 88796885 879824305 396598644 823020688 334851683 682882712 847429599 888...
result:
ok 500 numbers
Test #17:
score: 0
Accepted
time: 6ms
memory: 4044kb
input:
500 500 500 -901702666 351536883 -553096556 -12247644 -14241244 98468556 -793958607 -999887707 -894032910 38022158 -134014475 639897554 -61468536 -968867614 -363148731 -518006068 -985159725 -688170843 -390708115 73510139 601255689 -836286721 478886237 -218645804 724101653 206283354 -592709009 -54981...
output:
879478176 44895837 222778896 299056760 459849951 413838727 271861909 135172325 369876017 772291349 288915506 40518418 120722520 489004058 795467085 440669676 679489168 686147119 484183055 276961468 387433763 227355653 842643573 798414401 667476501 635395856 510642724 792257092 437757870 921878747 36...
result:
ok 500 numbers
Test #18:
score: 0
Accepted
time: 3ms
memory: 3812kb
input:
500 500 500 -23957085 89597448 279190305 665685316 -840055119 -575288467 -332983281 -648077065 -595625186 70504456 -427376098 803166216 324455195 -774721837 -574716534 -363258160 -356413382 186803944 -176392799 -89786574 113194999 -248874787 508577442 412312787 351184462 -750040278 -575719563 465886...
output:
796480339 557837848 754107862 815827346 414562979 472887526 461802193 704671280 150724230 889392203 410794501 355361325 755045478 230684672 469082755 160421817 613888058 880851910 81781514 275777155 469039160 274812243 382134369 90336156 83487675 755510237 502221402 519154393 272454262 984290073 699...
result:
ok 500 numbers
Test #19:
score: 0
Accepted
time: 6ms
memory: 3740kb
input:
500 500 500 -556276977 -974516765 816509895 735727582 629098290 -641154795 -774865919 -1299153 -297217461 397954025 -425770451 -425674441 102488232 221598719 -178393643 86457017 -630525004 259603952 -257044753 844058762 233025004 -564320817 -263906133 -661761365 -21732729 -1331168 -263762847 8736997...
output:
430703521 264296600 450750921 819273205 764437218 898752834 45110599 31736921 270581198 820706868 583121122 706134979 774622614 982742936 341484311 656982673 880764494 460796214 464341544 193506837 403410316 168844313 654226247 921525043 207675841 601386662 604116713 804815031 780918170 556319636 85...
result:
ok 500 numbers
Test #20:
score: 0
Accepted
time: 6ms
memory: 3812kb
input:
500 500 500 321468604 763543813 745938792 -586339472 706142380 -412053853 -313890593 645478759 -293777007 135469053 478693159 -557373050 -119478730 415744497 217929248 536172194 -591713202 -865421273 -42729437 -222095915 647822278 -879766847 -234214929 -933660738 -689617190 -54796837 -246773401 4793...
output:
99643867 797790680 117520301 52202392 750645517 708216290 41516009 835813051 977083646 977651719 730889761 289737413 425913664 845931313 563046428 367920130 455303169 324460957 330372383 916507678 470615106 571780062 981697429 286596333 568468983 29449857 156959753 537748583 968861047 328057384 2612...
result:
ok 500 numbers
Test #21:
score: 0
Accepted
time: 6ms
memory: 3744kb
input:
500 500 500 -505818558 206637109 -421774360 681528028 -414638765 619221868 -755773230 -707743342 4630718 167951351 185331536 -689071658 -341445693 -587934960 -288605825 985887371 -865824823 -792621265 -123381391 -90425359 159761589 2612356 -499490994 -302702146 642498362 988879543 -229783955 -504956...
output:
516027113 339960641 489756734 355729464 725784885 222560920 681515130 426514409 475293251 502597154 50178091 756157988 28579538 564199781 754874794 514003796 749624739 289019012 672003817 901814808 7682411 338820429 686389969 644898154 678031469 103954649 681979482 17471041 4440262 543919815 3165571...
result:
ok 500 numbers
Test #22:
score: 0
Accepted
time: 7ms
memory: 3812kb
input:
500 500 500 -347877860 527039679 48889269 423854846 -285585489 -909443324 83088136 -755862860 -342498224 -356043217 170471024 325807447 -511588712 -818997308 -358183 -669803979 -595710417 513262231 -929467517 164182054 -462596490 -79245066 345522978 -223646976 595580352 -657224741 -923381515 -895054...
output:
969965606 18264751 629305960 27286696 162768537 126384997 545402051 188094206 407060997 206670050 716310712 535000164 143845354 998379114 177833472 618210301 982753253 633108530 647352469 861145917 616175682 65506261 856210146 100547662 645637137 6039651 576222559 808554231 307695396 592645172 14327...
result:
ok 500 numbers
Test #23:
score: 0
Accepted
time: 760ms
memory: 10140kb
input:
30976 35179 40169 493897111 888600649 -975309652 -653761772 -109084948 -339057770 -323560919 172076671 194108839 -733555675 177323248 -801860526 -220088802 -261931344 291094970 -715152201 295852610 -950657180 -394691096 375214182 -495546348 222663161 -710690410 -906392069 415617168 457144628 -484651...
output:
46341209 997384397 950488515 880577381 375257170 314721120 156703815 783764888 585385783 218371806 505978258 290823773 97757571 88511309 68018513 533033979 269812217 775847487 591945012 740085563 597329525 10424245 181307192 753319789 394603730 546533807 503735790 628994999 34437448 68508764 9516834...
result:
ok 40169 numbers
Test #24:
score: 0
Accepted
time: 762ms
memory: 13076kb
input:
33559 33197 32218 -533202672 62786775 -746208710 102180824 537692964 -40650045 -586045890 -121284952 357377501 -347631944 76501755 -110570365 229626375 -536042966 -243995716 -795804155 -770302067 -535859905 192720838 404905386 135412243 -445221300 332985970 -594435353 -273711164 -47966178 712859087 ...
output:
661408620 883039430 655607633 320305584 608991919 708269037 724364884 648497371 466222603 902610255 682226559 935071350 906857400 102381762 789417646 519996983 269881403 293864597 319515564 124414314 253285433 768530221 25242000 722517507 70496856 933049360 835531898 536069595 902460658 502132452 25...
result:
ok 32218 numbers
Test #25:
score: 0
Accepted
time: 921ms
memory: 10764kb
input:
31025 41512 42008 439697558 434798135 285067011 -634669083 -815529137 257757679 -553563592 783178658 -871463157 -569598907 -632210431 -912072708 384374282 92703376 -466162978 -581488838 -638631510 -121062631 -122725193 -662545458 -938661909 -818138491 786727811 -577445907 134102553 544065066 8132273...
output:
104154550 636719266 672445873 521784998 388849013 403232035 103746236 510001288 922372536 983032201 316241735 486520512 23675597 220393145 956990774 398774286 717153424 157368210 37588637 645574476 532850485 512500425 211278932 8524610 155292579 304469258 183693392 612597955 979616360 783454755 9837...
result:
ok 42008 numbers
Test #26:
score: 0
Accepted
time: 891ms
memory: 13548kb
input:
41050 32087 44355 -882369496 -391015740 219200683 -173693757 -463718495 261198134 -226114024 784784305 996838248 -791565869 -733031924 -220782547 834089459 -476375515 703779079 729968527 295213826 -1232626 -438171223 -337886984 -307703318 808944331 -169595822 -560456461 -555225779 333921530 10737551...
output:
699230737 631303224 680676353 746898772 921147020 508953443 682548856 210051385 134195677 263295351 358416302 102499310 812639565 634746682 598909309 179011382 639567328 228291778 273934347 629893397 161741784 900081127 65142039 108896554 932568448 982588840 694316110 280088865 717518571 761170947 2...
result:
ok 44355 numbers
Test #27:
score: 0
Accepted
time: 784ms
memory: 13068kb
input:
38516 30105 36405 -812327230 -608938920 448301624 287281569 478026687 559605858 -488598996 786389951 865139640 691499911 558255902 -727317620 380946672 152370827 481611818 354349303 -770940852 -489293316 -145726559 -308195780 618222544 436027140 -223061491 -248499745 460478632 630985503 -496784928 -...
output:
132961294 348386401 594429344 364192801 275872392 887837116 492084187 478850839 227154931 362355328 710380954 471717720 215642858 424650813 798378640 752095758 498803711 112670643 881853754 70560672 170211753 123450414 590338715 81179425 730958764 500872481 638525088 27880574 851626964 451862153 700...
result:
ok 36405 numbers
Test #28:
score: 0
Accepted
time: 1129ms
memory: 14364kb
input:
48541 48123 46195 160572999 565247218 -520422668 -154601068 829837329 858013583 -456116697 787995598 -971591712 469532948 457434409 -330994728 830661849 -416708064 259444556 568664619 -639270295 -74496041 -461172589 -278504575 346323171 -526824591 820614889 865631750 -836740394 420841968 700725335 -...
output:
378481395 351044147 787515091 732223322 8696638 325218000 258700177 179011676 819069760 903381184 459107749 59531701 6255066 644726995 580640172 153135117 573170083 595056741 668245274 607887910 239626636 750137596 253375172 890538316 159766606 815292452 781106359 332339306 33507190 863901941 912045...
result:
ok 46195 numbers
Test #29:
score: 0
Accepted
time: 1017ms
memory: 13792kb
input:
38565 46141 38244 838505959 -260566656 -291321726 11406988 -523384772 861454037 -128667129 494633975 896709693 247565985 -251277777 65328163 -719622987 212038278 -570613400 782979935 294575041 340301234 -481651350 359077323 977281762 -899741782 -430676013 882621197 178964017 -987126802 193202855 -45...
output:
753850336 502252689 802403482 978398393 117851985 798841877 43995632 516285864 579060912 361345165 740413781 441373174 226139974 882322891 827957052 64198003 820220944 442452875 774697027 440917528 63578196 217485523 685698879 159151553 460641308 189366603 841900015 613978928 298106290 566344472 763...
result:
ok 38244 numbers
Test #30:
score: 0
Accepted
time: 992ms
memory: 13888kb
input:
36031 44158 40592 -188593824 111444703 -357188054 -135508380 418360410 -840138252 -391152101 496239621 -332130964 928456987 -352099270 -441206910 -269907810 840784621 -792780662 702327981 -476612366 -442726726 -797097380 388768527 -96792390 727341040 -484141682 -805422100 -510364315 -395095558 -6092...
output:
218099207 441534512 348953852 307702032 199585323 886817307 952366094 373272821 414910543 167557341 794363613 416150824 770487173 167472124 572336401 815720303 364468162 394790493 10323415 127001500 843766306 96603026 480184090 721593917 235716073 894024128 794648367 172306236 816345189 439706791 24...
result:
ok 40592 numbers
Test #31:
score: 0
Accepted
time: 983ms
memory: 13988kb
input:
46056 45031 40084 489339135 -714369171 379120397 325466947 -132686912 -541730527 -358669803 202877998 -463829573 706490024 644221286 -44884019 -115159903 271705729 377161395 916643297 -639909080 -27929451 -504652716 713427002 534166201 59456579 559534698 -788432654 -102550599 -900206364 588223369 -1...
output:
664819303 799746579 923774208 594766628 579158619 983662223 55387977 160414858 808857608 740952408 499027547 434237500 698323449 582287616 36543143 958333643 694916160 319725402 467047755 632374377 8167929 455183029 325233930 586113339 376850009 994136907 626970498 9979936 395110261 982706983 165704...
result:
ok 40084 numbers
Test #32:
score: 0
Accepted
time: 888ms
memory: 13560kb
input:
42419 34754 40219 -81257471 -880283165 -854577525 261470348 -180806430 -888859469 20193593 -909124563 256082263 241379735 413158938 -954461611 524116030 246852865 585902843 110557171 -90334398 -60352991 -291542868 -441559039 -289636592 12538570 913430427 517969798 410209796 -497406597 -357636629 -53...
output:
928070962 853950805 542939619 982613561 794645945 212795670 871529435 17236586 139226933 817619804 326557170 567618911 739659580 508266934 978468129 547378009 120827330 237229657 556423452 742001152 221768690 298561715 226249912 497497385 25493016 761671683 250057079 779706492 323074294 119412064 72...
result:
ok 40219 numbers
Test #33:
score: 0
Accepted
time: 1039ms
memory: 14040kb
input:
39885 45330 42567 596675489 293902973 -625476583 427478405 465971482 -885419014 52675892 -907518916 419350924 19412772 -590520519 -263171450 973831207 -27258756 -539122383 29905218 -548598381 -843380950 -606988899 -411867835 636289269 -360378621 -42893206 534959244 -279118537 -707550133 839873634 -3...
output:
502476096 506934774 952833153 393266087 322134977 776938966 690976245 794548023 559849553 779414963 662675454 256414850 802855538 162511556 455260051 71778548 652326757 707432184 389742096 808591613 604729355 542666837 505957394 493947674 836707756 143276576 934371764 627099456 352932726 949779805 6...
result:
ok 42567 numbers
Test #34:
score: 0
Accepted
time: 989ms
memory: 13828kb
input:
42468 43347 42058 -430424295 -531910901 -691342911 -14404233 -887250619 -587011290 85158190 799119474 287652316 -202554191 -396374742 935326220 -576453629 601487586 -171355105 244220534 680214225 -428583676 -19576965 -382176631 -732752152 971736931 -96358875 551948690 128695180 -410486159 940241848 ...
output:
23667705 172505419 471332034 487482354 51081815 576449668 330671133 107850233 208744607 84722510 849204755 577806670 923783607 716939389 632072588 29738872 763433944 700208199 30561046 101952420 558620702 696997621 652421567 444898639 273125245 320007945 358506981 238545632 693696287 815389780 37015...
result:
ok 42058 numbers
Test #35:
score: 0
Accepted
time: 1024ms
memory: 13796kb
input:
39934 41365 44406 -655349299 -454866812 339932809 446571093 -240472707 -583570836 117640488 800725120 450920978 -719488424 599945815 -373383632 -126738451 935266659 703619683 163568580 -385940452 -13786401 -335022995 -352485426 -709684255 303852470 652350235 863905407 -855600422 -915596965 137752098...
output:
556693908 99643681 869465 651413204 907743016 509005791 758173775 81832327 739278689 437746268 510885966 991574019 982417149 723595894 937420340 245214387 870380711 883921055 536231784 521178561 276335686 851435784 357468610 13300817 385244297 777375139 274728175 808208796 924077879 865949191 897231...
result:
ok 44406 numbers
Test #36:
score: 0
Accepted
time: 935ms
memory: 13928kb
input:
49959 42238 36456 612518201 -985713416 569033751 907546420 111337935 -285163111 150122786 802330767 -777919680 -38597422 794091592 -879918705 322976726 661155037 481452421 377883896 -254269895 -796814360 -945436296 580063742 -78725664 -69064721 -598940667 880894853 750038529 -28598451 -664737651 452...
output:
252413152 532119424 406448928 269144049 249582589 519220730 354313721 582284613 953291124 555035962 230819422 302946127 374805829 417162715 571155180 590462404 940453267 261109987 143599243 16721068 389744778 472500517 589256476 537870601 115108721 997191074 477282477 296730974 148082717 928587673 7...
result:
ok 36456 numbers
Test #37:
score: 0
Accepted
time: 1019ms
memory: 13824kb
input:
39983 47698 38803 -709548853 188472722 208200153 170696512 -946916896 13244613 182605085 508969143 -909618288 -260564385 85379405 -483595814 -130166061 994934110 -348605535 592199212 974542710 -382017086 -63057092 314787676 552232927 -441981912 -652406336 602917029 -842147767 -533709257 827739882 92...
output:
515602599 840773175 782418 248297677 872540642 793118823 593048288 531378318 401541593 891383103 133384969 371454219 772475679 214356385 473486068 630247370 437364081 180882921 544208093 214356385 292831564 691233913 994048553 279691874 405323791 127202068 479845414 88521425 559627127 60697117 39923...
result:
ok 38803 numbers
Test #38:
score: 0
Accepted
time: 845ms
memory: 10128kb
input:
30007 38273 38295 263351377 265516812 -465556869 926639108 -595106254 16685068 -79879887 805542060 -746349626 -777498618 -310409358 -695163617 24581846 720822488 -570772797 216579988 811245997 -262187081 -378503122 639446151 -521841225 -814899103 391270044 914873745 173556644 58321986 25250132 49396...
output:
312959125 751651242 523591358 382940310 923615456 443417811 723517833 384124779 257474267 614631633 163902128 476695623 363962378 357357459 834983087 855201376 623046498 438620716 937051905 426662914 435639371 224782583 693786506 742154114 341448090 768997127 903736270 664732051 680247267 270893938 ...
result:
ok 38295 numbers
Test #39:
score: 0
Accepted
time: 1007ms
memory: 14160kb
input:
47475 36290 48085 941284336 -560297062 -531423197 189789201 51671658 315092792 247569681 -584961612 -878048235 -704498311 980878469 -593807996 474297023 -650431183 -497972788 430895304 40058590 -750247771 -693949152 669137355 109117367 517216449 -565053589 931863191 -515771688 650353230 -777239617 -...
output:
736331601 461303388 621211408 206999831 686128835 72823391 396257059 205006948 180309060 671228864 124902281 943884441 596713243 373136061 829767275 463515905 626442460 228494758 280595114 12216258 97538493 201821746 706963996 131531125 813319379 895770026 517084977 90941182 929570558 266860229 1403...
result:
ok 48085 numbers
Test #40:
score: 0
Accepted
time: 777ms
memory: 13048kb
input:
44941 34308 30431 -988673411 -483252973 -597289526 650764527 993416840 613500517 280051979 -583355966 -714779573 -926465273 -22800988 97482165 924012200 780489939 377001999 350243350 973903926 -335450496 -106537219 -398313490 132185264 144299258 -913486527 948852637 187009299 145242424 420270646 -26...
output:
678203604 191590724 727913144 355103440 233633207 639152924 334921232 319823541 765601151 83534178 386820815 800846205 373628171 886661101 224685715 337761600 463174138 260928709 696364993 245691459 254403765 946396169 839196141 302832330 45693002 282324168 671736586 905441918 85229817 870643346 559...
result:
ok 30431 numbers
Test #41:
score: 0
Accepted
time: 1122ms
memory: 14400kb
input:
47524 44884 49924 -15773181 985900436 728953465 208881889 -654772531 616940971 17567008 -581750319 -238587487 556600507 171344789 -704020178 -626272636 -590763732 744769277 564558666 -894425531 79346778 -716950519 -368622286 763143855 573556846 130189853 -739190660 -797286303 737273667 -87251834 -99...
output:
814581235 718931323 297723760 833028295 709557033 764991341 44533879 803178657 881187924 796394089 783408721 528684423 60019194 739624667 862850936 70957920 430251722 387029870 734617070 97963166 835904907 119127654 627625478 758270100 45651438 406012443 647099169 148891812 43808501 858322934 374566...
result:
ok 49924 numbers
Test #42:
score: 0
Accepted
time: 911ms
memory: 10768kb
input:
31328 44904 42617 21520906 525019171 -504744456 -952256758 -702892048 564779299 -506427560 -891578101 481324348 -710684561 -962575523 -415772535 -281963973 -320649325 -244314509 -241527459 -934785389 849098018 -503840671 -426466277 -60658938 -570503213 484085581 -335646171 -284525909 42931386 671920...
output:
185780195 274329194 243407060 313613843 308238682 399989560 433786743 252918088 42774324 239780808 286808755 27549098 230579907 900861122 160145833 595559598 278428902 619336579 31088691 432947341 884445910 726849634 334525048 801265998 18613500 813771576 208617668 963623393 652253376 317808904 6152...
result:
ok 42617 numbers
Test #43:
score: 0
Accepted
time: 1137ms
memory: 14636kb
input:
50000 50000 50000 674028042 392361958 123922920 91563172 -5827433 -865578055 605860618 -56114136 568219754 -473945262 -889972454 644593010 -932651524 936602997 -922307608 167751204 815304526 -171514501 -27212143 -803114832 -736104720 83571263 506082891 865266923 761612339 -472238051 -318656725 12328...
output:
737969576 10553619 620023180 716422679 219924644 737617398 912695130 306514688 157060903 899492976 27194127 535399030 649491971 560447882 113292414 648548885 533005301 988697279 510038820 373986172 894649465 338936132 388611497 738715407 978774054 506798175 910184557 144751598 303344241 964091520 96...
result:
ok 50000 numbers
Test #44:
score: 0
Accepted
time: 1136ms
memory: 14680kb
input:
50000 50000 50000 -153259120 130422523 956209781 769496132 -831641307 165697666 -933164069 590663776 571660208 -441462964 14491157 512894401 550414256 -67076459 -525984717 617466381 -555949145 703460286 -107864097 130730504 -321307446 -231874768 830741365 -503774499 388695148 -525703720 -301667279 -...
output:
871870025 156055780 845980859 738375577 269009227 802638169 721686197 226735856 771120264 522084796 170449908 601160588 456841642 178945926 734158618 658611836 757099522 935334817 762961787 999872735 612803656 317246670 123300527 526486215 715132612 228948906 264677560 994254466 979480855 10335758 2...
result:
ok 50000 numbers
Test #45:
score: 0
Accepted
time: 1141ms
memory: 14644kb
input:
50000 50000 50000 724486461 -131516911 885638677 -257603652 -754597218 394798608 329986036 -762558325 870067933 -408980666 -278870467 676163063 328447293 -167897952 967480223 772214288 -830060766 776260294 106451219 -640456903 895664608 -547320798 860432570 127184093 15777957 223005390 -284677833 74...
output:
989576751 271469626 331854599 885693011 770199090 100141589 59080796 651397273 883620703 220848590 743214542 390302738 507783814 793600877 996327406 884142280 497140694 61803127 704786135 232816789 61263940 66431045 291822982 343336669 572349138 811447518 234314935 945876011 580612086 533893125 1041...
result:
ok 50000 numbers
Test #46:
score: 0
Accepted
time: 1140ms
memory: 14756kb
input:
50000 50000 50000 -102800701 -393456346 -282074475 420329308 419588921 328932280 -914071381 -410747683 -831524356 -376498367 -277264820 544464455 106480331 -876610139 -636196899 -778070548 -201314424 -348764931 25799265 -803753617 -689538131 -862766828 -501985545 -946890059 445035545 971714501 27278...
output:
688727722 60948626 127327346 15296134 11061227 704966245 109650180 428739874 681485346 633091939 533527374 415453189 736650885 969209089 321893860 329695403 334271407 887485406 778485047 792913742 918682447 743512129 515398461 551424150 430826855 598223639 991117123 562419342 352200613 292717799 219...
result:
ok 50000 numbers
Test #47:
score: 0
Accepted
time: 1144ms
memory: 14732kb
input:
50000 50000 50000 -930087863 247462183 255245116 -606770475 -406224954 -344824742 -748063324 530997499 -828083901 -344016069 -570626444 -684376203 -410453902 -977431632 -847764702 768786678 -475426045 -275964923 240114581 425058989 -274740856 -275354894 -472294341 781210581 72118354 15390868 4426832...
output:
945997819 908835721 159596094 927662929 106638943 981434142 273177766 803020351 878999966 61296144 435780293 885677777 315502911 434418211 894373516 644936363 795295559 984902994 524374814 367208839 686259457 826916721 363609672 868635919 602232760 153531821 165491555 684300021 849649412 97430237 26...
result:
ok 50000 numbers
Test #48:
score: 0
Accepted
time: 1144ms
memory: 14784kb
input:
50000 50000 50000 242624988 280490019 -110293258 -536728210 -34213594 -410691071 810054051 -822224602 -529676177 -311533771 -569020797 -816074811 565404369 313856195 -746409081 -781498158 -436614243 599009864 159462627 -346128418 -762801546 -590800925 -442603137 -292863571 -595766107 -38074801 61257...
output:
192767965 260136054 290992294 480760301 268229025 215333968 593247471 655071089 39008428 625146457 75162763 434944886 433380927 923630761 251366026 840525965 773189585 261055764 643147097 282868274 96026209 790598352 706360479 632326476 542298673 881488673 190073670 566401763 35915367 790724910 4031...
result:
ok 50000 numbers
Test #49:
score: 0
Accepted
time: 1139ms
memory: 14640kb
input:
50000 50000 50000 -879629444 18550584 721993603 436172020 -860027469 -476557399 -728970636 -470413960 -231268452 -279051472 -272447880 -652806149 343437406 213034702 -55118920 -331782980 192132100 671809872 78810673 -509425131 -642971541 -906246955 -117944662 43127750 -968683298 -994398434 373214492...
output:
395336063 588825091 214068731 271315962 788937616 563944155 983790315 148936928 98980418 643311933 198372057 634855134 530230270 346931320 107160709 219653547 24119335 779408199 407694935 218344002 745941931 323989590 712629760 473679839 469727905 30905339 352133400 324025068 237260281 693812105 180...
result:
ok 50000 numbers
Test #50:
score: 0
Accepted
time: 1154ms
memory: 14728kb
input:
50000 50000 50000 -1883863 -243388851 651422500 -885895034 -782983379 -247456457 829146740 471331222 -227827998 -246569174 -565809504 -784504758 -173496826 -495677485 -856621263 117932197 -81979522 744609880 293125989 424420205 -228174267 -613802291 814604506 969053612 363432254 -245689323 390203938...
output:
428105572 275939771 437675993 874797861 340550920 275468988 483724528 412730750 533117990 213505312 884073079 755167150 780997605 426933096 717241618 688669890 210583537 743860192 777614486 749651177 758442258 313246374 405302645 683387432 224185432 695430706 599934870 455730309 18094650 749266251 2...
result:
ok 50000 numbers
Test #51:
score: 0
Accepted
time: 1141ms
memory: 14712kb
input:
50000 50000 50000 -534203755 -505328285 -811257923 87005196 391202759 783819264 995154796 823141864 70579727 -214086876 -564203857 -621236096 -395463789 -596498978 -165331102 272680104 546766821 -85448075 212474035 261123491 186623008 -929248321 844295710 -399987810 -9484937 -299154992 407193384 507...
output:
595887661 422933791 281766814 113964065 110544176 891999647 621601416 650944521 273426135 905737378 486108697 767512389 916075180 650018768 864820311 353016514 664254150 386719559 929165407 236365734 897843170 549014848 364661856 106860297 536269964 985853102 553295984 720396467 190662315 17368715 9...
result:
ok 50000 numbers
Test #52:
score: 0
Accepted
time: 1151ms
memory: 14660kb
input:
50000 50000 50000 720878993 422964979 -340594293 -778558680 -677569199 -744845928 931158198 775022346 -884439909 966951299 28826325 98675739 -860574078 -25386547 925091319 -793076706 -380944007 123293372 798497229 515730903 661406978 -716138474 786451719 776209410 -56402946 349708006 -286404177 -177...
output:
424370819 898014889 118543047 736912097 458772746 58178103 150731182 913387569 624441542 541632503 27906000 788862205 955371708 611885018 447457643 786472080 805379759 325346392 221958339 653692449 692401708 188028282 594467166 602105088 427659005 451554369 494806247 79212830 308358303 265529658 496...
result:
ok 50000 numbers
Test #53:
score: 0
Accepted
time: 1148ms
memory: 14604kb
input:
50000 50000 50000 -401375439 161025545 491692567 194341550 -600525109 -810712256 -607866489 -578199755 824033288 999433597 -264535298 869835095 917458972 168759230 -383618533 -638328799 247802335 998268160 717845275 647401460 -923795761 166240730 -280999126 -297864742 -429320137 -901582896 -26941473...
output:
795027632 930172317 609216241 200109886 623598479 443083390 310050599 800740326 398288998 233052387 73893431 775815853 677703782 435802979 267185187 776479650 866505928 122571242 416142913 656191219 353303877 271238861 457466825 117896627 737723286 237396726 733369100 80846583 191141531 398084026 29...
result:
ok 50000 numbers
Test #54:
score: 0
Accepted
time: 1139ms
memory: 14808kb
input:
50000 50000 50000 771337412 -100913890 -676020585 872274509 868628299 515530735 -754781856 68578157 25298964 -968084118 32037619 738136486 -401650040 -834920226 814879137 -188613622 581581408 776100898 932160591 -123785947 588143563 -149205300 -546275192 -569764115 607828145 -152873786 42541985 7392...
output:
389059872 543219376 669715865 314960171 353866496 576849433 297852105 688174263 660853317 112291099 646155507 101297410 831223766 917886852 273879085 331369652 245618934 360361278 976984872 82022109 358621448 455306335 638522813 190616247 70142931 840832524 127493693 610335093 13695277 275289430 339...
result:
ok 50000 numbers
Test #55:
score: 0
Accepted
time: 1145ms
memory: 14644kb
input:
50000 50000 50000 -350917020 -67886055 -746591688 -154825274 945672389 449664407 -588773800 -187501895 323706688 -935601819 -261324005 901405148 -918584273 -640774449 -493830715 261101555 307469786 -53957058 851508637 810059389 -997059176 -759618601 -516583988 61194476 234910954 -206339455 59531432 ...
output:
951887062 103788627 63546856 227947039 318774282 965301751 736905688 912070602 448613246 438248431 194536974 107753476 121349232 831494932 873609436 251925847 808048653 90328724 885436074 730764402 925772410 472664644 29554110 562640200 467484409 266080551 858075036 167638652 569165451 213951186 276...
result:
ok 50000 numbers
Test #56:
score: 0
Accepted
time: 1132ms
memory: 14808kb
input:
50000 50000 50000 -883236912 -329825489 -209272098 -84783009 119858514 678765349 -127798474 164308747 327147143 -903119521 -259718358 769706540 859448778 355546107 999634225 710816732 641248859 -276124320 -934176060 941729945 -877229171 -172206667 -191925513 987120337 -138006237 837336925 76520878 1...
output:
805337669 529161281 847436089 526927147 703366960 703126174 225382246 314689078 815119398 235755261 274474664 551806450 331270950 126307097 977507014 612167659 659117489 385299407 478888698 593346316 310643079 232761071 674908122 742062038 253023722 777785567 277055586 139964128 259711789 633838270 ...
result:
ok 50000 numbers
Test #57:
score: 0
Accepted
time: 1137ms
memory: 14672kb
input:
50000 50000 50000 -5491331 -591764924 -574810471 593149951 999077383 -289958944 -569681112 -893946084 625554867 -870637223 644745252 932975201 932449085 549691884 -604042897 257673945 367137237 893817737 985171999 -419392002 -462431897 -487652697 740623655 -381921084 -805890698 -413953977 388477594 ...
output:
311391793 661021829 690797548 717883970 435809372 128133467 988112940 695729110 194332160 481958913 809452536 630749954 917636177 285997810 995222227 575792537 140977416 71000404 305926148 491291270 267407706 893473989 773390932 756610864 60338881 845209795 741198421 184072709 692861511 582267087 20...
result:
ok 50000 numbers
Test #58:
score: 0
Accepted
time: 1134ms
memory: 14784kb
input:
50000 50000 50000 -832778493 49153605 257476389 -433949832 -923878540 -355825272 -108705785 -247168172 923962592 -543187654 351383629 -590832726 415514852 -453987572 -207720005 707389122 995883580 671650476 904520045 809420604 -950492586 -803098727 770314859 544004777 821192124 -467419646 405467040 ...
output:
644270050 458024629 873867630 333425143 662579180 206390717 140580782 875283987 474707878 1652365 868560326 614453966 259797959 239235096 92504673 84476394 852577013 458740995 486230271 25997410 813354862 125835334 969225614 415291755 330275079 963447034 953344685 105994246 692000742 57486262 366177...
result:
ok 50000 numbers
Test #59:
score: 0
Accepted
time: 1137ms
memory: 14944kb
input:
50000 50000 50000 44967088 -212785829 186905286 538950397 545274868 -421691600 -845555693 104642470 927403046 -805672626 352989276 -427564064 193547889 -554809065 -714255078 862137029 721771958 -960582259 -881164652 646123891 -535695312 -510654064 800006064 272105404 448274933 576256734 -775368748 -...
output:
794158355 45852409 200780375 497735628 167392938 273712642 425962026 783983075 713002875 369788525 202932638 162005872 560115519 411129768 252241884 878543837 155508483 591915335 690311019 360432007 339538796 840607568 325589718 417548078 41923625 350824018 587153794 680421682 481745446 696970706 66...
result:
ok 50000 numbers
Test #60:
score: 0
Accepted
time: 1132ms
memory: 14672kb
input:
50000 50000 50000 -782320074 -179757994 724224877 608992663 -280539006 609584121 -89613097 -953612361 -774189242 -773190328 59627652 -559262673 -28419073 441511491 -317932187 -688147807 -944448983 -85607472 -961816606 -125063517 -415865307 -531132824 829697268 -801968748 75357742 -380066899 -4634120...
output:
218018094 516251893 764539666 915656938 500395532 285576965 910671667 164766208 440013813 372299757 253797827 389867423 889982996 62594543 146724877 642031695 10177845 251607618 14326601 89403198 936752922 685584945 703208900 561510222 165665846 319391388 997857402 131440140 189052349 428072560 2142...
result:
ok 50000 numbers
Test #61:
score: 0
Accepted
time: 1131ms
memory: 14684kb
input:
50000 50000 50000 390392777 -441697428 -443488276 -713074391 -203494917 838685063 -826463004 -601801719 -475781518 -445740760 356200569 -395994011 357504658 635657268 -824467260 -238432630 486472139 -12807464 -747501289 -896250924 -903925997 -846578854 57213693 -171010156 -887493989 -728499837 -4464...
output:
744755394 368192840 408469045 740362685 98137139 172330033 690626518 954389264 830618524 772013015 344976383 332559661 588695624 261071062 753268398 426666297 619488888 914851253 339502883 613250917 227006493 291900791 791805582 615574734 673747197 804978616 380813202 799668685 505530491 897195714 2...
result:
ok 50000 numbers
Test #62:
score: 0
Accepted
time: 1137ms
memory: 14624kb
input:
50000 50000 50000 548333476 -416262128 27175354 -380813033 727733138 -689980129 -282568908 -649921237 274231589 -361844634 949230752 323917824 187361639 -498263044 -536219618 105876033 756586545 998108763 741379868 261214452 768683207 -633469006 -295597569 -994812950 -934411999 -79636839 859979867 -...
output:
896232114 339768819 1188782 248681677 202258708 607836632 791614211 624388898 684036744 275925920 794136474 338647050 227294606 510736936 878707585 131233367 958626729 168649908 196919680 449314296 549848214 600294826 340995304 861591565 857009429 211397609 644540989 499953317 861582122 846444921 61...
result:
ok 50000 numbers