QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#475394 | #9125. Majority and Permutation | ucup-team008# | AC ✓ | 713ms | 47408kb | C++17 | 28.9kb | 2024-07-13 14:27:47 | 2024-07-13 14:27:48 |
Judging History
answer
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <complex>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <vector>
using namespace std;
// BEGIN NO SAD
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
typedef vector<int> vi;
#define f first
#define s second
#define derr if(0) cerr
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#define debug(x...) cerr << "\e[91m"<<__func__<<":"<<__LINE__<<" [" << #x << "] = ["; _print(x); cerr << "\e[39m" << flush;
// END NO SAD
template<class Fun>
class y_combinator_result {
Fun fun_;
public:
template<class T>
explicit y_combinator_result(T &&fun): fun_(std::forward<T>(fun)) {}
template<class ...Args>
decltype(auto) operator()(Args &&...args) {
return fun_(std::ref(*this), std::forward<Args>(args)...);
}
};
template<class Fun>
decltype(auto) y_combinator(Fun &&fun) {
return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun));
}
template<class T>
bool updmin(T& a, T b) {
if(b < a) {
a = b;
return true;
}
return false;
}
template<class T>
bool updmax(T& a, T b) {
if(b > a) {
a = b;
return true;
}
return false;
}
typedef int64_t ll;
template<typename float_t>
struct fast_complex {
// credit to neal
float_t x, y;
fast_complex(float_t _x = 0, float_t _y = 0) : x(_x), y(_y) {}
float_t real() const {
return x;
}
void real(float_t _x) {
x = _x;
}
float_t imag() const {
return y;
}
void imag(float_t _y) {
y = _y;
}
fast_complex<float_t>& operator+=(const fast_complex<float_t> &other) {
x += other.x;
y += other.y;
return *this;
}
fast_complex<float_t>& operator-=(const fast_complex<float_t> &other) {
x -= other.x;
y -= other.y;
return *this;
}
fast_complex<float_t> operator+(const fast_complex<float_t> &other) const {
return fast_complex<float_t>(*this) += other;
}
fast_complex<float_t> operator-(const fast_complex<float_t> &other) const {
return fast_complex<float_t>(*this) -= other;
}
fast_complex<float_t> operator*(const fast_complex<float_t> &other) const {
return {x * other.x - y * other.y, x * other.y + other.x * y};
}
};
template<typename float_t>
fast_complex<float_t> fast_conj(const fast_complex<float_t> &c) {
return {c.x, -c.y};
}
template<typename float_t>
fast_complex<float_t> fast_polar(float_t magnitude, float_t angle) {
return {magnitude * cos(angle), magnitude * sin(angle)};
}
template<typename float_t>
ostream& operator<<(ostream &stream, const fast_complex<float_t> &c) {
return stream << '(' << c.x << ", " << c.y << ')';
}
namespace FFT {
typedef double float_t;
const float_t ONE = 1;
const float_t PI = acos(-ONE);
vector<fast_complex<float_t>> roots;
vector<int> bit_reverse;
bool is_power_of_two(int n) {
return (n & (n - 1)) == 0;
}
int round_up_power_two(int n) {
assert(n > 0);
while (n & (n - 1))
n = (n | (n - 1)) + 1;
return n;
}
// Given n (a power of two), finds k such that n == 1 << k.
int get_length(int n) {
assert(is_power_of_two(n));
return __builtin_ctz(n);
}
// Rearranges the indices to be sorted by lowest bit first, then second lowest, etc., rather than highest bit first.
// This makes even-odd div-conquer much easier.
template<typename fast_complex_array>
void bit_reorder(int n, fast_complex_array &&values) {
if ((int) bit_reverse.size() != n) {
bit_reverse.assign(n, 0);
int length = get_length(n);
for (int i = 0; i < n; i++)
bit_reverse[i] = (bit_reverse[i >> 1] >> 1) + ((i & 1) << (length - 1));
}
for (int i = 0; i < n; i++)
if (i < bit_reverse[i])
swap(values[i], values[bit_reverse[i]]);
}
void prepare_roots(int n) {
if ((int) roots.size() >= n)
return;
if (roots.empty())
roots = {{0, 0}, {1, 0}};
int length = get_length(roots.size());
roots.resize(n);
// The roots array is set up such that for a given power of two n >= 2, roots[n / 2] through roots[n - 1] are
// the first half of the n-th roots of unity.
while (1 << length < n) {
double min_angle = 2 * PI / (1 << (length + 1));
for (int i = 0; i < 1 << (length - 1); i++) {
int index = (1 << (length - 1)) + i;
roots[2 * index] = roots[index];
roots[2 * index + 1] = fast_polar(ONE, min_angle * (2 * i + 1));
}
length++;
}
}
template<typename fast_complex_array>
void fft_recursive(int n, fast_complex_array &&values, int depth = 0) {
if (n <= 1)
return;
if (depth == 0) {
assert(is_power_of_two(n));
prepare_roots(n);
bit_reorder(n, values);
}
n /= 2;
fft_recursive(n, values, depth + 1);
fft_recursive(n, values + n, depth + 1);
for (int i = 0; i < n; i++) {
const fast_complex<float_t> &even = values[i];
fast_complex<float_t> odd = values[n + i] * roots[n + i];
values[n + i] = even - odd;
values[i] = even + odd;
}
}
// Iterative version of fft_recursive above.
template<typename fast_complex_array>
void fft_iterative(int N, fast_complex_array &&values) {
assert(is_power_of_two(N));
prepare_roots(N);
bit_reorder(N, values);
for (int n = 1; n < N; n *= 2)
for (int start = 0; start < N; start += 2 * n)
for (int i = 0; i < n; i++) {
const fast_complex<float_t> &even = values[start + i];
fast_complex<float_t> odd = values[start + n + i] * roots[n + i];
values[start + n + i] = even - odd;
values[start + i] = even + odd;
}
}
inline fast_complex<float_t> extract(int N, const vector<fast_complex<float_t>> &values, int index, int side) {
if (side == -1) {
// Return the product of 0 and 1.
int other = (N - index) & (N - 1);
return (fast_conj(values[other] * values[other]) - values[index] * values[index]) * fast_complex<float_t>(0, 0.25);
}
int other = (N - index) & (N - 1);
int sign = side == 0 ? +1 : -1;
fast_complex<float_t> multiplier = side == 0 ? fast_complex<float_t>(0.5, 0) : fast_complex<float_t>(0, -0.5);
return multiplier * fast_complex<float_t>(values[index].real() + values[other].real() * sign,
values[index].imag() - values[other].imag() * sign);
}
void invert_fft(int N, vector<fast_complex<float_t>> &values) {
assert(N >= 2);
for (int i = 0; i < N; i++)
values[i] = fast_conj(values[i]) * (ONE / N);
for (int i = 0; i < N / 2; i++) {
fast_complex<float_t> first = values[i] + values[N / 2 + i];
fast_complex<float_t> second = (values[i] - values[N / 2 + i]) * roots[N / 2 + i];
values[i] = first + second * fast_complex<float_t>(0, 1);
}
fft_recursive(N / 2, values.begin());
for (int i = N - 1; i >= 0; i--)
values[i] = i % 2 == 0 ? values[i / 2].real() : values[i / 2].imag();
}
const int FFT_CUTOFF = 150;
const double SPLIT_CUTOFF = 2e15;
const int SPLIT_BASE = 1 << 15;
template<typename T_out, typename T_in>
vector<T_out> square(const vector<T_in> &input) {
int n = input.size();
// Brute force when n is small enough.
if (n < 1.5 * FFT_CUTOFF) {
vector<T_out> result(2 * n - 1);
for (int i = 0; i < n; i++) {
result[2 * i] += (T_out) input[i] * input[i];
for (int j = i + 1; j < n; j++)
result[i + j] += (T_out) 2 * input[i] * input[j];
}
return result;
}
int N = round_up_power_two(n);
assert(N >= 2);
prepare_roots(2 * N);
vector<fast_complex<float_t>> values(N, 0);
for (int i = 0; i < n; i += 2)
values[i / 2] = fast_complex<float_t>(input[i], i + 1 < n ? input[i + 1] : 0);
fft_iterative(N, values.begin());
for (int i = 0; i <= N / 2; i++) {
int j = (N - i) & (N - 1);
fast_complex<float_t> even = extract(N, values, i, 0);
fast_complex<float_t> odd = extract(N, values, i, 1);
fast_complex<float_t> aux = even * even + odd * odd * roots[N + i] * roots[N + i];
fast_complex<float_t> tmp = even * odd;
values[i] = aux - fast_complex<float_t>(0, 2) * tmp;
values[j] = fast_conj(aux) - fast_complex<float_t>(0, 2) * fast_conj(tmp);
}
for (int i = 0; i < N; i++)
values[i] = fast_conj(values[i]) * (ONE / N);
fft_recursive(N, values.begin());
vector<T_out> result(2 * n - 1);
for (int i = 0; i < (int) result.size(); i++) {
float_t value = i % 2 == 0 ? values[i / 2].real() : values[i / 2].imag();
result[i] = is_integral<T_out>::value ? round(value) : value;
}
return result;
}
template<typename T_out, typename T_in>
vector<T_out> multiply(const vector<T_in> &left, const vector<T_in> &right) {
if (left == right)
return square<T_out>(left);
int n = left.size();
int m = right.size();
// Brute force when either n or m is small enough.
if (min(n, m) < FFT_CUTOFF) {
vector<T_out> result(n + m - 1);
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
result[i + j] += (T_out) left[i] * right[j];
return result;
}
int N = round_up_power_two(n + m - 1);
vector<fast_complex<float_t>> values(N, 0);
for (int i = 0; i < n; i++)
values[i].real(left[i]);
for (int i = 0; i < m; i++)
values[i].imag(right[i]);
fft_iterative(N, values.begin());
for (int i = 0; i <= N / 2; i++) {
int j = (N - i) & (N - 1);
fast_complex<float_t> product_i = extract(N, values, i, -1);
values[i] = product_i;
values[j] = fast_conj(product_i);
}
invert_fft(N, values);
vector<T_out> result(n + m - 1);
for (int i = 0; i < (int) result.size(); i++)
result[i] = is_integral<T_out>::value ? round(values[i].real()) : values[i].real();
return result;
}
template<typename T>
vector<T> mod_multiply(const vector<T> &left, const vector<T> &right, T mod, bool split = false) {
int n = left.size();
int m = right.size();
for (int i = 0; i < n; i++)
assert(0 <= left[i] && left[i] < mod);
for (int i = 0; i < m; i++)
assert(0 <= right[i] && right[i] < mod);
// Brute force when either n or m is small enough. Brute force up to higher values when split = true.
if (min(n, m) < (split ? 2 : 1) * FFT_CUTOFF) {
const uint64_t ULL_BOUND = numeric_limits<uint64_t>::max() - (uint64_t) mod * mod;
vector<uint64_t> result(n + m - 1);
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) {
result[i + j] += (uint64_t) left[i] * right[j];
if (result[i + j] > ULL_BOUND)
result[i + j] %= mod;
}
for (int i = 0; i < (int) result.size(); i++)
if (result[i] >= (uint64_t) mod)
result[i] %= mod;
return vector<T>(result.begin(), result.end());
}
if (!split) {
const vector<uint64_t> &product = multiply<uint64_t>(left, right);
vector<T> result(n + m - 1);
for (int i = 0; i < (int) result.size(); i++)
result[i] = product[i] % mod;
return result;
}
int N = round_up_power_two(n + m - 1);
vector<fast_complex<float_t>> left_fft(N, 0), right_fft(N, 0);
for (int i = 0; i < n; i++) {
left_fft[i].real(left[i] % SPLIT_BASE);
left_fft[i].imag(left[i] / SPLIT_BASE);
}
fft_iterative(N, left_fft.begin());
if (left == right) {
copy(left_fft.begin(), left_fft.end(), right_fft.begin());
} else {
for (int i = 0; i < m; i++) {
right_fft[i].real(right[i] % SPLIT_BASE);
right_fft[i].imag(right[i] / SPLIT_BASE);
}
fft_iterative(N, right_fft.begin());
}
vector<fast_complex<float_t>> product(N);
vector<T> result(n + m - 1);
for (int exponent = 0; exponent <= 2; exponent++) {
uint64_t multiplier = 1;
for (int k = 0; k < exponent; k++)
multiplier = multiplier * SPLIT_BASE % mod;
fill(product.begin(), product.end(), 0);
for (int x = 0; x < 2; x++)
for (int y = 0; y < 2; y++)
if (x + y == exponent)
for (int i = 0; i < N; i++)
product[i] += extract(N, left_fft, i, x) * extract(N, right_fft, i, y);
invert_fft(N, product);
for (int i = 0; i < (int) result.size(); i++) {
uint64_t value = round(product[i].real());
result[i] = (result[i] + value % mod * multiplier) % mod;
}
}
return result;
}
}
struct barrett_reduction {
unsigned mod;
uint64_t div;
barrett_reduction(unsigned m) : mod(m), div(-1LLU / m) {}
unsigned operator()(uint64_t a) const {
#ifdef __SIZEOF_INT128__
uint64_t q = uint64_t(__uint128_t(div) * a >> 64);
uint64_t r = a - q * mod;
return unsigned(r < mod ? r : r - mod);
#endif
return unsigned(a % mod);
}
};
template<const int &MOD, const barrett_reduction &barrett>
struct _b_int {
int val;
_b_int(int64_t v = 0) {
if (v < 0) v = v % MOD + MOD;
if (v >= MOD) v %= MOD;
val = int(v);
}
_b_int(uint64_t v) {
if (v >= uint64_t(MOD)) v %= MOD;
val = int(v);
}
_b_int(int v) : _b_int(int64_t(v)) {}
_b_int(unsigned v) : _b_int(uint64_t(v)) {}
static int inv_mod(int a, int m = MOD) {
// https://en.wikipedia.org/wiki/Extended_Euclidean_algorithm#Example
int g = m, r = a, x = 0, y = 1;
while (r != 0) {
int q = g / r;
g %= r; swap(g, r);
x -= q * y; swap(x, y);
}
return x < 0 ? x + m : x;
}
explicit operator int() const { return val; }
explicit operator unsigned() const { return val; }
explicit operator int64_t() const { return val; }
explicit operator uint64_t() const { return val; }
explicit operator double() const { return val; }
explicit operator long double() const { return val; }
_b_int& operator+=(const _b_int &other) {
val -= MOD - other.val;
if (val < 0) val += MOD;
return *this;
}
_b_int& operator-=(const _b_int &other) {
val -= other.val;
if (val < 0) val += MOD;
return *this;
}
static unsigned fast_mod(uint64_t x) {
#if !defined(_WIN32) || defined(_WIN64)
return barrett(x);
#endif
// Optimized mod for Codeforces 32-bit machines.
// x must be less than 2^32 * MOD for this to work, so that x / MOD fits in an unsigned 32-bit int.
unsigned x_high = unsigned(x >> 32), x_low = unsigned(x);
unsigned quot, rem;
asm("divl %4\n"
: "=a" (quot), "=d" (rem)
: "d" (x_high), "a" (x_low), "r" (MOD));
return rem;
}
_b_int& operator*=(const _b_int &other) {
val = fast_mod(uint64_t(val) * other.val);
return *this;
}
_b_int& operator/=(const _b_int &other) {
return *this *= other.inv();
}
friend _b_int operator+(const _b_int &a, const _b_int &b) { return _b_int(a) += b; }
friend _b_int operator-(const _b_int &a, const _b_int &b) { return _b_int(a) -= b; }
friend _b_int operator*(const _b_int &a, const _b_int &b) { return _b_int(a) *= b; }
friend _b_int operator/(const _b_int &a, const _b_int &b) { return _b_int(a) /= b; }
_b_int& operator++() {
val = val == MOD - 1 ? 0 : val + 1;
return *this;
}
_b_int& operator--() {
val = val == 0 ? MOD - 1 : val - 1;
return *this;
}
_b_int operator++(int) { _b_int before = *this; ++*this; return before; }
_b_int operator--(int) { _b_int before = *this; --*this; return before; }
_b_int operator-() const {
return val == 0 ? 0 : MOD - val;
}
friend bool operator==(const _b_int &a, const _b_int &b) { return a.val == b.val; }
friend bool operator!=(const _b_int &a, const _b_int &b) { return a.val != b.val; }
friend bool operator<(const _b_int &a, const _b_int &b) { return a.val < b.val; }
friend bool operator>(const _b_int &a, const _b_int &b) { return a.val > b.val; }
friend bool operator<=(const _b_int &a, const _b_int &b) { return a.val <= b.val; }
friend bool operator>=(const _b_int &a, const _b_int &b) { return a.val >= b.val; }
_b_int inv() const {
return inv_mod(val);
}
_b_int pow(int64_t p) const {
if (p < 0)
return inv().pow(-p);
_b_int a = *this, result = 1;
while (p > 0) {
if (p & 1)
result *= a;
p >>= 1;
if (p > 0)
a *= a;
}
return result;
}
friend ostream& operator<<(ostream &os, const _b_int &m) {
return os << m.val;
}
friend istream& operator>>(istream &is, _b_int &m) {
int64_t x;
is >> x;
m = x;
return is;
}
};
int MOD = 998244353;
barrett_reduction barrett(MOD);
using mnum = _b_int<MOD, barrett>;
using uint = unsigned int;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
template <uint MD> struct ModInt {
using M = ModInt;
const static M G;
uint v;
ModInt(ll _v = 0) { set_v(_v % MD + MD); }
M& set_v(uint _v) {
v = (_v < MD) ? _v : _v - MD;
return *this;
}
explicit operator bool() const { return v != 0; }
M operator-() const { return M() - *this; }
M operator+(const M& r) const { return M().set_v(v + r.v); }
M operator-(const M& r) const { return M().set_v(v + MD - r.v); }
M operator*(const M& r) const { return M().set_v(ull(v) * r.v % MD); }
M operator/(const M& r) const { return *this * r.inv(); }
M& operator+=(const M& r) { return *this = *this + r; }
M& operator-=(const M& r) { return *this = *this - r; }
M& operator*=(const M& r) { return *this = *this * r; }
M& operator/=(const M& r) { return *this = *this / r; }
bool operator==(const M& r) const { return v == r.v; }
M pow(ll n) const {
M x = *this, r = 1;
while (n) {
if (n & 1) r *= x;
x *= x;
n >>= 1;
}
return r;
}
M inv() const { return pow(MD - 2); }
friend ostream& operator<<(ostream& os, const M& r) { return os << r.v; }
};
using Mint = ModInt<998244353>;
template <> const Mint Mint::G = Mint(3);
template <class Mint> void nft(bool type, V<Mint>& a) {
int n = int(a.size()), s = 0;
while ((1 << s) < n) s++;
assert(1 << s == n);
static V<Mint> ep, iep;
while (int(ep.size()) <= s) {
ep.push_back(Mint::G.pow(Mint(-1).v / (1 << ep.size())));
iep.push_back(ep.back().inv());
}
V<Mint> b(n);
for (int i = 1; i <= s; i++) {
int w = 1 << (s - i);
Mint base = type ? iep[i] : ep[i], now = 1;
for (int y = 0; y < n / 2; y += w) {
for (int x = 0; x < w; x++) {
auto l = a[y << 1 | x];
auto r = now * a[y << 1 | x | w];
b[y | x] = l + r;
b[y | x | n >> 1] = l - r;
}
now *= base;
}
swap(a, b);
}
}
template <class Mint> V<Mint> multiply(const V<Mint>& a, const V<Mint>& b) {
int n = int(a.size()), m = int(b.size());
if (!n || !m) return {};
if (min(n, m) <= 8) {
V<Mint> ans(n + m - 1);
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) ans[i + j] += a[i] * b[j];
return ans;
}
int lg = 0;
while ((1 << lg) < n + m - 1) lg++;
int z = 1 << lg;
auto a2 = a, b2 = b;
a2.resize(z);
b2.resize(z);
nft(false, a2);
nft(false, b2);
for (int i = 0; i < z; i++) a2[i] *= b2[i];
nft(true, a2);
a2.resize(n + m - 1);
Mint iz = Mint(z).inv();
for (int i = 0; i < n + m - 1; i++) a2[i] *= iz;
return a2;
}
template <class D> struct Poly {
V<D> v;
Poly(const V<D>& _v = {}) : v(_v) { shrink(); }
void shrink() {
while (v.size() && !v.back()) v.pop_back();
}
int size() const { return int(v.size()); }
D freq(int p) const { return (p < size()) ? v[p] : D(0); }
Poly operator+(const Poly& r) const {
auto n = max(size(), r.size());
V<D> res(n);
for (int i = 0; i < n; i++) res[i] = freq(i) + r.freq(i);
return res;
}
Poly operator-(const Poly& r) const {
int n = max(size(), r.size());
V<D> res(n);
for (int i = 0; i < n; i++) res[i] = freq(i) - r.freq(i);
return res;
}
Poly operator*(const Poly& r) const { return {multiply(v, r.v)}; }
Poly operator*(const D& r) const {
int n = size();
V<D> res(n);
for (int i = 0; i < n; i++) res[i] = v[i] * r;
return res;
}
Poly operator/(const D& r) const { return *this * r.inv(); }
Poly operator/(const Poly& r) const {
if (size() < r.size()) return {{}};
int n = size() - r.size() + 1;
return (rev().pre(n) * r.rev().inv(n)).pre(n).rev(n);
}
Poly operator%(const Poly& r) const { return *this - *this / r * r; }
Poly operator<<(int s) const {
V<D> res(size() + s);
for (int i = 0; i < size(); i++) res[i + s] = v[i];
return res;
}
Poly operator>>(int s) const {
if (size() <= s) return Poly();
V<D> res(size() - s);
for (int i = 0; i < size() - s; i++) res[i] = v[i + s];
return res;
}
Poly& operator+=(const Poly& r) { return *this = *this + r; }
Poly& operator-=(const Poly& r) { return *this = *this - r; }
Poly& operator*=(const Poly& r) { return *this = *this * r; }
Poly& operator*=(const D& r) { return *this = *this * r; }
Poly& operator/=(const Poly& r) { return *this = *this / r; }
Poly& operator/=(const D& r) { return *this = *this / r; }
Poly& operator%=(const Poly& r) { return *this = *this % r; }
Poly& operator<<=(const size_t& n) { return *this = *this << n; }
Poly& operator>>=(const size_t& n) { return *this = *this >> n; }
Poly pre(int le) const {
return {{v.begin(), v.begin() + min(size(), le)}};
}
Poly rev(int n = -1) const {
V<D> res = v;
if (n != -1) res.resize(n);
reverse(res.begin(), res.end());
return res;
}
Poly diff() const {
V<D> res(max(0, size() - 1));
for (int i = 1; i < size(); i++) res[i - 1] = freq(i) * i;
return res;
}
Poly inte() const {
V<D> res(size() + 1);
for (int i = 0; i < size(); i++) res[i + 1] = freq(i) / (i + 1);
return res;
}
// f * f.inv() = 1 + g(x)x^m
Poly inv(int m) const {
Poly res = Poly({D(1) / freq(0)});
for (int i = 1; i < m; i *= 2) {
res = (res * D(2) - res * res * pre(2 * i)).pre(2 * i);
}
return res.pre(m);
}
Poly exp(int n) const {
assert(freq(0) == 0);
Poly f({1}), g({1});
for (int i = 1; i < n; i *= 2) {
g = (g * 2 - f * g * g).pre(i);
Poly q = diff().pre(i - 1);
Poly w = (q + g * (f.diff() - f * q)).pre(2 * i - 1);
f = (f + f * (*this - w.inte()).pre(2 * i)).pre(2 * i);
}
return f.pre(n);
}
Poly log(int n) const {
assert(freq(0) == 1);
auto f = pre(n);
return (f.diff() * f.inv(n - 1)).pre(n - 1).inte();
}
Poly sqrt(int n) const {
assert(freq(0) == 1);
Poly f = pre(n + 1);
Poly g({1});
for (int i = 1; i < n; i *= 2) {
g = (g + f.pre(2 * i) * g.inv(2 * i)) / 2;
}
return g.pre(n + 1);
}
Poly pow_mod(ll n, const Poly& mod) {
Poly x = *this, r = {{1}};
while (n) {
if (n & 1) r = r * x % mod;
x = x * x % mod;
n >>= 1;
}
return r;
}
friend ostream& operator<<(ostream& os, const Poly& p) {
if (p.size() == 0) return os << "0";
for (auto i = 0; i < p.size(); i++) {
if (p.v[i]) {
os << p.v[i] << "x^" << i;
if (i != p.size() - 1) os << "+";
}
}
return os;
}
};
void solve() {
int n, m;
cin >> n >> m;
V<Mint> a(2*n+1);
a[0] = 1;
for(int i = 1; i <= 2*n; i++) {
a[i] = (a[i-1] * i);
}
auto pol = Poly<Mint>(a);
pol = pol.inv(2*n+1);
vector<mnum> scale(2*n+1);
for(int i = 1; i <= 2*n; i++) {
scale[i] = (int)pol.freq(i).v;
scale[i] *= -1;
}
vector<bool> used(2*n+1);
while(m--) {
int x;
cin >> x;
used[x] = true;
}
vector<mnum> dp(2*n+1);
dp[0] = 1;
auto convolve = [&](int lhs, int mid, int rhs) -> void {
vector<int> lv(mid-lhs+1), rv(rhs-lhs+1);
for(int i = lhs; i <= mid; i++) lv[i-lhs] = (int)dp[i];
for(int i = lhs; i <= rhs; i++) rv[i-lhs] = (int)scale[i-lhs];
vector<int> p = FFT::mod_multiply(lv, rv, MOD, true);
for(int i = 0; i < sz(p); i++) {
int j = lhs + i;
if(mid+1 <= j && j <= rhs) dp[j] += p[i];
}
};
auto dfs = y_combinator([&](auto self, int lhs, int rhs) -> void {
if(lhs == rhs) {
if(used[lhs] && used[2*n-lhs]) dp[lhs] = 0;
return;
}
int mid = (lhs+rhs)/2;
self(lhs, mid);
convolve(lhs, mid, rhs);
self(mid+1, rhs);
});
dfs(0, 2*n);
cout << dp[2*n] << "\n";
}
// what would chika do
// are there edge cases (N=1?)
// are array sizes proper (scaled by proper constant, for example 2* for koosaga tree)
// integer overflow?
// DS reset properly between test cases
// are you doing geometry in floating points
// are you not using modint when you should
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3572kb
input:
2 2 1 3
output:
14
result:
ok "14"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3760kb
input:
5 4 1 3 7 9
output:
2909184
result:
ok "2909184"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3836kb
input:
5 1 5
output:
3614400
result:
ok "3614400"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3572kb
input:
3 1 3
output:
684
result:
ok "684"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
5 2 5 9
output:
3614400
result:
ok "3614400"
Test #6:
score: 0
Accepted
time: 696ms
memory: 47096kb
input:
96685 10195 21 27 35 53 63 81 89 117 119 125 131 135 141 157 181 201 225 229 269 275 287 293 321 325 361 363 379 403 409 429 435 441 491 501 505 543 569 609 611 669 711 717 725 727 731 759 769 785 793 797 809 821 863 899 903 911 929 937 961 997 1051 1073 1077 1123 1157 1179 1235 1251 1275 1317 1319 ...
output:
95571712
result:
ok "95571712"
Test #7:
score: 0
Accepted
time: 337ms
memory: 26012kb
input:
64166 56097 3 9 11 13 15 17 19 21 25 27 29 31 33 35 37 39 41 43 45 47 49 51 55 57 59 61 63 65 67 69 71 73 75 77 79 85 87 89 91 93 95 97 101 105 107 111 113 115 117 119 121 123 125 127 131 133 137 141 143 145 149 153 155 159 161 163 167 169 171 173 175 177 181 183 185 187 189 191 195 197 199 201 205 ...
output:
228890492
result:
ok "228890492"
Test #8:
score: 0
Accepted
time: 695ms
memory: 47224kb
input:
98805 64583 1 3 5 7 9 13 15 17 19 21 27 33 35 39 41 43 45 47 49 53 55 57 59 61 65 67 71 73 75 77 79 81 83 85 89 91 95 97 103 107 109 121 123 127 129 135 137 139 141 143 145 149 151 153 155 157 159 161 163 167 171 173 175 177 179 181 183 185 187 189 191 197 199 203 205 207 213 215 219 221 223 225 227...
output:
184329625
result:
ok "184329625"
Test #9:
score: 0
Accepted
time: 421ms
memory: 27820kb
input:
72245 14521 5 35 37 43 75 77 97 129 155 171 173 175 179 183 209 213 219 225 227 229 241 255 257 263 271 295 297 305 307 315 321 323 335 351 361 363 369 379 389 391 395 433 435 439 443 449 451 455 463 483 497 523 531 537 557 559 567 573 589 595 609 613 633 641 643 651 655 657 669 695 701 721 793 803 ...
output:
61878119
result:
ok "61878119"
Test #10:
score: 0
Accepted
time: 328ms
memory: 25952kb
input:
63266 62348 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 87 89 91 93 95 97 99 101 103 105 107 109 111 113 115 117 119 121 123 127 129 131 133 135 137 139 141 143 145 149 151 153 155 157 159 161 163 165 167 169 171 173 175 17...
output:
265087059
result:
ok "265087059"
Test #11:
score: 0
Accepted
time: 689ms
memory: 47148kb
input:
96192 60042 1 3 5 7 9 13 17 21 31 33 39 41 45 47 51 53 55 57 61 63 65 67 69 75 79 81 83 85 87 89 91 95 99 101 103 105 109 111 115 131 133 135 137 141 151 153 155 157 161 165 169 173 175 177 181 183 189 193 199 205 207 209 215 217 219 221 225 227 229 231 239 243 245 247 249 251 257 263 265 273 275 27...
output:
750054525
result:
ok "750054525"
Test #12:
score: 0
Accepted
time: 680ms
memory: 46916kb
input:
96428 60349 1 3 7 9 13 19 21 23 25 27 29 37 39 41 43 45 49 51 53 55 61 63 67 69 73 75 77 81 85 87 89 91 93 95 97 99 101 111 113 117 123 125 127 129 131 135 137 139 141 149 151 155 157 161 169 171 173 175 177 179 185 189 193 197 209 211 213 219 223 225 229 231 233 235 237 239 243 247 251 253 259 263 ...
output:
214089880
result:
ok "214089880"
Test #13:
score: 0
Accepted
time: 671ms
memory: 46996kb
input:
92301 57523 3 7 9 13 15 17 19 21 27 29 31 33 45 47 53 61 63 67 71 73 75 77 79 81 83 85 87 91 93 99 101 107 109 111 113 115 117 121 125 127 129 133 135 137 139 145 147 149 153 155 159 161 165 167 171 173 175 177 183 185 189 191 193 195 197 199 205 207 211 213 215 219 221 223 225 231 235 237 239 241 2...
output:
698581206
result:
ok "698581206"
Test #14:
score: 0
Accepted
time: 671ms
memory: 46604kb
input:
92162 57420 5 7 9 15 23 25 27 29 31 35 37 39 43 45 49 51 53 57 63 65 67 69 73 77 81 83 85 87 89 99 101 103 107 109 115 117 121 123 125 127 129 131 133 135 137 139 141 143 145 147 149 153 157 159 161 167 175 177 185 189 191 197 199 201 203 219 221 223 229 231 235 239 241 243 247 251 257 259 267 275 2...
output:
779052124
result:
ok "779052124"
Test #15:
score: 0
Accepted
time: 684ms
memory: 47176kb
input:
95309 59643 1 7 9 11 15 17 23 25 29 33 35 37 45 47 49 51 53 55 59 61 63 65 67 69 71 79 81 83 85 87 89 93 95 97 103 105 107 111 113 115 117 119 121 123 127 129 131 133 135 139 141 143 147 149 159 161 163 167 169 173 179 181 183 189 193 197 199 203 207 209 211 213 215 217 223 227 229 231 237 239 241 2...
output:
895352747
result:
ok "895352747"
Test #16:
score: 0
Accepted
time: 688ms
memory: 47288kb
input:
97003 25153 11 19 27 31 53 71 75 81 85 95 97 113 129 131 139 145 159 163 171 175 193 209 211 213 217 227 237 239 241 249 253 271 275 279 295 301 309 329 331 343 351 359 361 375 379 383 389 395 401 403 413 415 425 433 441 447 451 455 473 475 495 505 521 533 535 537 539 543 559 603 605 609 611 615 619...
output:
945539005
result:
ok "945539005"
Test #17:
score: 0
Accepted
time: 682ms
memory: 46944kb
input:
99075 39136 3 5 7 15 17 19 21 29 31 33 41 51 53 55 57 59 61 65 73 81 89 91 97 101 115 119 121 123 127 133 135 149 155 157 171 175 183 185 187 189 191 199 215 225 227 229 231 237 239 241 247 257 267 269 271 273 281 283 295 299 315 323 333 337 339 343 349 351 367 377 395 397 399 407 411 413 423 427 43...
output:
432766313
result:
ok "432766313"
Test #18:
score: 0
Accepted
time: 689ms
memory: 47048kb
input:
92159 26615 5 27 33 37 49 53 65 67 69 71 73 77 93 95 107 115 143 147 155 161 163 173 175 179 183 185 203 221 225 235 241 245 253 257 271 273 291 301 305 307 317 327 337 339 347 351 353 363 375 377 379 389 397 401 405 409 419 421 437 441 443 447 453 465 477 489 491 497 505 531 547 557 559 563 571 583...
output:
232913447
result:
ok "232913447"
Test #19:
score: 0
Accepted
time: 667ms
memory: 47108kb
input:
93053 56499 1 5 9 11 13 17 19 23 25 29 31 37 39 45 47 49 51 55 59 65 67 69 71 75 79 83 91 99 103 105 107 109 111 113 115 117 121 123 125 127 129 131 133 135 137 139 141 145 151 157 159 161 165 167 169 171 175 177 179 181 183 185 187 191 193 195 197 199 201 205 207 209 211 215 217 221 223 227 233 235...
output:
694330858
result:
ok "694330858"
Test #20:
score: 0
Accepted
time: 689ms
memory: 47116kb
input:
93589 51398 3 7 21 23 25 29 31 33 35 37 39 41 43 47 49 53 55 61 63 77 83 85 89 95 99 105 109 113 117 125 127 129 135 139 141 147 151 155 157 159 163 165 167 171 173 179 183 185 187 197 201 207 211 217 219 221 233 239 241 251 257 261 265 267 269 273 275 283 287 289 291 295 297 305 307 313 315 317 321...
output:
777536233
result:
ok "777536233"
Test #21:
score: 0
Accepted
time: 685ms
memory: 47288kb
input:
100000 62633 3 5 9 13 15 17 19 21 23 27 33 37 39 41 45 49 51 53 55 61 63 65 69 71 73 77 81 85 87 89 91 95 97 99 103 105 107 109 111 115 117 119 123 125 127 129 133 137 139 141 143 145 147 149 153 159 161 163 165 167 173 177 179 181 183 187 193 195 197 199 209 211 213 215 217 221 223 225 227 233 235 ...
output:
737504170
result:
ok "737504170"
Test #22:
score: 0
Accepted
time: 679ms
memory: 47216kb
input:
100000 62720 3 5 7 9 13 15 21 23 25 27 33 39 45 47 49 51 55 59 61 69 73 77 79 83 87 89 91 95 97 101 105 107 109 115 125 129 137 139 141 143 145 149 151 153 157 161 169 171 173 175 177 181 183 189 191 193 195 197 199 209 213 217 219 221 225 227 229 231 233 235 237 241 245 247 249 251 253 255 259 261 ...
output:
617748342
result:
ok "617748342"
Test #23:
score: 0
Accepted
time: 696ms
memory: 47272kb
input:
100000 61952 1 5 11 13 15 19 21 23 25 29 33 35 39 43 45 47 49 57 59 61 63 67 71 73 75 77 79 81 83 85 87 91 93 99 101 103 107 109 115 117 121 123 125 129 133 137 143 147 149 153 155 157 161 169 173 175 179 181 183 185 187 189 191 193 199 201 211 217 219 221 225 229 231 235 239 243 245 247 251 253 255...
output:
610444772
result:
ok "610444772"
Test #24:
score: 0
Accepted
time: 694ms
memory: 47312kb
input:
100000 62478 7 9 11 15 19 21 23 25 29 31 33 35 37 39 43 45 47 51 53 55 57 59 61 65 67 75 79 83 93 95 97 99 101 103 109 111 113 115 119 121 123 137 143 145 147 149 151 157 167 169 171 175 177 179 181 185 187 189 191 193 195 197 199 207 209 211 215 217 221 223 227 231 233 235 239 241 243 245 247 249 2...
output:
35574634
result:
ok "35574634"
Test #25:
score: 0
Accepted
time: 682ms
memory: 47272kb
input:
100000 62512 1 3 5 7 9 13 17 23 25 27 31 33 35 37 39 41 45 47 53 55 57 59 61 63 65 69 71 73 75 77 81 83 89 91 93 97 99 101 103 105 107 109 111 117 121 123 125 127 129 133 135 137 139 141 153 155 157 161 163 165 167 169 171 175 181 183 187 189 191 193 195 199 203 207 209 213 219 223 225 227 229 231 2...
output:
576341038
result:
ok "576341038"
Test #26:
score: 0
Accepted
time: 689ms
memory: 47296kb
input:
100000 25239 3 7 9 11 17 19 23 33 43 47 51 57 65 69 77 79 93 113 121 123 145 147 151 153 161 165 169 173 175 179 181 185 191 197 199 201 209 213 215 217 219 227 229 233 241 263 295 303 305 315 321 329 343 349 359 363 365 367 379 381 383 387 389 395 397 409 441 447 457 461 463 465 471 477 479 547 551...
output:
610186317
result:
ok "610186317"
Test #27:
score: 0
Accepted
time: 692ms
memory: 47228kb
input:
100000 24954 3 5 7 13 17 25 37 43 49 53 61 83 93 101 111 115 117 123 131 135 139 141 157 181 185 195 197 201 221 223 229 241 245 251 257 285 293 301 323 337 347 349 357 363 367 373 377 431 435 437 441 449 453 461 469 479 489 493 495 499 501 513 517 523 527 539 541 557 559 563 583 589 593 611 631 635...
output:
584892215
result:
ok "584892215"
Test #28:
score: 0
Accepted
time: 697ms
memory: 47404kb
input:
100000 25057 7 13 21 41 43 47 65 83 89 111 113 119 131 133 141 143 145 157 169 181 185 201 207 211 215 221 253 257 269 277 287 291 295 303 315 319 333 335 369 371 377 407 415 417 445 447 457 475 485 503 507 509 511 513 517 535 541 543 545 551 555 557 567 573 585 587 591 593 595 605 611 623 629 631 6...
output:
420635212
result:
ok "420635212"
Test #29:
score: 0
Accepted
time: 692ms
memory: 47360kb
input:
100000 53389 1 5 9 13 17 19 27 29 31 33 35 39 47 63 71 77 79 83 87 89 91 93 97 101 103 105 107 109 111 115 117 119 125 129 137 139 145 149 155 157 161 163 165 177 179 181 185 195 197 199 207 209 217 219 221 223 225 227 229 233 235 239 245 247 251 253 257 259 267 269 273 275 277 281 285 287 289 291 2...
output:
272341848
result:
ok "272341848"
Test #30:
score: 0
Accepted
time: 692ms
memory: 47172kb
input:
100000 63131 1 3 7 9 11 13 15 17 19 21 23 27 29 31 37 39 41 45 47 49 61 63 65 69 71 73 77 85 87 91 95 99 101 103 105 107 111 113 117 119 121 125 127 129 133 137 141 143 145 147 149 153 155 157 161 163 171 173 177 179 181 183 185 187 191 193 195 197 199 201 203 207 209 213 215 225 227 233 235 239 241...
output:
486074251
result:
ok "486074251"
Test #31:
score: 0
Accepted
time: 694ms
memory: 47408kb
input:
100000 65584 1 3 7 9 11 13 15 17 21 23 29 31 33 37 41 45 47 51 53 57 63 65 69 71 75 77 79 85 95 97 101 107 109 111 113 117 119 121 125 129 131 133 135 139 145 151 155 157 159 167 169 173 177 179 181 183 189 195 199 203 205 215 217 219 221 225 231 233 235 237 241 245 251 255 263 265 267 271 273 275 2...
output:
300548747
result:
ok "300548747"
Test #32:
score: 0
Accepted
time: 689ms
memory: 47212kb
input:
100000 85028 1 3 5 7 9 11 13 15 17 21 23 29 31 33 35 37 39 41 45 47 49 51 53 55 59 61 63 65 67 69 71 73 75 77 79 81 85 87 89 91 93 95 97 99 101 103 105 107 109 111 115 117 119 121 129 131 133 135 137 139 141 143 145 149 151 153 159 161 163 165 167 169 171 173 175 177 179 181 183 185 187 189 191 193 ...
output:
771549211
result:
ok "771549211"
Test #33:
score: 0
Accepted
time: 692ms
memory: 47404kb
input:
100000 85689 1 3 5 7 9 11 13 19 23 25 29 33 37 39 41 43 45 47 49 53 55 57 59 61 63 65 67 69 71 73 75 77 79 83 85 87 89 91 93 97 99 101 103 105 107 109 111 113 117 121 123 125 127 129 133 135 137 139 141 143 145 147 149 151 153 155 157 159 161 163 165 167 169 171 175 177 183 187 189 191 193 195 197 1...
output:
559777459
result:
ok "559777459"
Test #34:
score: 0
Accepted
time: 671ms
memory: 47372kb
input:
100000 92620 1 3 5 7 9 11 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 93 95 97 99 101 103 105 107 109 111 113 115 117 119 121 123 125 127 129 131 133 135 137 139 141 143 147 149 153 155 157 159 165 167 169 171 173 175 177 179 181 183...
output:
636710940
result:
ok "636710940"
Test #35:
score: 0
Accepted
time: 696ms
memory: 47404kb
input:
100000 98228 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 101 103 105 107 109 111 113 115 117 119 121 123 125 127 129 131 133 135 137 139 141 143 145 147 149 151 153 155 157 159 161 163 165 167 169 171 1...
output:
997403689
result:
ok "997403689"
Test #36:
score: 0
Accepted
time: 688ms
memory: 47376kb
input:
100000 88348 1 3 5 7 9 13 15 17 19 21 25 27 29 33 37 39 41 43 47 49 51 55 57 59 61 65 67 69 71 73 75 77 79 81 83 85 87 89 93 95 97 99 101 103 105 109 111 115 117 121 123 125 127 129 131 133 135 137 139 143 145 147 151 153 155 157 159 161 163 165 167 169 171 173 175 177 179 181 183 185 187 189 191 19...
output:
238193664
result:
ok "238193664"
Test #37:
score: 0
Accepted
time: 712ms
memory: 47292kb
input:
100000 94819 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 91 93 95 97 99 101 103 105 107 109 113 115 117 119 123 125 127 129 131 133 135 137 139 141 143 145 147 149 151 153 155 157 159 161 163 165 167 169 171 173 175 1...
output:
108236721
result:
ok "108236721"
Test #38:
score: 0
Accepted
time: 690ms
memory: 47260kb
input:
100000 85432 1 3 9 11 13 15 17 19 21 23 25 27 29 31 35 37 41 43 45 47 49 53 55 57 61 63 65 67 69 75 77 79 81 83 87 89 91 93 95 97 99 101 103 105 107 109 111 115 117 121 123 125 127 131 133 135 137 139 143 145 149 151 153 155 157 159 161 163 165 167 169 173 175 177 183 187 189 191 193 195 197 199 201...
output:
784268076
result:
ok "784268076"
Test #39:
score: 0
Accepted
time: 695ms
memory: 47376kb
input:
100000 87305 1 3 5 7 9 11 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 55 57 61 63 65 67 71 73 75 77 79 81 83 85 87 89 91 93 95 99 101 103 105 107 111 113 115 117 119 121 123 125 127 129 131 133 135 137 143 145 147 149 151 153 155 157 159 165 167 171 173 175 177 179 183 185 187 189 191 1...
output:
149630632
result:
ok "149630632"
Test #40:
score: 0
Accepted
time: 674ms
memory: 47176kb
input:
99999 85201 1 3 5 7 9 11 13 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 103 105 107 111 113 115 117 119 121 123 125 127 129 131 133 135 137 139 141 143 145 147 149 151 153 157 161 163 165 167 169 171 173 175 177 179 181 1...
output:
440345213
result:
ok "440345213"
Test #41:
score: 0
Accepted
time: 698ms
memory: 47380kb
input:
99999 95806 1 3 5 7 9 11 15 19 21 23 25 27 29 31 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 87 91 93 95 97 99 101 103 107 109 111 113 115 117 119 121 123 125 127 129 131 133 135 137 139 141 143 145 147 149 151 153 155 157 159 161 163 165 167 169 173 175 177 179 181 183 1...
output:
501450066
result:
ok "501450066"
Test #42:
score: 0
Accepted
time: 702ms
memory: 47204kb
input:
99999 86821 1 3 5 7 9 11 15 17 19 21 25 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 77 79 81 83 85 87 89 95 99 101 105 107 109 113 115 117 119 121 123 125 127 131 133 135 137 139 141 143 145 147 149 151 153 155 159 161 163 165 169 171 173 175 177 179 181 183 185 189 191 193 ...
output:
751814239
result:
ok "751814239"
Test #43:
score: 0
Accepted
time: 686ms
memory: 47340kb
input:
99999 95752 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 101 103 105 107 109 111 113 115 117 119 121 123 125 127 129 131 133 135 137 139 141 143 145 147 149 151 153 155 157 159 161 163 165 167 169 171...
output:
581742233
result:
ok "581742233"
Test #44:
score: 0
Accepted
time: 682ms
memory: 47388kb
input:
99999 95760 1 3 5 7 9 11 13 17 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 79 81 83 85 87 89 91 93 95 97 99 101 103 105 107 109 111 113 115 117 119 121 123 125 127 129 131 133 135 137 139 141 143 145 147 149 153 155 157 159 161 163 165 167 169 171 173 175 177 ...
output:
138387454
result:
ok "138387454"
Test #45:
score: 0
Accepted
time: 694ms
memory: 47372kb
input:
99999 91930 1 3 5 7 9 11 13 15 17 19 23 25 27 31 33 35 37 39 41 43 45 47 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 101 103 105 107 109 111 113 115 117 119 121 123 125 127 129 131 133 135 137 139 141 143 145 147 149 151 155 157 159 161 163 165 167 169 171 173 175 177 179...
output:
741500441
result:
ok "741500441"
Test #46:
score: 0
Accepted
time: 677ms
memory: 47392kb
input:
99999 94888 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 101 103 105 107 109 111 113 115 117 119 121 123 125 127 129 131 133 135 137 139 141 145 147 149 151 153 155 157 159 161 163 165 167 169 171 173 17...
output:
974503537
result:
ok "974503537"
Test #47:
score: 0
Accepted
time: 691ms
memory: 47200kb
input:
99999 95733 1 3 5 7 9 11 13 15 17 19 23 25 27 29 33 35 37 39 41 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 101 103 105 107 109 111 113 115 117 119 121 123 125 127 129 131 133 135 137 141 143 145 147 149 151 153 155 157 159 161 163 165 167 169 171 173 175 177 ...
output:
448105112
result:
ok "448105112"
Test #48:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
1 1 1
output:
1
result:
ok "1"
Test #49:
score: 0
Accepted
time: 689ms
memory: 47392kb
input:
100000 100000 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 101 103 105 107 109 111 113 115 117 119 121 123 125 127 129 131 133 135 137 139 141 143 145 147 149 151 153 155 157 159 161 163 165 167 169 1...
output:
749028041
result:
ok "749028041"
Test #50:
score: 0
Accepted
time: 305ms
memory: 25396kb
input:
50000 50000 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 101 103 105 107 109 111 113 115 117 119 121 123 125 127 129 131 133 135 137 139 141 143 145 147 149 151 153 155 157 159 161 163 165 167 169 171...
output:
769389319
result:
ok "769389319"
Test #51:
score: 0
Accepted
time: 697ms
memory: 47260kb
input:
99999 99999 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 101 103 105 107 109 111 113 115 117 119 121 123 125 127 129 131 133 135 137 139 141 143 145 147 149 151 153 155 157 159 161 163 165 167 169 171...
output:
481565462
result:
ok "481565462"
Test #52:
score: 0
Accepted
time: 695ms
memory: 47268kb
input:
100000 1 1
output:
638474417
result:
ok "638474417"
Test #53:
score: 0
Accepted
time: 0ms
memory: 3636kb
input:
2 1 1
output:
24
result:
ok "24"
Test #54:
score: 0
Accepted
time: 296ms
memory: 25456kb
input:
50000 25000 5 11 13 15 17 21 29 35 37 39 47 49 51 53 55 57 59 63 65 67 69 73 75 83 91 105 107 113 117 123 129 131 133 135 137 139 149 151 153 159 161 163 171 177 183 187 189 195 203 207 209 211 213 217 229 231 237 245 249 251 259 263 265 269 271 275 279 281 283 285 289 293 295 299 305 307 311 313 31...
output:
215582594
result:
ok "215582594"
Test #55:
score: 0
Accepted
time: 713ms
memory: 47364kb
input:
100000 50000 9 13 15 17 23 27 35 37 39 43 47 53 55 57 65 77 81 85 87 91 95 97 101 105 107 109 111 115 117 125 131 137 139 147 149 151 155 161 167 169 171 173 179 187 189 195 201 205 213 217 219 221 227 231 235 237 239 241 243 249 251 253 255 261 263 267 271 279 289 299 303 305 307 311 315 317 321 32...
output:
638474417
result:
ok "638474417"
Extra Test:
score: 0
Extra Test Passed