QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#66109 | #4879. Standard Problem | japan022022 | AC ✓ | 325ms | 15592kb | C++20 | 28.4kb | 2022-12-06 21:51:54 | 2022-12-06 21:51:56 |
Judging History
answer
#line 1 "library/my_template.hpp"
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pi = pair<ll, ll>;
using vi = vector<ll>;
using u32 = unsigned int;
using u64 = unsigned long long;
using i128 = __int128;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vector<vc<T>>;
template <class T>
using vvvc = vector<vvc<T>>;
template <class T>
using vvvvc = vector<vvvc<T>>;
template <class T>
using vvvvvc = vector<vvvvc<T>>;
template <class T>
using pq = priority_queue<T>;
template <class T>
using pqg = priority_queue<T, vector<T>, greater<T>>;
#define vec(type, name, ...) vector<type> name(__VA_ARGS__)
#define vv(type, name, h, ...) \
vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...) \
vector<vector<vector<type>>> name( \
h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
#define vvvv(type, name, a, b, c, ...) \
vector<vector<vector<vector<type>>>> name( \
a, vector<vector<vector<type>>>( \
b, vector<vector<type>>(c, vector<type>(__VA_ARGS__))))
// https://trap.jp/post/1224/
#define FOR1(a) for (ll _ = 0; _ < ll(a); ++_)
#define FOR2(i, a) for (ll i = 0; i < ll(a); ++i)
#define FOR3(i, a, b) for (ll i = a; i < ll(b); ++i)
#define FOR4(i, a, b, c) for (ll i = a; i < ll(b); i += (c))
#define FOR1_R(a) for (ll i = (a)-1; i >= ll(0); --i)
#define FOR2_R(i, a) for (ll i = (a)-1; i >= ll(0); --i)
#define FOR3_R(i, a, b) for (ll i = (b)-1; i >= ll(a); --i)
#define FOR4_R(i, a, b, c) for (ll i = (b)-1; i >= ll(a); i -= (c))
#define overload4(a, b, c, d, e, ...) e
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FOR_R(...) \
overload4(__VA_ARGS__, FOR4_R, FOR3_R, FOR2_R, FOR1_R)(__VA_ARGS__)
#define FOR_subset(t, s) for (ll t = s; t >= 0; t = (t == 0 ? -1 : (t - 1) & s))
#define all(x) x.begin(), x.end()
#define len(x) ll(x.size())
#define elif else if
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define stoi stoll
template <typename T, typename U>
T SUM(const vector<U> &A) {
T sum = 0;
for (auto &&a: A) sum += a;
return sum;
}
#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define LB(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define UB(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define UNIQUE(x) sort(all(x)), x.erase(unique(all(x)), x.end())
int popcnt(int x) { return __builtin_popcount(x); }
int popcnt(u32 x) { return __builtin_popcount(x); }
int popcnt(ll x) { return __builtin_popcountll(x); }
int popcnt(u64 x) { return __builtin_popcountll(x); }
// (0, 1, 2, 3, 4) -> (-1, 0, 1, 1, 2)
int topbit(int x) { return (x == 0 ? -1 : 31 - __builtin_clz(x)); }
int topbit(u32 x) { return (x == 0 ? -1 : 31 - __builtin_clz(x)); }
int topbit(ll x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
int topbit(u64 x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
// (0, 1, 2, 3, 4) -> (-1, 0, 1, 0, 2)
int lowbit(int x) { return (x == 0 ? -1 : __builtin_ctz(x)); }
int lowbit(u32 x) { return (x == 0 ? -1 : __builtin_ctz(x)); }
int lowbit(ll x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }
int lowbit(u64 x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }
template <typename T>
T pick(deque<T> &que) {
T a = que.front();
que.pop_front();
return a;
}
template <typename T>
T pick(pq<T> &que) {
T a = que.top();
que.pop();
return a;
}
template <typename T>
T pick(pqg<T> &que) {
assert(que.size());
T a = que.top();
que.pop();
return a;
}
template <typename T>
T pick(vc<T> &que) {
assert(que.size());
T a = que.back();
que.pop_back();
return a;
}
template <typename T, typename U>
T ceil(T x, U y) {
return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U>
T floor(T x, U y) {
return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T, typename U>
pair<T, T> divmod(T x, U y) {
T q = floor(x, y);
return {q, x - q * y};
}
template <typename F>
ll binary_search(F check, ll ok, ll ng) {
assert(check(ok));
while (abs(ok - ng) > 1) {
auto x = (ng + ok) / 2;
tie(ok, ng) = (check(x) ? mp(x, ng) : mp(ok, x));
}
return ok;
}
template <typename F>
double binary_search_real(F check, double ok, double ng, int iter = 100) {
FOR(iter) {
double x = (ok + ng) / 2;
tie(ok, ng) = (check(x) ? mp(x, ng) : mp(ok, x));
}
return (ok + ng) / 2;
}
template <class T, class S>
inline bool chmax(T &a, const S &b) {
return (a < b ? a = b, 1 : 0);
}
template <class T, class S>
inline bool chmin(T &a, const S &b) {
return (a > b ? a = b, 1 : 0);
}
vc<int> s_to_vi(const string &S, char first_char) {
vc<int> A(S.size());
FOR(i, S.size()) { A[i] = S[i] - first_char; }
return A;
}
template <typename T, typename U>
vector<T> cumsum(vector<U> &A, int off = 1) {
int N = A.size();
vector<T> B(N + 1);
FOR(i, N) { B[i + 1] = B[i] + A[i]; }
if (off == 0) B.erase(B.begin());
return B;
}
template <typename CNT, typename T>
vc<CNT> bincount(const vc<T> &A, int size) {
vc<CNT> C(size);
for (auto &&x: A) { ++C[x]; }
return C;
}
// stable
template <typename T>
vector<int> argsort(const vector<T> &A) {
vector<int> ids(A.size());
iota(all(ids), 0);
sort(all(ids),
[&](int i, int j) { return A[i] < A[j] || (A[i] == A[j] && i < j); });
return ids;
}
// A[I[0]], A[I[1]], ...
template <typename T>
vc<T> rearrange(const vc<T> &A, const vc<int> &I) {
int n = len(I);
vc<T> B(n);
FOR(i, n) B[i] = A[I[i]];
return B;
}
#line 1 "library/other/io.hpp"
// based on yosupo's fastio
#include <unistd.h>
namespace fastio {
// クラスが read(), print() を持っているかを判定するメタ関数
struct has_write_impl {
template <class T>
static auto check(T &&x) -> decltype(x.write(), std::true_type{});
template <class T>
static auto check(...) -> std::false_type;
};
template <class T>
class has_write : public decltype(has_write_impl::check<T>(std::declval<T>())) {
};
struct has_read_impl {
template <class T>
static auto check(T &&x) -> decltype(x.read(), std::true_type{});
template <class T>
static auto check(...) -> std::false_type;
};
template <class T>
class has_read : public decltype(has_read_impl::check<T>(std::declval<T>())) {};
struct Scanner {
FILE *fp;
char line[(1 << 15) + 1];
size_t st = 0, ed = 0;
void reread() {
memmove(line, line + st, ed - st);
ed -= st;
st = 0;
ed += fread(line + ed, 1, (1 << 15) - ed, fp);
line[ed] = '\0';
}
bool succ() {
while (true) {
if (st == ed) {
reread();
if (st == ed) return false;
}
while (st != ed && isspace(line[st])) st++;
if (st != ed) break;
}
if (ed - st <= 50) {
bool sep = false;
for (size_t i = st; i < ed; i++) {
if (isspace(line[i])) {
sep = true;
break;
}
}
if (!sep) reread();
}
return true;
}
template <class T, enable_if_t<is_same<T, string>::value, int> = 0>
bool read_single(T &ref) {
if (!succ()) return false;
while (true) {
size_t sz = 0;
while (st + sz < ed && !isspace(line[st + sz])) sz++;
ref.append(line + st, sz);
st += sz;
if (!sz || st != ed) break;
reread();
}
return true;
}
template <class T, enable_if_t<is_integral<T>::value, int> = 0>
bool read_single(T &ref) {
if (!succ()) return false;
bool neg = false;
if (line[st] == '-') {
neg = true;
st++;
}
ref = T(0);
while (isdigit(line[st])) { ref = 10 * ref + (line[st++] & 0xf); }
if (neg) ref = -ref;
return true;
}
template <typename T,
typename enable_if<has_read<T>::value>::type * = nullptr>
inline bool read_single(T &x) {
x.read();
return true;
}
bool read_single(double &ref) {
string s;
if (!read_single(s)) return false;
ref = std::stod(s);
return true;
}
bool read_single(char &ref) {
string s;
if (!read_single(s) || s.size() != 1) return false;
ref = s[0];
return true;
}
template <class T>
bool read_single(vector<T> &ref) {
for (auto &d: ref) {
if (!read_single(d)) return false;
}
return true;
}
template <class T, class U>
bool read_single(pair<T, U> &p) {
return (read_single(p.first) && read_single(p.second));
}
template <size_t N = 0, typename T>
void read_single_tuple(T &t) {
if constexpr (N < std::tuple_size<T>::value) {
auto &x = std::get<N>(t);
read_single(x);
read_single_tuple<N + 1>(t);
}
}
template <class... T>
bool read_single(tuple<T...> &tpl) {
read_single_tuple(tpl);
return true;
}
void read() {}
template <class H, class... T>
void read(H &h, T &... t) {
bool f = read_single(h);
assert(f);
read(t...);
}
Scanner(FILE *fp) : fp(fp) {}
};
struct Printer {
Printer(FILE *_fp) : fp(_fp) {}
~Printer() { flush(); }
static constexpr size_t SIZE = 1 << 15;
FILE *fp;
char line[SIZE], small[50];
size_t pos = 0;
void flush() {
fwrite(line, 1, pos, fp);
pos = 0;
}
void write(const char &val) {
if (pos == SIZE) flush();
line[pos++] = val;
}
template <class T, enable_if_t<is_integral<T>::value, int> = 0>
void write(T val) {
if (pos > (1 << 15) - 50) flush();
if (val == 0) {
write('0');
return;
}
if (val < 0) {
write('-');
val = -val; // todo min
}
size_t len = 0;
while (val) {
small[len++] = char(0x30 | (val % 10));
val /= 10;
}
for (size_t i = 0; i < len; i++) { line[pos + i] = small[len - 1 - i]; }
pos += len;
}
void write(const string &s) {
for (char c: s) write(c);
}
void write(const char *s) {
size_t len = strlen(s);
for (size_t i = 0; i < len; i++) write(s[i]);
}
void write(const double &x) {
ostringstream oss;
oss << fixed << setprecision(15) << x;
string s = oss.str();
write(s);
}
void write(const long double &x) {
ostringstream oss;
oss << fixed << setprecision(15) << x;
string s = oss.str();
write(s);
}
template <typename T,
typename enable_if<has_write<T>::value>::type * = nullptr>
inline void write(T &x) {
x.write();
}
template <class T>
void write(const vector<T> &val) {
auto n = val.size();
for (size_t i = 0; i < n; i++) {
if (i) write(' ');
write(val[i]);
}
}
template <class T, class U>
void write(const pair<T, U> val) {
write(val.first);
write(' ');
write(val.second);
}
template <size_t N = 0, typename T>
void write_tuple(const T t) {
if constexpr (N < std::tuple_size<T>::value) {
if constexpr (N > 0) { write(' '); }
const auto x = std::get<N>(t);
write(x);
write_tuple<N + 1>(t);
}
}
template <class... T>
bool write(tuple<T...> tpl) {
write_tuple(tpl);
return true;
}
template <class T, size_t S>
void write(const array<T, S> &val) {
auto n = val.size();
for (size_t i = 0; i < n; i++) {
if (i) write(' ');
write(val[i]);
}
}
void write(i128 val) {
string s;
bool negative = 0;
if (val < 0) {
negative = 1;
val = -val;
}
while (val) {
s += '0' + int(val % 10);
val /= 10;
}
if (negative) s += "-";
reverse(all(s));
if (len(s) == 0) s = "0";
write(s);
}
};
Scanner scanner = Scanner(stdin);
Printer printer = Printer(stdout);
void flush() { printer.flush(); }
void print() { printer.write('\n'); }
template <class Head, class... Tail>
void print(Head &&head, Tail &&... tail) {
printer.write(head);
if (sizeof...(Tail)) printer.write(' ');
print(forward<Tail>(tail)...);
}
void read() {}
template <class Head, class... Tail>
void read(Head &head, Tail &... tail) {
scanner.read(head);
read(tail...);
}
} // namespace fastio
using fastio::print;
using fastio::flush;
using fastio::read;
#define INT(...) \
int __VA_ARGS__; \
read(__VA_ARGS__)
#define LL(...) \
ll __VA_ARGS__; \
read(__VA_ARGS__)
#define STR(...) \
string __VA_ARGS__; \
read(__VA_ARGS__)
#define CHAR(...) \
char __VA_ARGS__; \
read(__VA_ARGS__)
#define DBL(...) \
double __VA_ARGS__; \
read(__VA_ARGS__)
#define VEC(type, name, size) \
vector<type> name(size); \
read(name)
#define VV(type, name, h, w) \
vector<vector<type>> name(h, vector<type>(w)); \
read(name)
void YES(bool t = 1) { print(t ? "YES" : "NO"); }
void NO(bool t = 1) { YES(!t); }
void Yes(bool t = 1) { print(t ? "Yes" : "No"); }
void No(bool t = 1) { Yes(!t); }
void yes(bool t = 1) { print(t ? "yes" : "no"); }
void no(bool t = 1) { yes(!t); }
#line 2 "library/mod/modint.hpp"
template <int mod>
struct modint {
int val;
constexpr modint(ll x = 0) noexcept {
if (0 <= x && x < mod)
val = x;
else {
x %= mod;
val = (x < 0 ? x + mod : x);
}
}
bool operator<(const modint &other) const {
return val < other.val;
} // To use std::map
modint &operator+=(const modint &p) {
if ((val += p.val) >= mod) val -= mod;
return *this;
}
modint &operator-=(const modint &p) {
if ((val += mod - p.val) >= mod) val -= mod;
return *this;
}
modint &operator*=(const modint &p) {
val = (int)(1LL * val * p.val % mod);
return *this;
}
modint &operator/=(const modint &p) {
*this *= p.inverse();
return *this;
}
modint operator-() const { return modint(-val); }
modint operator+(const modint &p) const { return modint(*this) += p; }
modint operator-(const modint &p) const { return modint(*this) -= p; }
modint operator*(const modint &p) const { return modint(*this) *= p; }
modint operator/(const modint &p) const { return modint(*this) /= p; }
bool operator==(const modint &p) const { return val == p.val; }
bool operator!=(const modint &p) const { return val != p.val; }
modint inverse() const {
int a = val, b = mod, u = 1, v = 0, t;
while (b > 0) {
t = a / b;
swap(a -= t * b, b), swap(u -= t * v, v);
}
return modint(u);
}
modint pow(int64_t n) const {
modint ret(1), mul(val);
while (n > 0) {
if (n & 1) ret *= mul;
mul *= mul;
n >>= 1;
}
return ret;
}
void write() { fastio::printer.write(val); }
void read() { fastio::scanner.read(val); }
static constexpr int get_mod() { return mod; }
};
struct ArbitraryModInt {
static constexpr bool is_modint = true;
int val;
ArbitraryModInt() : val(0) {}
ArbitraryModInt(int64_t y)
: val(y >= 0 ? y % get_mod()
: (get_mod() - (-y) % get_mod()) % get_mod()) {}
bool operator<(const ArbitraryModInt &other) const {
return val < other.val;
} // To use std::map<ArbitraryModInt, T>
static int &get_mod() {
static int mod = 0;
return mod;
}
static void set_mod(int md) { get_mod() = md; }
ArbitraryModInt &operator+=(const ArbitraryModInt &p) {
if ((val += p.val) >= get_mod()) val -= get_mod();
return *this;
}
ArbitraryModInt &operator-=(const ArbitraryModInt &p) {
if ((val += get_mod() - p.val) >= get_mod()) val -= get_mod();
return *this;
}
ArbitraryModInt &operator*=(const ArbitraryModInt &p) {
long long a = (long long)val * p.val;
int xh = (int)(a >> 32), xl = (int)a, d, m;
asm("divl %4; \n\t" : "=a"(d), "=d"(m) : "d"(xh), "a"(xl), "r"(get_mod()));
val = m;
return *this;
}
ArbitraryModInt &operator/=(const ArbitraryModInt &p) {
*this *= p.inverse();
return *this;
}
ArbitraryModInt operator-() const { return ArbitraryModInt(get_mod() - val); }
ArbitraryModInt operator+(const ArbitraryModInt &p) const {
return ArbitraryModInt(*this) += p;
}
ArbitraryModInt operator-(const ArbitraryModInt &p) const {
return ArbitraryModInt(*this) -= p;
}
ArbitraryModInt operator*(const ArbitraryModInt &p) const {
return ArbitraryModInt(*this) *= p;
}
ArbitraryModInt operator/(const ArbitraryModInt &p) const {
return ArbitraryModInt(*this) /= p;
}
bool operator==(const ArbitraryModInt &p) const { return val == p.val; }
bool operator!=(const ArbitraryModInt &p) const { return val != p.val; }
ArbitraryModInt inverse() const {
int a = val, b = get_mod(), u = 1, v = 0, t;
while (b > 0) {
t = a / b;
swap(a -= t * b, b), swap(u -= t * v, v);
}
return ArbitraryModInt(u);
}
ArbitraryModInt pow(int64_t n) const {
ArbitraryModInt ret(1), mul(val);
while (n > 0) {
if (n & 1) ret *= mul;
mul *= mul;
n >>= 1;
}
return ret;
}
void write() { fastio::printer.write(val); }
void read() { fastio::scanner.read(val); }
};
template <typename mint>
mint inv(int n) {
static const int mod = mint::get_mod();
static vector<mint> dat = {0, 1};
assert(0 <= n);
if (n >= mod) n %= mod;
while (int(dat.size()) <= n) {
int k = dat.size();
auto q = (mod + k - 1) / k;
int r = k * q - mod;
dat.emplace_back(dat[r] * mint(q));
}
return dat[n];
}
template <typename mint>
mint fact(int n) {
static const int mod = mint::get_mod();
static vector<mint> dat = {1, 1};
assert(0 <= n);
if (n >= mod) return 0;
while (int(dat.size()) <= n) {
int k = dat.size();
dat.emplace_back(dat[k - 1] * mint(k));
}
return dat[n];
}
template <typename mint>
mint fact_inv(int n) {
static const int mod = mint::get_mod();
static vector<mint> dat = {1, 1};
assert(-1 <= n && n < mod);
if (n == -1) return mint(0);
while (int(dat.size()) <= n) {
int k = dat.size();
dat.emplace_back(dat[k - 1] * inv<mint>(k));
}
return dat[n];
}
template <class mint, class... Ts>
mint fact_invs(Ts... xs) {
return (mint(1) * ... * fact_inv<mint>(xs));
}
template <typename mint, class Head, class... Tail>
mint multinomial(Head &&head, Tail &&... tail) {
return fact<mint>(head) * fact_invs<mint>(std::forward<Tail>(tail)...);
}
template <typename mint>
mint C_dense(int n, int k) {
static vvc<mint> C;
static int H = 0, W = 0;
auto calc = [&](int i, int j) -> mint {
if (i == 0) return (j == 0 ? mint(1) : mint(0));
return C[i - 1][j] + (j ? C[i - 1][j - 1] : 0);
};
if (W <= k) {
FOR(i, H) {
C[i].resize(k + 1);
FOR(j, W, k + 1) { C[i][j] = calc(i, j); }
}
W = k + 1;
}
if (H <= n) {
C.resize(n + 1);
FOR(i, H, n + 1) {
C[i].resize(W);
FOR(j, W) { C[i][j] = calc(i, j); }
}
H = n + 1;
}
return C[n][k];
}
template <typename mint, bool large = false, bool dense = false>
mint C(ll n, ll k) {
assert(n >= 0);
if (k < 0 || n < k) return 0;
if (dense) return C_dense<mint>(n, k);
if (!large) return fact<mint>(n) * fact_inv<mint>(k) * fact_inv<mint>(n - k);
k = min(k, n - k);
mint x(1);
FOR(i, k) { x *= mint(n - i); }
x *= fact_inv<mint>(k);
return x;
}
template <typename mint, bool large = false>
mint C_inv(ll n, ll k) {
assert(n >= 0);
assert(0 <= k && k <= n);
if (!large) return fact_inv<mint>(n) * fact<mint>(k) * fact<mint>(n - k);
return mint(1) / C<mint, 1>(n, k);
}
// [x^d] (1-x) ^ {-n} の計算
template <typename mint, bool large = false, bool dense = false>
mint C_negative(ll n, ll d) {
assert(n >= 0);
if (d < 0) return mint(0);
if (n == 0) { return (d == 0 ? mint(1) : mint(0)); }
return C<mint, large, dense>(n + d - 1, d);
}
using modint107 = modint<1000000007>;
using modint998 = modint<998244353>;
using amint = ArbitraryModInt;
#line 2 "library/ds/segtree/lazy_segtree.hpp"
template <typename ActedMonoid>
struct Lazy_SegTree {
using AM = ActedMonoid;
using MX = typename AM::Monoid_X;
using MA = typename AM::Monoid_A;
static_assert(MX::commute);
using X = typename MX::value_type;
using A = typename MA::value_type;
int n, log, size;
vc<X> dat;
vc<A> laz;
Lazy_SegTree() {}
Lazy_SegTree(int n) { build(n); }
template <typename F>
Lazy_SegTree(int n, F f) {
build(n, f);
}
Lazy_SegTree(const vc<X>& v) { build(v); }
void build(int m) {
build(m, [](int i) -> X { return MX::unit(); });
}
void build(const vc<X>& v) {
build(len(v), [&](int i) -> X { return v[i]; });
}
template <typename F>
void build(int m, F f) {
n = m, log = 1;
while ((1 << log) < n) ++log;
size = 1 << log;
dat.assign(size << 1, MX::unit());
laz.assign(size, MA::unit());
FOR(i, n) dat[size + i] = f(i);
FOR_R(i, 1, size) update(i);
}
void update(int k) { dat[k] = MX::op(dat[2 * k], dat[2 * k + 1]); }
void set(int p, X x) {
assert(0 <= p && p < n);
p += size;
for (int i = log; i >= 1; i--) push(p >> i);
dat[p] = x;
for (int i = 1; i <= log; i++) update(p >> i);
}
X get(int p) {
assert(0 <= p && p < n);
p += size;
for (int i = log; i >= 1; i--) push(p >> i);
return dat[p];
}
vc<X> get_all() {
FOR(k, 1, size) { push(k); }
return {dat.begin() + size, dat.begin() + size + n};
}
X prod(int l, int r) {
assert(0 <= l && l <= r && r <= n);
if (l == r) return MX::unit();
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);
}
X x = MX::unit();
while (l < r) {
if (l & 1) x = MX::op(x, dat[l++]);
if (r & 1) x = MX::op(x, dat[--r]);
l >>= 1, r >>= 1;
}
return x;
}
X prod_all() { return dat[1]; }
void apply(int l, int r, A a) {
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) apply_at(l++, a);
if (r & 1) apply_at(--r, a);
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 <typename F>
int max_right(const F check, int l) {
assert(0 <= l && l <= n);
assert(check(MX::unit()));
if (l == n) return n;
l += size;
for (int i = log; i >= 1; i--) push(l >> i);
X sm = MX::unit();
do {
while (l % 2 == 0) l >>= 1;
if (!check(MX::op(sm, dat[l]))) {
while (l < size) {
push(l);
l = (2 * l);
if (check(MX::op(sm, dat[l]))) { sm = MX::op(sm, dat[l++]); }
}
return l - size;
}
sm = MX::op(sm, dat[l++]);
} while ((l & -l) != l);
return n;
}
template <typename F>
int min_left(const F check, int r) {
assert(0 <= r && r <= n);
assert(check(MX::unit()));
if (r == 0) return 0;
r += size;
for (int i = log; i >= 1; i--) push((r - 1) >> i);
X sm = MX::unit();
do {
r--;
while (r > 1 && (r % 2)) r >>= 1;
if (!check(MX::op(dat[r], sm))) {
while (r < size) {
push(r);
r = (2 * r + 1);
if (check(MX::op(dat[r], sm))) { sm = MX::op(dat[r--], sm); }
}
return r + 1 - size;
}
sm = MX::op(dat[r], sm);
} while ((r & -r) != r);
return 0;
}
private:
void apply_at(int k, A a) {
ll sz = 1 << (log - topbit(k));
dat[k] = AM::act(dat[k], a, sz);
if (k < size) laz[k] = MA::op(laz[k], a);
}
void push(int k) {
if (laz[k] == MA::unit()) return;
apply_at(2 * k, laz[k]), apply_at(2 * k + 1, laz[k]);
laz[k] = MA::unit();
}
};
#line 2 "library/alg/monoid/affine.hpp"
template <typename K>
struct Monoid_Affine {
using F = pair<K, K>;
using value_type = F;
static constexpr F op(const F &x, const F &y) noexcept {
return F({x.first * y.first, x.second * y.first + y.second});
}
static constexpr F inverse(const F &x) {
auto [a, b] = x;
a = K(1) / a;
return {a, a * (-b)};
}
static constexpr K eval(const F &f, K x) noexcept {
return f.first * x + f.second;
}
static constexpr F unit() { return {K(1), K(0)}; }
static constexpr bool commute = false;
};
#line 2 "library/alg/monoid/add.hpp"
template <typename X>
struct Monoid_Add {
using value_type = X;
static constexpr X op(const X &x, const X &y) noexcept { return x + y; }
static constexpr X inverse(const X &x) noexcept { return -x; }
static constexpr X power(const X &x, ll n) noexcept { return X(n) * x; }
static constexpr X unit() { return X(0); }
static constexpr bool commute = true;
};
#line 2 "library/alg/monoid/max.hpp"
template <class X>
struct Monoid_Max {
using value_type = X;
static constexpr X op(const X &x, const X &y) noexcept { return max(x, y); }
static constexpr X unit() { return numeric_limits<X>::lowest(); }
static constexpr bool commute = true;
};
#line 3 "library/alg/acted_monoid/max_add.hpp"
template <typename E>
struct ActedMonoid_Max_Add {
using Monoid_X = Monoid_Max<E>;
using Monoid_A = Monoid_Add<E>;
using X = typename Monoid_X::value_type;
using A = typename Monoid_A::value_type;
static constexpr X act(const X &x, const A &a, const ll &size) {
if (x == numeric_limits<E>::lowest()) return x;
return x + a;
}
};
#line 2 "library/ds/segtree/dual_segtree.hpp"
template <typename Monoid>
struct Dual_SegTree {
using MA = Monoid;
using A = typename MA::value_type;
int n, log, size;
vc<A> laz;
Dual_SegTree() : Dual_SegTree(0) {}
Dual_SegTree(int n) { build(n); }
void build(int m) {
n = m;
log = 1;
while ((1 << log) < n) ++log;
size = 1 << log;
laz.assign(size << 1, MA::unit());
}
A get(int p) {
assert(0 <= p && p < n);
p += size;
for (int i = log; i >= 1; i--) push(p >> i);
return laz[p];
}
vc<A> get_all() {
FOR(i, size) push(i);
return {laz.begin() + size, laz.begin() + size + n};
}
void apply(int l, int r, const A& a) {
assert(0 <= l && l <= r && r <= n);
if (l == r) return;
l += size, r += size;
if (!MA::commute) {
for (int i = log; i >= 1; i--) {
if (((l >> i) << i) != l) push(l >> i);
if (((r >> i) << i) != r) push((r - 1) >> i);
}
}
while (l < r) {
if (l & 1) all_apply(l++, a);
if (r & 1) all_apply(--r, a);
l >>= 1, r >>= 1;
}
}
private:
void push(int k) {
if (laz[k] == MA::unit()) return;
all_apply(2 * k, laz[k]), all_apply(2 * k + 1, laz[k]);
laz[k] = MA::unit();
}
void all_apply(int k, A a) { laz[k] = MA::op(laz[k], a); }
};
#line 8 "main.cpp"
using mint = modint998;
struct AM {
using Monoid_X = Monoid_Max<ll>;
using Monoid_A = Monoid_Affine<ll>;
using X = typename Monoid_X::value_type;
using A = typename Monoid_A::value_type;
static constexpr X act(const X &x, const A &a, const ll &size) {
assert(a.fi == 0 || a.fi == 1);
return a.fi * x + a.se;
}
};
void solve() {
LL(N, M);
// i -> 末尾が i 以下であるような LIS の重み最大
Lazy_SegTree<AM> seg1(M + 1, [](int i) -> int { return 0; });
// i -> 末尾が i 以下であるような LIS の最大長に対応する数え上げ
using AFF = Monoid_Affine<mint>;
Dual_SegTree<AFF> seg2(M + 1);
FOR(N) {
LL(L, R, c);
// [L, R] に c を加算
seg1.apply(L, R + 1, {1, c});
// print(seg1.get_all());
ll val = seg1.prod(R, R + 1);
mint cnt = AFF::eval(seg2.get(R), mint(1));
int p = R + 1;
int q = seg1.max_right([&](auto e) -> bool { return e < val; }, p);
seg1.apply(p, q, {0, val});
seg2.apply(p, q, {mint(0), cnt});
p = q;
q = seg1.max_right([&](auto e) -> bool { return e <= val; }, p);
seg2.apply(p, q, {mint(1), cnt});
// print(seg1.get_all());
}
print(seg1.prod(M, M + 1), AFF::eval(seg2.get(M), mint(1)));
}
signed main() {
LL(T);
FOR(T) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3420kb
input:
2 3 4 1 2 1 2 3 1 2 2 1 2 5 1 4 3 2 5 3
output:
3 1 6 1
result:
ok 4 number(s): "3 1 6 1"
Test #2:
score: 0
Accepted
time: 2ms
memory: 3356kb
input:
30 3 3 1 3 1 1 3 1 1 3 1 3 3 1 2 1 1 3 1 1 3 1 3 3 2 2 1 1 3 1 1 3 1 3 3 1 3 1 1 2 1 1 3 1 3 3 2 3 1 1 2 1 1 3 1 3 3 2 2 1 1 3 1 1 3 1 3 3 2 2 1 1 2 1 1 3 1 3 3 1 3 1 2 3 1 1 3 1 3 3 2 3 1 1 3 1 2 2 1 3 3 1 2 1 1 2 1 1 2 1 3 3 1 3 1 1 3 1 1 3 1 3 3 1 3 1 1 2 1 1 3 1 3 3 2 3 1 1 2 1 1 3 1 3 3 1 3 1 1...
output:
3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 2 2 3 1 3 1 3 1 3 1 2 2 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1
result:
ok 60 numbers
Test #3:
score: 0
Accepted
time: 2ms
memory: 3380kb
input:
20 5 5 1 5 1 1 5 1 1 4 1 1 5 1 1 5 1 5 5 2 4 1 1 5 1 1 5 1 2 4 1 2 4 1 5 5 2 4 1 1 5 1 1 5 1 2 5 1 1 3 1 5 5 1 5 1 1 5 1 2 3 1 1 5 1 1 4 1 5 5 1 4 1 1 4 1 2 5 1 1 3 1 2 4 1 5 5 2 4 1 3 3 1 1 3 1 2 4 1 4 4 1 5 5 3 3 1 1 4 1 3 3 1 2 5 1 2 5 1 5 5 2 4 1 2 3 1 4 4 1 2 4 1 2 4 1 5 5 3 3 1 3 3 1 2 4 1 1 4...
output:
5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 4 1 5 1 5 1 5 1 5 1 5 1 4 1 5 1 5 1 5 1 5 1 5 1
result:
ok 40 numbers
Test #4:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
10 10 10 1 10 1 1 10 1 1 9 1 2 7 1 1 9 1 1 10 1 1 9 1 1 9 1 1 9 1 1 10 1 10 10 1 8 1 1 10 1 2 10 1 3 10 1 1 10 1 4 10 1 1 8 1 1 10 1 1 9 1 1 10 1 10 10 1 7 1 4 7 1 1 8 1 4 6 1 1 10 1 2 10 1 2 10 1 1 10 1 3 10 1 5 7 1 10 10 3 7 1 1 10 1 1 6 1 1 9 1 2 9 1 2 6 1 2 9 1 1 10 1 2 10 1 4 8 1 10 10 3 8 1 4 ...
output:
10 1 10 1 10 1 10 1 10 1 10 1 10 1 9 1 9 1 10 1
result:
ok 20 numbers
Test #5:
score: 0
Accepted
time: 60ms
memory: 3516kb
input:
10000 20 20 2 3 1 2 3 1 1 6 1 1 6 1 1 2 1 1 1 1 1 5 1 4 4 1 1 2 1 2 4 1 1 2 1 1 6 1 1 2 1 1 9 1 1 4 1 8 11 1 2 11 1 1 8 1 2 4 1 2 7 1 20 20 4 8 1 1 2 1 2 3 1 2 2 1 1 5 1 3 7 1 1 4 1 2 7 1 3 4 1 1 2 1 5 5 1 1 6 1 1 7 1 1 8 1 1 1 1 1 1 1 3 3 1 2 3 1 1 1 1 1 2 1 20 20 1 1 1 3 11 1 1 8 1 2 9 1 2 7 1 3 9...
output:
17 1 13 1 17 2 12 6 16 1 20 1 20 1 19 1 17 1 13 9 13 4 14 3 12 1 11 3 12 9 19 2 20 1 20 1 19 2 13 4 13 2 13 7 16 2 16 1 18 1 20 1 20 1 20 1 16 5 18 1 13 2 14 4 13 2 14 2 13 6 20 1 20 1 19 1 17 2 15 2 13 4 15 2 16 1 13 2 12 6 20 1 20 1 20 1 18 1 14 4 15 2 15 2 13 5 13 6 16 1 20 1 20 1 20 1 20 1 18 1 ...
result:
ok 20000 numbers
Test #6:
score: 0
Accepted
time: 113ms
memory: 3392kb
input:
1000 200 200 1 21 1 93 108 1 52 55 1 61 67 1 1 23 1 70 72 1 1 8 1 21 78 1 1 20 1 6 31 1 71 85 1 4 57 1 9 15 1 63 101 1 48 60 1 93 100 1 55 77 1 94 96 1 59 59 1 3 4 1 6 7 1 3 21 1 14 20 1 88 93 1 46 52 1 1 29 1 1 19 1 45 46 1 3 35 1 3 16 1 79 105 1 84 104 1 16 17 1 41 48 1 4 7 1 2 48 1 101 117 1 14 7...
output:
74 24 68 16 73 12 88 12 111 2 198 1 195 1 190 3 177 2 140 9 70 140 74 14 84 4 93 32 109 14 196 3 197 4 195 1 175 1 130 28 74 124 68 6 84 2 104 8 119 2 194 2 194 2 194 1 172 6 135 4 62 360 74 36 82 180 87 6 107 4 197 2 197 1 189 2 177 2 139 2 71 8 76 20 82 8 102 2 107 208 196 2 198 1 192 3 178 3 135 ...
result:
ok 2000 numbers
Test #7:
score: 0
Accepted
time: 270ms
memory: 9332kb
input:
1 200000 70000 3758 4743 1 33161 33877 1 24037 24952 1 33131 33134 1 24741 25130 1 12964 13639 1 32062 32778 1 12046 12449 1 28229 29159 1 12021 12282 1 5329 6033 1 16581 16923 1 30368 31177 1 29343 29965 1 32647 33027 1 25775 26193 1 878 1026 1 17927 17950 1 16554 16592 1 30029 30096 1 19536 19742 ...
output:
4170 745614878
result:
ok 2 number(s): "4170 745614878"
Test #8:
score: 0
Accepted
time: 264ms
memory: 15588kb
input:
1 200000 200000 78834 78835 1 80528 80530 1 47499 47503 1 65196 65198 1 36003 36005 1 79144 79146 1 91460 91460 1 87949 87951 1 97054 97054 1 99216 99219 1 1043 1046 1 25088 25089 1 59424 59428 1 78742 78744 1 46264 46265 1 44746 44750 1 84877 84881 1 24091 24094 1 35772 35774 1 77841 77841 1 96537 ...
output:
898 862947721
result:
ok 2 number(s): "898 862947721"
Test #9:
score: 0
Accepted
time: 292ms
memory: 15516kb
input:
1 200000 200000 70228 70241 1 2243 2290 1 37711 37751 1 65609 65630 1 35069 35114 1 55461 55502 1 45322 45352 1 63193 63237 1 47993 48004 1 77797 77807 1 65933 65943 1 50756 50758 1 89846 89848 1 40757 40796 1 32542 32568 1 71472 71518 1 36752 36753 1 78477 78511 1 64720 64750 1 17369 17372 1 51635 ...
output:
958 258160284
result:
ok 2 number(s): "958 258160284"
Test #10:
score: 0
Accepted
time: 325ms
memory: 15564kb
input:
1 200000 200000 75340 75924 1 89847 90265 1 59883 60818 1 26303 26836 1 83285 84012 1 51579 51933 1 83631 83730 1 34162 35024 1 82604 83469 1 22334 22878 1 39351 40150 1 74106 74554 1 6193 6244 1 16427 16530 1 20013 20625 1 34653 35093 1 83885 84698 1 66234 67215 1 35548 36129 1 998 1540 1 86220 871...
output:
2172 380312816
result:
ok 2 number(s): "2172 380312816"
Test #11:
score: 0
Accepted
time: 152ms
memory: 15592kb
input:
1 200000 200000 1 4 1 3 4 1 1 3 1 1 2 1 4 7 1 7 10 1 6 8 1 3 6 1 7 7 1 2 3 1 6 6 1 8 10 1 4 6 1 9 11 1 2 3 1 10 14 1 6 7 1 11 11 1 19 20 1 1 5 1 8 8 1 6 9 1 2 3 1 16 19 1 18 20 1 23 27 1 6 9 1 6 10 1 30 32 1 19 23 1 17 21 1 7 9 1 15 19 1 3 5 1 1 2 1 37 38 1 14 16 1 14 16 1 26 28 1 5 9 1 34 38 1 26 2...
output:
31676 227442792
result:
ok 2 number(s): "31676 227442792"
Test #12:
score: 0
Accepted
time: 155ms
memory: 15584kb
input:
1 200000 200000 2 16 1 3 24 1 3 21 1 5 36 1 3 30 1 6 45 1 7 17 1 6 46 1 4 28 1 1 11 1 11 26 1 9 51 1 1 18 1 9 41 1 8 23 1 10 10 1 1 41 1 5 27 1 16 55 1 20 27 1 10 53 1 12 52 1 20 32 1 1 3 1 1 49 1 24 65 1 20 56 1 18 29 1 11 32 1 20 48 1 3 22 1 20 53 1 32 76 1 4 43 1 17 37 1 34 74 1 12 17 1 32 68 1 1...
output:
68340 480122735
result:
ok 2 number(s): "68340 480122735"
Test #13:
score: 0
Accepted
time: 162ms
memory: 15324kb
input:
1 200000 200000 1 105 1 3 24 1 3 742 1 3 689 1 5 445 1 5 384 1 1 796 1 3 880 1 8 984 1 4 907 1 8 79 1 12 887 1 1 731 1 8 154 1 6 745 1 6 328 1 7 487 1 7 526 1 2 819 1 6 698 1 10 464 1 13 222 1 3 885 1 10 222 1 14 627 1 20 133 1 13 600 1 22 507 1 23 342 1 14 58 1 21 546 1 27 283 1 7 720 1 22 337 1 1 ...
output:
98727 824244096
result:
ok 2 number(s): "98727 824244096"
Test #14:
score: 0
Accepted
time: 63ms
memory: 15536kb
input:
1 79364 198410 79365 79366 1 79367 79368 1 79369 79370 1 79371 79372 1 79373 79374 1 79375 79376 1 79377 79378 1 79379 79380 1 79381 79382 1 79383 79384 1 79385 79386 1 79387 79388 1 79389 79390 1 79391 79392 1 79393 79394 1 79395 79396 1 79397 79398 1 79399 79400 1 79401 79402 1 79403 79404 1 79405...
output:
39682 2
result:
ok 2 number(s): "39682 2"
Test #15:
score: 0
Accepted
time: 50ms
memory: 3572kb
input:
10000 20 20 1 20 1 1 20 1 1 17 1 1 17 1 1 18 1 2 15 1 2 18 1 3 19 1 2 20 1 1 18 1 1 20 1 2 20 1 2 16 1 4 18 1 3 20 1 1 19 1 2 20 1 1 20 1 1 19 1 1 20 1 20 20 2 16 1 6 17 1 4 19 1 4 18 1 1 19 1 1 20 1 1 18 1 2 20 1 1 14 1 1 20 1 3 18 1 1 20 1 2 20 1 1 20 1 4 15 1 2 20 1 1 20 1 3 20 1 4 20 1 1 18 1 20...
output:
20 1 20 1 20 1 20 1 20 1 19 1 19 1 19 1 18 2 18 1 20 1 20 1 20 1 20 1 20 1 20 1 18 1 18 1 17 2 17 1 20 1 20 1 20 1 19 2 20 1 20 1 19 1 18 3 16 4 16 2 20 1 20 1 20 1 20 1 20 1 20 1 20 1 17 3 19 1 18 1 20 1 20 1 20 1 20 1 20 1 18 2 20 1 16 1 16 3 18 1 20 1 20 1 20 1 20 1 18 2 20 1 20 1 19 1 18 2 19 2 ...
result:
ok 20000 numbers
Test #16:
score: 0
Accepted
time: 101ms
memory: 3588kb
input:
1000 200 200 1 199 1 1 200 1 1 194 1 48 158 1 88 118 1 6 199 1 2 196 1 58 141 1 34 190 1 94 123 1 1 200 1 85 113 1 74 120 1 56 140 1 98 115 1 68 133 1 95 112 1 6 199 1 24 187 1 93 113 1 5 200 1 4 194 1 52 138 1 85 126 1 30 171 1 74 151 1 46 164 1 3 197 1 98 103 1 86 116 1 86 112 1 9 190 1 97 98 1 10...
output:
197 1 194 1 195 2 195 2 195 1 192 3 194 4 195 2 192 2 187 1 198 2 194 2 198 1 196 1 192 8 196 2 195 1 190 1 190 1 186 6 197 1 197 2 195 2 190 4 190 2 195 1 194 2 192 1 192 6 188 3 196 2 192 1 192 4 195 4 189 4 193 5 195 2 195 4 191 2 190 11 195 1 196 3 188 3 192 1 191 2 192 3 196 2 199 1 189 6 188 6...
result:
ok 2000 numbers
Test #17:
score: 0
Accepted
time: 250ms
memory: 9328kb
input:
1 200000 70000 27719 42274 1 6647 63356 1 5652 64350 1 22872 47119 1 3679 66321 1 11511 58495 1 23308 46704 1 24449 45557 1 33000 36998 1 5669 64344 1 2638 67371 1 17273 52732 1 26524 43487 1 6542 63460 1 23855 46144 1 3415 66589 1 8348 61652 1 10806 59196 1 14117 55892 1 2754 67250 1 10393 59604 1 ...
output:
199993 1
result:
ok 2 number(s): "199993 1"
Test #18:
score: 0
Accepted
time: 255ms
memory: 15592kb
input:
1 200000 200000 13120 186896 1 57545 142432 1 91680 108341 1 46072 153888 1 4082 195951 1 59587 140389 1 22601 177420 1 95670 104331 1 56267 143757 1 86957 113079 1 25102 174930 1 4532 195474 1 21523 178514 1 83244 116749 1 42887 157135 1 40685 159320 1 96933 103074 1 21007 179004 1 79655 120339 1 5...
output:
199986 8
result:
ok 2 number(s): "199986 8"
Test #19:
score: 0
Accepted
time: 178ms
memory: 15468kb
input:
1 200000 200000 2 199999 1 1 200000 1 1 200000 1 5 200000 1 4 199997 1 3 199996 1 7 200000 1 7 199992 1 8 199995 1 10 199997 1 8 199995 1 13 199989 1 11 199992 1 7 199989 1 8 200000 1 8 199997 1 12 199988 1 3 199983 1 10 199985 1 10 199982 1 13 199990 1 1 199985 1 19 199992 1 10 199995 1 8 199975 1 ...
output:
199985 1
result:
ok 2 number(s): "199985 1"
Test #20:
score: 0
Accepted
time: 135ms
memory: 3768kb
input:
300 1497 2969 558 2856 1 1484 1893 1 438 2226 1 1292 2738 1 397 903 1 1181 1723 1 2692 2880 1 885 2721 1 951 1346 1 937 2486 1 409 929 1 311 1817 1 458 1530 1 1058 1216 1 1056 1104 1 2484 2706 1 766 1796 1 754 1413 1 1684 2509 1 173 1090 1 580 1121 1 2047 2086 1 1586 1841 1 428 1819 1 1599 2696 1 73...
output:
816 280 1349 16248 249 2 92 600 348 48 23 1 38 2 297 40 196 16 1346 288 54 4 188 72 396 24 109 50 224 30 63 8 118 2 74 12 193 336 306 80 522 64 379 120 1672 1 515 8 256 56 565 45 64 2 73 2 616 128 178 8 4 2 64 2 732 6 21 9 120 8 334 128 15 7 170 320 31 1 302 72 464 4 50 13 717 1104 405 8 71 4 483 12...
result:
ok 600 numbers
Test #21:
score: 0
Accepted
time: 314ms
memory: 15460kb
input:
1 200000 200000 53839 55210 1 103761 171904 1 51490 64117 1 52415 59053 1 28403 81648 1 36025 96539 1 34877 167586 1 37797 192220 1 103331 198197 1 104826 194492 1 70132 87411 1 60069 142685 1 124807 162475 1 56049 120528 1 109669 121796 1 36092 179102 1 156082 170394 1 117350 157532 1 39585 145600 ...
output:
100201 402633336
result:
ok 2 number(s): "100201 402633336"
Test #22:
score: 0
Accepted
time: 53ms
memory: 15540kb
input:
1 79364 198410 158727 198410 1 158725 198410 1 158723 198410 1 158721 198410 1 158719 198410 1 158717 198410 1 158715 198410 1 158713 198410 1 158711 198410 1 158709 198410 1 158707 198410 1 158705 198410 1 158703 198410 1 158701 198410 1 158699 198410 1 158697 198410 1 158695 198410 1 158693 198410...
output:
39682 2
result:
ok 2 number(s): "39682 2"
Test #23:
score: 0
Accepted
time: 30ms
memory: 15404kb
input:
1 66666 199998 133331 199998 1 133329 199998 1 133327 199998 1 133325 199998 1 133323 199998 1 133321 199998 1 133319 199998 1 133317 199998 1 133315 199998 1 133313 199998 1 133311 199998 1 133309 199998 1 133307 199998 1 133305 199998 1 133303 199998 1 133301 199998 1 133299 199998 1 133297 199998...
output:
66666 1
result:
ok 2 number(s): "66666 1"
Test #24:
score: 0
Accepted
time: 46ms
memory: 3516kb
input:
10000 20 20 2 20 5 1 20 5 2 20 2 1 20 6 3 17 3 1 20 4 2 20 7 5 20 1 1 18 5 2 18 7 2 18 2 2 18 1 1 19 6 1 20 3 1 20 7 1 16 1 2 18 10 9 15 8 1 19 6 5 20 4 20 20 2 15 3 2 19 7 1 20 2 1 18 6 3 20 5 1 20 9 1 20 10 1 19 1 1 19 3 3 16 7 2 19 4 3 17 3 1 20 10 3 16 4 2 18 4 2 15 6 2 20 2 2 20 9 3 20 5 2 13 5...
output:
93 1 105 1 128 1 117 1 114 1 124 1 98 1 101 1 127 1 117 1 112 1 108 1 111 1 99 1 97 1 105 1 106 1 116 1 97 1 107 1 113 1 115 1 86 1 137 1 99 1 108 2 114 1 94 1 96 1 83 1 113 1 104 1 99 1 82 1 117 1 91 1 103 1 107 1 100 1 86 1 123 1 111 1 119 1 112 1 78 1 128 1 122 1 117 1 91 1 108 1 118 1 99 1 99 1 ...
result:
ok 20000 numbers
Test #25:
score: 0
Accepted
time: 101ms
memory: 3496kb
input:
1000 200 200 62 139 8 89 110 10 40 183 5 59 156 10 3 189 4 75 128 4 78 125 1 5 192 9 8 195 3 32 151 3 92 99 9 65 139 1 74 119 2 12 185 6 70 143 2 3 194 5 24 174 5 80 142 6 63 144 3 71 134 10 1 200 5 85 123 1 95 126 8 112 121 8 94 111 10 92 113 1 1 199 5 57 144 9 81 122 4 52 160 5 2 200 9 60 139 10 5...
output:
1077 1 1073 1 1028 1 1048 1 1088 2 1075 1 1021 1 1008 2 1093 2 1127 1 1083 1 1104 1 1102 1 1146 1 994 1 1047 1 970 1 1089 1 1052 1 998 1 996 1 1135 1 1155 1 1158 1 1046 1 1129 1 1012 1 1080 2 990 1 1002 1 1077 1 1098 1 1089 1 995 1 1109 1 1133 1 1037 1 1108 1 1053 2 1088 1 1043 1 1153 1 1053 1 1051 ...
result:
ok 2000 numbers
Test #26:
score: 0
Accepted
time: 234ms
memory: 9452kb
input:
1 200000 70000 13421 56568 1 4349 65667 2 15557 54445 2 25559 44450 1 23675 46328 1 13772 56231 1 23551 46447 3 23209 46801 2 6747 63266 1 8699 61307 1 24946 45064 3 18881 51117 3 25923 44084 3 31091 38916 1 31929 38072 2 16293 53701 2 16194 53809 2 10662 59337 3 6960 63032 3 25829 44157 2 34484 355...
output:
400757 1
result:
ok 2 number(s): "400757 1"
Test #27:
score: 0
Accepted
time: 255ms
memory: 15464kb
input:
1 200000 200000 14346 185691 9 15513 184451 4 95019 104950 3 5289 194720 4 78689 121304 1 54194 145818 4 17594 182430 10 45423 154549 7 32203 167784 6 80570 119468 6 57035 142929 3 50995 149009 8 56869 143107 9 68883 131145 3 49209 150773 8 8768 191241 3 18033 181985 2 19511 180501 10 83354 116645 2...
output:
1101347 2
result:
ok 2 number(s): "1101347 2"
Test #28:
score: 0
Accepted
time: 255ms
memory: 15456kb
input:
1 200000 200000 1835 1860 3 72172 72215 7 80101 80110 6 19476 19513 9 93148 93242 8 46447 46522 9 35057 35071 6 66552 66630 8 83931 83967 4 8564 8567 10 20863 20946 1 39346 39441 6 25535 25599 8 12284 12309 3 9979 9999 6 99467 99549 9 22984 23004 10 1635 1665 4 72541 72615 3 99278 99346 2 50884 5091...
output:
6621 113246208
result:
ok 2 number(s): "6621 113246208"
Test #29:
score: 0
Accepted
time: 148ms
memory: 15464kb
input:
1 200000 200000 2 5 7 1 88 5 2 93 9 3 29 1 1 29 3 4 93 5 7 27 4 9 32 6 8 29 9 8 103 9 10 76 4 3 89 6 4 23 6 8 64 4 3 43 8 15 77 3 13 51 6 19 26 6 4 40 7 5 95 9 21 60 5 18 58 6 3 73 10 19 79 1 15 49 7 12 105 3 26 88 8 1 55 8 21 65 8 30 60 9 31 89 1 33 116 6 31 112 2 11 82 10 34 75 7 22 24 5 27 69 1 1...
output:
462635 711287574
result:
ok 2 number(s): "462635 711287574"
Test #30:
score: 0
Accepted
time: 123ms
memory: 3588kb
input:
300 55 318 69 305 4029 182 308 4191 40 306 2136 6 262 1542 105 128 4386 75 192 2596 131 288 3792 112 118 632 34 187 785 104 119 3567 231 253 3264 164 215 2600 82 107 4796 115 168 1140 39 165 1064 95 291 2364 184 232 49 22 264 972 4 190 4675 10 245 3304 67 183 3844 171 175 400 88 140 3296 85 130 2544...
output:
93668 1 1475675 1 1861822 1 1729524 1 1017322 1 906885 1 259697 1 585460 1 1139624 1 63824 1 1015898 1 683051 1 780407 1 555390 1 68540 1 1196528 1 1398141 1 94744 1 548364 1 667084 1 371386 2 161105 1 1292366 1 393038 1 635798 1 799982 1 113188 1 204880 1 22995 1 79812 1 223924 1 777346 1 119204 1 ...
result:
ok 600 numbers
Test #31:
score: 0
Accepted
time: 279ms
memory: 15460kb
input:
1 200000 200000 54789 89627 8054928 128204 171619 8705846 111831 185204 287046 35223 98646 1902720 37958 87251 9760212 74544 85603 1537270 70376 131929 4873392 44922 170533 2705892 166191 168630 9013379 27266 128950 7524690 93950 112980 5561322 63354 106040 4891284 42904 153325 9266452 11155 35900 2...
output:
494907106860 1
result:
ok 2 number(s): "494907106860 1"
Test #32:
score: 0
Accepted
time: 26ms
memory: 15460kb
input:
1 59524 198410 158727 198410 1 158725 198410 1 158723 198410 1 158721 198410 1 158719 198410 1 158717 198410 1 158715 198410 1 158713 198410 1 158711 198410 1 158709 198410 1 158707 198410 1 158705 198410 1 158703 198410 1 158701 198410 1 158699 198410 1 158697 198410 1 158695 198410 1 158693 198410...
output:
1000019841 1
result:
ok 2 number(s): "1000019841 1"
Test #33:
score: 0
Accepted
time: 75ms
memory: 15520kb
input:
1 59524 198410 79365 79366 1 79367 79368 1 79369 79370 1 79371 79372 1 79373 79374 1 79375 79376 1 79377 79378 1 79379 79380 1 79381 79382 1 79383 79384 1 79385 79386 1 79387 79388 1 79389 79390 1 79391 79392 1 79393 79394 1 79395 79396 1 79397 79398 1 79399 79400 1 79401 79402 1 79403 79404 1 79405...
output:
1000019841 1
result:
ok 2 number(s): "1000019841 1"
Test #34:
score: 0
Accepted
time: 45ms
memory: 15468kb
input:
1 79364 198410 158727 198410 1 158725 198410 1 158723 198410 1 158721 198410 1 158719 198410 1 158717 198410 1 158715 198410 1 158713 198410 1 158711 198410 1 158709 198410 1 158707 198410 1 158705 198410 1 158703 198410 1 158701 198410 1 158699 198410 1 158697 198410 1 158695 198410 1 158693 198410...
output:
29762000000000 1
result:
ok 2 number(s): "29762000000000 1"
Test #35:
score: 0
Accepted
time: 64ms
memory: 15460kb
input:
1 79364 198410 79365 79366 1 79367 79368 1 79369 79370 1 79371 79372 1 79373 79374 1 79375 79376 1 79377 79378 1 79379 79380 1 79381 79382 1 79383 79384 1 79385 79386 1 79387 79388 1 79389 79390 1 79391 79392 1 79393 79394 1 79395 79396 1 79397 79398 1 79399 79400 1 79401 79402 1 79403 79404 1 79405...
output:
29762000000000 1
result:
ok 2 number(s): "29762000000000 1"