QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#791061 | #8522. Waterfall Matrix | maspy | AC ✓ | 1793ms | 112604kb | C++23 | 22.8kb | 2024-11-28 16:39:43 | 2024-11-28 16:39:45 |
Judging History
answer
#line 1 "/home/maspy/compro/library/my_template.hpp"
#if defined(LOCAL)
#include <my_template_compiled.hpp>
#else
// https://codeforces.com/blog/entry/96344
#pragma GCC optimize("Ofast,unroll-loops")
// いまの CF だとこれ入れると動かない?
// #pragma GCC target("avx2,popcnt")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i128 = __int128;
using u128 = unsigned __int128;
using f128 = __float128;
template <class T>
constexpr T infty = 0;
template <>
constexpr int infty<int> = 1'010'000'000;
template <>
constexpr ll infty<ll> = 2'020'000'000'000'000'000;
template <>
constexpr u32 infty<u32> = infty<int>;
template <>
constexpr u64 infty<u64> = infty<ll>;
template <>
constexpr i128 infty<i128> = i128(infty<ll>) * 2'000'000'000'000'000'000;
template <>
constexpr double infty<double> = infty<ll>;
template <>
constexpr long double infty<long double> = infty<ll>;
using pi = pair<ll, ll>;
using vi = vector<ll>;
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 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 overload4(a, b, c, d, e, ...) e
#define overload3(a, b, c, d, ...) d
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FOR_R(...) overload3(__VA_ARGS__, 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
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); }
int popcnt_sgn(int x) { return (__builtin_parity(x) & 1 ? -1 : 1); }
int popcnt_sgn(u32 x) { return (__builtin_parity(x) & 1 ? -1 : 1); }
int popcnt_sgn(ll x) { return (__builtin_parity(x) & 1 ? -1 : 1); }
int popcnt_sgn(u64 x) { return (__builtin_parity(x) & 1 ? -1 : 1); }
// (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 kth_bit(int k) {
return T(1) << k;
}
template <typename T>
bool has_kth_bit(T x, int k) {
return x >> k & 1;
}
template <typename T>
T floor(T a, T b) {
return a / b - (a % b && (a ^ b) < 0);
}
template <typename T>
T ceil(T x, T y) {
return floor(x + y - 1, y);
}
template <typename T>
T bmod(T x, T y) {
return x - y * floor(x, y);
}
template <typename T>
pair<T, T> divmod(T x, T y) {
T q = floor(x, y);
return {q, x - q * y};
}
template <typename T, typename U>
T SUM(const vector<U> &A) {
T sm = 0;
for (auto &&a: A) sm += a;
return sm;
}
#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()), x.shrink_to_fit()
template <typename T>
T POP(deque<T> &que) {
T a = que.front();
que.pop_front();
return a;
}
template <typename T>
T POP(pq<T> &que) {
T a = que.top();
que.pop();
return a;
}
template <typename T>
T POP(pqg<T> &que) {
T a = que.top();
que.pop();
return a;
}
template <typename T>
T POP(vc<T> &que) {
T a = que.back();
que.pop_back();
return a;
}
template <typename F>
ll binary_search(F check, ll ok, ll ng, bool check_ok = true) {
if (check_ok) assert(check(ok));
while (abs(ok - ng) > 1) {
auto x = (ng + ok) / 2;
(check(x) ? ok : ng) = 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;
(check(x) ? ok : ng) = 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);
}
// ? は -1
vc<int> s_to_vi(const string &S, char first_char) {
vc<int> A(S.size());
FOR(i, S.size()) { A[i] = (S[i] != '?' ? S[i] - first_char : -1); }
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;
}
// stable sort
template <typename T>
vector<int> argsort(const vector<T> &A) {
vector<int> ids(len(A));
iota(all(ids), 0);
sort(all(ids), [&](int i, int j) { return (A[i] == A[j] ? i < j : A[i] < A[j]); });
return ids;
}
// A[I[0]], A[I[1]], ...
template <typename T>
vc<T> rearrange(const vc<T> &A, const vc<int> &I) {
vc<T> B(len(I));
FOR(i, len(I)) B[i] = A[I[i]];
return B;
}
template <typename T, typename... Vectors>
void concat(vc<T> &first, const Vectors &... others) {
vc<T> &res = first;
(res.insert(res.end(), others.begin(), others.end()), ...);
}
#endif
#line 1 "/home/maspy/compro/library/other/io.hpp"
#define FASTIO
#include <unistd.h>
// https://judge.yosupo.jp/submission/21623
namespace fastio {
static constexpr uint32_t SZ = 1 << 17;
char ibuf[SZ];
char obuf[SZ];
char out[100];
// pointer of ibuf, obuf
uint32_t pil = 0, pir = 0, por = 0;
struct Pre {
char num[10000][4];
constexpr Pre() : num() {
for (int i = 0; i < 10000; i++) {
int n = i;
for (int j = 3; j >= 0; j--) {
num[i][j] = n % 10 | '0';
n /= 10;
}
}
}
} constexpr pre;
inline void load() {
memcpy(ibuf, ibuf + pil, pir - pil);
pir = pir - pil + fread(ibuf + pir - pil, 1, SZ - pir + pil, stdin);
pil = 0;
if (pir < SZ) ibuf[pir++] = '\n';
}
inline void flush() {
fwrite(obuf, 1, por, stdout);
por = 0;
}
void rd(char &c) {
do {
if (pil + 1 > pir) load();
c = ibuf[pil++];
} while (isspace(c));
}
void rd(string &x) {
x.clear();
char c;
do {
if (pil + 1 > pir) load();
c = ibuf[pil++];
} while (isspace(c));
do {
x += c;
if (pil == pir) load();
c = ibuf[pil++];
} while (!isspace(c));
}
template <typename T>
void rd_real(T &x) {
string s;
rd(s);
x = stod(s);
}
template <typename T>
void rd_integer(T &x) {
if (pil + 100 > pir) load();
char c;
do
c = ibuf[pil++];
while (c < '-');
bool minus = 0;
if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
if (c == '-') { minus = 1, c = ibuf[pil++]; }
}
x = 0;
while ('0' <= c) { x = x * 10 + (c & 15), c = ibuf[pil++]; }
if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
if (minus) x = -x;
}
}
void rd(int &x) { rd_integer(x); }
void rd(ll &x) { rd_integer(x); }
void rd(i128 &x) { rd_integer(x); }
void rd(u32 &x) { rd_integer(x); }
void rd(u64 &x) { rd_integer(x); }
void rd(u128 &x) { rd_integer(x); }
void rd(double &x) { rd_real(x); }
void rd(long double &x) { rd_real(x); }
void rd(f128 &x) { rd_real(x); }
template <class T, class U>
void rd(pair<T, U> &p) {
return rd(p.first), rd(p.second);
}
template <size_t N = 0, typename T>
void rd_tuple(T &t) {
if constexpr (N < std::tuple_size<T>::value) {
auto &x = std::get<N>(t);
rd(x);
rd_tuple<N + 1>(t);
}
}
template <class... T>
void rd(tuple<T...> &tpl) {
rd_tuple(tpl);
}
template <size_t N = 0, typename T>
void rd(array<T, N> &x) {
for (auto &d: x) rd(d);
}
template <class T>
void rd(vc<T> &x) {
for (auto &d: x) rd(d);
}
void read() {}
template <class H, class... T>
void read(H &h, T &... t) {
rd(h), read(t...);
}
void wt(const char c) {
if (por == SZ) flush();
obuf[por++] = c;
}
void wt(const string s) {
for (char c: s) wt(c);
}
void wt(const char *s) {
size_t len = strlen(s);
for (size_t i = 0; i < len; i++) wt(s[i]);
}
template <typename T>
void wt_integer(T x) {
if (por > SZ - 100) flush();
if (x < 0) { obuf[por++] = '-', x = -x; }
int outi;
for (outi = 96; x >= 10000; outi -= 4) {
memcpy(out + outi, pre.num[x % 10000], 4);
x /= 10000;
}
if (x >= 1000) {
memcpy(obuf + por, pre.num[x], 4);
por += 4;
} else if (x >= 100) {
memcpy(obuf + por, pre.num[x] + 1, 3);
por += 3;
} else if (x >= 10) {
int q = (x * 103) >> 10;
obuf[por] = q | '0';
obuf[por + 1] = (x - q * 10) | '0';
por += 2;
} else
obuf[por++] = x | '0';
memcpy(obuf + por, out + outi + 4, 96 - outi);
por += 96 - outi;
}
template <typename T>
void wt_real(T x) {
ostringstream oss;
oss << fixed << setprecision(15) << double(x);
string s = oss.str();
wt(s);
}
void wt(int x) { wt_integer(x); }
void wt(ll x) { wt_integer(x); }
void wt(i128 x) { wt_integer(x); }
void wt(u32 x) { wt_integer(x); }
void wt(u64 x) { wt_integer(x); }
void wt(u128 x) { wt_integer(x); }
void wt(double x) { wt_real(x); }
void wt(long double x) { wt_real(x); }
void wt(f128 x) { wt_real(x); }
template <class T, class U>
void wt(const pair<T, U> val) {
wt(val.first);
wt(' ');
wt(val.second);
}
template <size_t N = 0, typename T>
void wt_tuple(const T t) {
if constexpr (N < std::tuple_size<T>::value) {
if constexpr (N > 0) { wt(' '); }
const auto x = std::get<N>(t);
wt(x);
wt_tuple<N + 1>(t);
}
}
template <class... T>
void wt(tuple<T...> tpl) {
wt_tuple(tpl);
}
template <class T, size_t S>
void wt(const array<T, S> val) {
auto n = val.size();
for (size_t i = 0; i < n; i++) {
if (i) wt(' ');
wt(val[i]);
}
}
template <class T>
void wt(const vector<T> val) {
auto n = val.size();
for (size_t i = 0; i < n; i++) {
if (i) wt(' ');
wt(val[i]);
}
}
void print() { wt('\n'); }
template <class Head, class... Tail>
void print(Head &&head, Tail &&... tail) {
wt(head);
if (sizeof...(Tail)) wt(' ');
print(forward<Tail>(tail)...);
}
// gcc expansion. called automaticall after main.
void __attribute__((destructor)) _d() { flush(); }
} // namespace fastio
using fastio::read;
using fastio::print;
using fastio::flush;
#if defined(LOCAL)
#define SHOW(...) SHOW_IMPL(__VA_ARGS__, SHOW6, SHOW5, SHOW4, SHOW3, SHOW2, SHOW1)(__VA_ARGS__)
#define SHOW_IMPL(_1, _2, _3, _4, _5, _6, NAME, ...) NAME
#define SHOW1(x) print(#x, "=", (x)), flush()
#define SHOW2(x, y) print(#x, "=", (x), #y, "=", (y)), flush()
#define SHOW3(x, y, z) print(#x, "=", (x), #y, "=", (y), #z, "=", (z)), flush()
#define SHOW4(x, y, z, w) print(#x, "=", (x), #y, "=", (y), #z, "=", (z), #w, "=", (w)), flush()
#define SHOW5(x, y, z, w, v) print(#x, "=", (x), #y, "=", (y), #z, "=", (z), #w, "=", (w), #v, "=", (v)), flush()
#define SHOW6(x, y, z, w, v, u) print(#x, "=", (x), #y, "=", (y), #z, "=", (z), #w, "=", (w), #v, "=", (v), #u, "=", (u)), flush()
#else
#define SHOW(...)
#endif
#define INT(...) \
int __VA_ARGS__; \
read(__VA_ARGS__)
#define LL(...) \
ll __VA_ARGS__; \
read(__VA_ARGS__)
#define U32(...) \
u32 __VA_ARGS__; \
read(__VA_ARGS__)
#define U64(...) \
u64 __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); }
void YA(bool t = 1) { print(t ? "YA" : "TIDAK"); }
void TIDAK(bool t = 1) { YES(!t); }
#line 2 "/home/maspy/compro/library/ds/fastset.hpp"
// 64-ary tree
// space: (N/63) * u64
struct FastSet {
static constexpr u32 B = 64;
int n, log;
vvc<u64> seg;
FastSet() {}
FastSet(int n) { build(n); }
int size() { return n; }
template <typename F>
FastSet(int n, F f) {
build(n, f);
}
void build(int m) {
seg.clear();
n = m;
do {
seg.push_back(vc<u64>((m + B - 1) / B));
m = (m + B - 1) / B;
} while (m > 1);
log = len(seg);
}
template <typename F>
void build(int n, F f) {
build(n);
FOR(i, n) { seg[0][i / B] |= u64(f(i)) << (i % B); }
FOR(h, log - 1) {
FOR(i, len(seg[h])) { seg[h + 1][i / B] |= u64(bool(seg[h][i])) << (i % B); }
}
}
bool operator[](int i) const { return seg[0][i / B] >> (i % B) & 1; }
void insert(int i) {
assert(0 <= i && i < n);
for (int h = 0; h < log; h++) { seg[h][i / B] |= u64(1) << (i % B), i /= B; }
}
void add(int i) { insert(i); }
void erase(int i) {
assert(0 <= i && i < n);
u64 x = 0;
for (int h = 0; h < log; h++) {
seg[h][i / B] &= ~(u64(1) << (i % B));
seg[h][i / B] |= x << (i % B);
x = bool(seg[h][i / B]);
i /= B;
}
}
void remove(int i) { erase(i); }
// min[x,n) or n
int next(int i) {
assert(i <= n);
chmax(i, 0);
for (int h = 0; h < log; h++) {
if (i / B == seg[h].size()) break;
u64 d = seg[h][i / B] >> (i % B);
if (!d) {
i = i / B + 1;
continue;
}
i += lowbit(d);
for (int g = h - 1; g >= 0; g--) {
i *= B;
i += lowbit(seg[g][i / B]);
}
return i;
}
return n;
}
// max [0,x], or -1
int prev(int i) {
assert(i >= -1);
if (i >= n) i = n - 1;
for (int h = 0; h < log; h++) {
if (i == -1) break;
u64 d = seg[h][i / B] << (63 - i % B);
if (!d) {
i = i / B - 1;
continue;
}
i -= __builtin_clzll(d);
for (int g = h - 1; g >= 0; g--) {
i *= B;
i += topbit(seg[g][i / B]);
}
return i;
}
return -1;
}
bool any(int l, int r) { return next(l) < r; }
// [l, r)
template <typename F>
void enumerate(int l, int r, F f) {
for (int x = next(l); x < r; x = next(x + 1)) f(x);
}
string to_string() {
string s(n, '?');
for (int i = 0; i < n; ++i) s[i] = ((*this)[i] ? '1' : '0');
return s;
}
};
#line 2 "/home/maspy/compro/library/ds/segtree/segtree.hpp"
template <class Monoid>
struct SegTree {
using MX = Monoid;
using X = typename MX::value_type;
using value_type = X;
vc<X> dat;
int n, log, size;
SegTree() {}
SegTree(int n) { build(n); }
template <typename F>
SegTree(int n, F f) {
build(n, f);
}
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());
FOR(i, n) dat[size + i] = f(i);
FOR_R(i, 1, size) update(i);
}
X get(int i) { return dat[size + i]; }
vc<X> get_all() { return {dat.begin() + size, dat.begin() + size + n}; }
void update(int i) { dat[i] = Monoid::op(dat[2 * i], dat[2 * i + 1]); }
void set(int i, const X& x) {
assert(i < n);
dat[i += size] = x;
while (i >>= 1) update(i);
}
void multiply(int i, const X& x) {
assert(i < n);
i += size;
dat[i] = Monoid::op(dat[i], x);
while (i >>= 1) update(i);
}
X prod(int L, int R) {
assert(0 <= L && L <= R && R <= n);
X vl = Monoid::unit(), vr = Monoid::unit();
L += size, R += size;
while (L < R) {
if (L & 1) vl = Monoid::op(vl, dat[L++]);
if (R & 1) vr = Monoid::op(dat[--R], vr);
L >>= 1, R >>= 1;
}
return Monoid::op(vl, vr);
}
X prod_all() { return dat[1]; }
template <class F>
int max_right(F check, int L) {
assert(0 <= L && L <= n && check(Monoid::unit()));
if (L == n) return n;
L += size;
X sm = Monoid::unit();
do {
while (L % 2 == 0) L >>= 1;
if (!check(Monoid::op(sm, dat[L]))) {
while (L < size) {
L = 2 * L;
if (check(Monoid::op(sm, dat[L]))) { sm = Monoid::op(sm, dat[L++]); }
}
return L - size;
}
sm = Monoid::op(sm, dat[L++]);
} while ((L & -L) != L);
return n;
}
template <class F>
int min_left(F check, int R) {
assert(0 <= R && R <= n && check(Monoid::unit()));
if (R == 0) return 0;
R += size;
X sm = Monoid::unit();
do {
--R;
while (R > 1 && (R % 2)) R >>= 1;
if (!check(Monoid::op(dat[R], sm))) {
while (R < size) {
R = 2 * R + 1;
if (check(Monoid::op(dat[R], sm))) { sm = Monoid::op(dat[R--], sm); }
}
return R + 1 - size;
}
sm = Monoid::op(dat[R], sm);
} while ((R & -R) != R);
return 0;
}
// prod_{l<=i<r} A[i xor x]
X xor_prod(int l, int r, int xor_val) {
static_assert(Monoid::commute);
X x = Monoid::unit();
for (int k = 0; k < log + 1; ++k) {
if (l >= r) break;
if (l & 1) { x = Monoid::op(x, dat[(size >> k) + ((l++) ^ xor_val)]); }
if (r & 1) { x = Monoid::op(x, dat[(size >> k) + ((--r) ^ xor_val)]); }
l /= 2, r /= 2, xor_val /= 2;
}
return x;
}
};
#line 2 "/home/maspy/compro/library/alg/monoid/min_idx.hpp"
template <typename T, bool tie_is_left = true>
struct Monoid_Min_Idx {
using value_type = pair<T, int>;
using X = value_type;
static constexpr bool is_small(const X& x, const X& y) {
if (x.fi < y.fi) return true;
if (x.fi > y.fi) return false;
return (tie_is_left ? (x.se < y.se) : (x.se >= y.se));
}
static X op(X x, X y) { return (is_small(x, y) ? x : y); }
static constexpr X unit() { return {infty<T>, -1}; }
static constexpr bool commute = true;
};
#line 6 "main.cpp"
pair<ll, vc<int>> solve_01(vc<int> A, vc<int> X) {
// 0,1を割り当てる
// 違う色だと減点で減点を最小に
// 1の右上に0があると矛盾
// カットをフローにすると、右上の0と左下の1で最大マッチングということ
// これは求まるが、そのときのカットを復元すればよい
int N = len(A);
vc<int> match(N, -1);
FastSet F(N);
vc<int> AtoI(N);
FOR(i, N) AtoI[A[i]] = i;
int ans = 0;
FOR(i, N) {
if (X[i] == 1) {
F.insert(A[i]);
continue;
}
int b = F.prev(A[i]);
if (b == -1) continue;
int j = AtoI[b];
match[i] = j, match[j] = i, F.erase(b), ++ans;
}
vc<int> vis(N);
SegTree<Monoid_Min_Idx<int>> seg(N, [&](int i) -> pair<int, int> {
if (X[i] == 0) return {infty<int>, -1};
return {A[i], i};
});
auto set_used = [&](int v) -> void {
vis[v] = 1;
if (X[v] == 1) seg.set(v, {infty<int>, -1});
};
auto dfs = [&](auto& dfs, int v) -> void {
if (X[v] == 1) {
int w = match[v];
if (w == -1 || vis[w]) return;
set_used(w), dfs(dfs, w);
return;
}
int p = match[v];
if (p != -1) {
while (1) {
auto [mi, idx] = seg.prod(0, p);
if (mi >= A[v]) break;
SHOW(v, idx);
set_used(idx), dfs(dfs, idx);
}
}
while (1) {
auto [mi, idx] = seg.prod(p + 1, v);
SHOW(mi, idx);
if (mi >= A[v]) break;
SHOW(v, idx);
set_used(idx), dfs(dfs, idx);
}
};
FOR(v, N) {
if (X[v] == 0 && match[v] == -1 && !vis[v]) {
SHOW(v);
set_used(v), dfs(dfs, v);
}
}
for (auto& x: vis) x ^= 1;
SHOW(A, X, ans, match, vis);
return {ans, vis};
}
// x=L...R-1 について cut value ([-infty,x),[x,infty)) を足す
ll dfs(vc<int> A, vc<int> X, ll L, ll R) {
if (L == R) return 0;
ll N = len(A);
if (N == 0) return 0;
{
vc<int> I = argsort(A);
A = argsort(I);
}
ll M = (L + R) / 2;
// 0<=A<N
vc<int> xx(N);
FOR(i, N) xx[i] = (X[i] < M ? 0 : 1);
auto [ANS, color] = solve_01(A, xx);
if (R - L == 1) return ANS;
vc<int> A0, A1, X0, X1;
FOR(i, N) {
if (color[i] == 0) {
// FOR(j, M + 1, R) { ANS += (X[i] >= j); }
ANS += max<ll>(0, min<ll>(R - M - 1, X[i] - M));
A0.eb(A[i]), X0.eb(X[i]);
}
if (color[i] == 1) {
// FOR(j, L, M) { ANS += (X[i] < j); }
ANS += max<ll>(0, min<ll>(M - L, M - X[i] - 1));
A1.eb(A[i]), X1.eb(X[i]);
}
}
SHOW(A, X, M, color, ANS);
ANS += dfs(A0, X0, L, M);
ANS += dfs(A1, X1, M + 1, R);
return ANS;
}
void solve() {
LL(N);
vc<int> A(N), B(N), C(N);
FOR(i, N) { read(A[i], B[i], C[i]); }
{
vc<int> I(N);
FOR(i, N) I[i] = i;
sort(all(I), [&](auto& L, auto& R) -> bool {
if (A[L] != A[R]) return A[L] < A[R];
return B[L] < B[R];
});
A = rearrange(A, I);
B = rearrange(B, I);
C = rearrange(C, I);
I = argsort(B);
B = argsort(I);
int mx = MAX(C);
for (auto& c: C) c = mx - c;
}
ll ANS = dfs(B, C, 0, MAX(C) + 1);
print(ANS);
}
signed main() { solve(); }
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3720kb
input:
5 1 3 5 3 2 1 3 3 3 4 4 1 3 5 4
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3980kb
input:
1 1 1 58383964
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3704kb
input:
2 1 1 204909414 2 2 807091086
output:
602181672
result:
ok 1 number(s): "602181672"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3800kb
input:
4 2 4 107744934 3 2 143843719 4 4 908851567 2 2 307161330
output:
801106633
result:
ok 1 number(s): "801106633"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3704kb
input:
7 1 2 140766572 5 3 795389698 3 6 279722536 2 6 442413348 4 2 475716910 5 4 704493410 5 2 423494885
output:
935621651
result:
ok 1 number(s): "935621651"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3816kb
input:
11 1 5 104443431 4 9 692130290 4 1 18812720 7 3 381505729 7 7 706418558 11 9 242808397 10 4 490383412 3 2 72839501 10 7 883914647 10 6 738589165 11 10 556539693
output:
2757182575
result:
ok 1 number(s): "2757182575"
Test #7:
score: 0
Accepted
time: 1ms
memory: 4024kb
input:
17 14 13 957289906 14 1 220840920 10 3 230060608 9 12 405076666 13 5 112827045 12 12 925699151 11 9 243364659 3 15 66125969 1 5 481618704 17 11 67207393 9 4 141885319 2 2 641760683 4 6 30421350 5 9 145177348 7 13 468875688 11 7 557989385 13 17 468110036
output:
3056543193
result:
ok 1 number(s): "3056543193"
Test #8:
score: 0
Accepted
time: 1ms
memory: 4012kb
input:
26 22 1 655039096 18 3 405980640 11 23 310084709 17 6 5210226 6 25 869210460 14 23 9079903 17 9 162692938 21 1 703337421 13 8 216969244 8 23 242760842 11 9 876472951 5 15 545320494 8 6 764694540 4 12 164086724 6 13 394175551 10 1 906738317 26 25 224731347 12 14 967318812 26 14 449256484 23 4 6152281...
output:
3872286425
result:
ok 1 number(s): "3872286425"
Test #9:
score: 0
Accepted
time: 1ms
memory: 3968kb
input:
40 33 19 974202889 40 11 262863105 18 17 143706322 15 37 253303786 4 8 962133788 40 22 885916470 22 19 949122323 32 29 221627390 17 24 605257795 3 14 259799950 5 3 987951246 28 30 451968921 13 17 503334855 11 26 190979064 11 13 497711531 29 4 764544900 38 16 199461325 7 9 618831071 25 30 209848351 1...
output:
7657769074
result:
ok 1 number(s): "7657769074"
Test #10:
score: 0
Accepted
time: 1ms
memory: 3792kb
input:
61 6 25 772410634 9 47 581631393 40 34 565465748 8 55 154525415 3 50 298013089 16 23 593130934 26 5 721815207 42 43 28712243 61 21 539501497 49 53 283028482 4 20 267467572 59 45 55599983 26 3 218043086 15 8 213292621 37 44 119318590 29 33 445273185 37 3 734748198 21 56 178476345 12 40 897802983 3 29...
output:
9305689053
result:
ok 1 number(s): "9305689053"
Test #11:
score: 0
Accepted
time: 1ms
memory: 4052kb
input:
92 67 63 115551817 40 57 922062274 21 83 268857323 59 65 957783695 44 1 720871230 44 65 682393003 85 21 850933251 47 32 990892557 75 90 807656030 37 83 446279042 6 8 121301986 52 34 648749799 29 56 519610045 58 28 915936953 19 8 736754508 77 25 251573087 77 5 708764858 71 66 395892865 37 9 339525762...
output:
20584500053
result:
ok 1 number(s): "20584500053"
Test #12:
score: 0
Accepted
time: 1ms
memory: 3932kb
input:
139 34 89 106739274 76 37 623575790 96 95 241595468 100 37 24819785 67 78 157943133 86 66 173514198 6 107 220712008 95 94 902234730 124 117 827871287 82 10 199132415 48 29 821720496 99 15 21336498 79 84 287004315 27 57 112113016 102 106 99696275 52 94 326387056 17 41 717541828 24 119 561086579 137 1...
output:
34223480997
result:
ok 1 number(s): "34223480997"
Test #13:
score: 0
Accepted
time: 1ms
memory: 3876kb
input:
209 202 11 985436507 81 23 303372005 58 65 271936110 105 6 780231383 183 131 67052291 140 15 742761772 92 31 934033938 172 97 238586287 77 191 267962930 199 10 970201899 2 150 211701369 35 162 119938268 195 197 567498864 62 159 198698620 17 110 472437657 202 179 121800271 115 135 70371572 111 62 443...
output:
49909325408
result:
ok 1 number(s): "49909325408"
Test #14:
score: 0
Accepted
time: 1ms
memory: 3904kb
input:
314 26 307 692391292 279 111 226570582 290 76 261494858 132 47 708283863 253 177 82612833 32 26 881275895 248 213 349235000 240 136 227630771 133 208 894493845 295 174 760101024 191 182 333036912 309 205 326571720 138 220 582371900 185 262 33941275 113 151 91998856 194 51 532523590 219 174 90194801 ...
output:
73980124774
result:
ok 1 number(s): "73980124774"
Test #15:
score: 0
Accepted
time: 2ms
memory: 3856kb
input:
472 215 64 888756595 191 437 782953525 284 151 807803141 142 382 737321722 200 373 933468526 387 190 414005694 137 464 157330847 240 55 838395267 262 74 996210474 428 42 179226852 364 446 789614149 177 66 882599216 6 278 229756157 22 325 676675321 231 131 811796299 335 86 632795653 184 433 454696152...
output:
115815454982
result:
ok 1 number(s): "115815454982"
Test #16:
score: 0
Accepted
time: 3ms
memory: 4012kb
input:
709 507 296 959229221 564 579 785837067 165 238 854583076 195 550 409079670 134 411 35472127 581 210 191747703 170 161 804804474 111 106 442762676 488 333 310679628 69 505 273768286 120 85 205745581 652 565 468876379 30 165 512567322 236 654 568944218 572 116 598480208 448 537 315385253 590 374 4940...
output:
176997131937
result:
ok 1 number(s): "176997131937"
Test #17:
score: 0
Accepted
time: 4ms
memory: 4040kb
input:
1064 1011 964 184314429 821 627 456155208 732 497 56527680 179 168 52071168 836 1005 604045343 19 401 439301716 818 500 303713286 970 268 24075641 888 744 839729821 101 97 726134962 942 260 735986500 143 436 241015562 668 910 391605524 634 635 160559352 205 50 612020502 20 360 696670729 175 575 2551...
output:
266930542461
result:
ok 1 number(s): "266930542461"
Test #18:
score: 0
Accepted
time: 6ms
memory: 4240kb
input:
1597 639 1393 166904194 1326 984 426206306 443 1524 935852282 848 1091 771776465 760 898 864783022 1379 372 38647886 481 603 346594658 521 122 293597610 1441 1589 133798182 1185 1272 279881925 544 666 231802145 1081 429 975793623 802 720 31278767 918 535 992962940 528 706 915212950 520 505 309874112...
output:
405559254752
result:
ok 1 number(s): "405559254752"
Test #19:
score: 0
Accepted
time: 13ms
memory: 4808kb
input:
2396 1981 1533 298355427 97 1737 959008541 787 1377 213392751 471 1 315600441 1995 1605 255228530 1813 309 900206470 463 536 734537574 730 2056 946098919 42 535 656307145 213 2365 598200890 582 105 100509217 1413 1740 655194157 1152 17 689800494 2106 1978 135105427 1252 999 617607068 1044 612 802184...
output:
597231143545
result:
ok 1 number(s): "597231143545"
Test #20:
score: 0
Accepted
time: 16ms
memory: 4664kb
input:
3595 1226 458 449847735 3424 1750 313050010 3169 2627 640096567 162 1184 906369956 1422 1015 293642622 340 2940 990712500 1026 1217 841244511 388 3004 899853656 896 669 146375886 2674 2297 111706208 3201 1696 323055839 351 1670 182429627 1633 511 12020195 2001 3285 41275714 248 1703 219345489 1759 1...
output:
899911898812
result:
ok 1 number(s): "899911898812"
Test #21:
score: 0
Accepted
time: 29ms
memory: 5080kb
input:
5393 2093 1287 583196596 2605 4403 533046343 3917 285 235297421 4318 4681 411844255 1588 1842 648962599 2164 2375 680797189 217 3854 531509369 4606 3646 354560797 4059 1754 976303595 1979 2652 265487574 4518 3955 157233712 2220 3416 107520029 1693 4855 722727994 4784 4162 245866252 498 1215 20109583...
output:
1349936604836
result:
ok 1 number(s): "1349936604836"
Test #22:
score: 0
Accepted
time: 46ms
memory: 6488kb
input:
8090 4866 7478 356775584 2504 3192 239406790 7743 2941 65392868 5615 1820 337863138 7340 4815 69744983 6191 1229 587983387 7729 3212 685050434 4313 5380 999113456 6515 5715 447059187 2429 7934 458547204 3870 7822 238996790 2286 3953 479733208 2620 3563 480862876 1111 6631 522438482 7956 2469 1939648...
output:
2064278617120
result:
ok 1 number(s): "2064278617120"
Test #23:
score: 0
Accepted
time: 77ms
memory: 9304kb
input:
12136 9194 7715 385468038 10307 6421 156181299 2779 9831 370946156 5449 7750 978449190 1276 844 367495644 1009 11917 41206130 4623 821 884083711 7802 3252 270221800 11699 9720 67880248 905 7498 882641163 846 10014 591139488 6648 1671 688996597 4295 12118 207178901 4320 10134 122002645 3686 10730 854...
output:
3119930013408
result:
ok 1 number(s): "3119930013408"
Test #24:
score: 0
Accepted
time: 115ms
memory: 10688kb
input:
18205 15502 9773 287504909 99 3826 342956061 5281 2167 882347909 11920 6288 432122804 12016 16973 61123860 5295 1207 911757865 14111 7883 777996097 1347 9620 363217200 660 15969 710395355 13065 15291 668428361 11892 17197 764778250 5172 9857 283025751 10253 11454 797309399 854 16916 387603881 4046 9...
output:
4646485106348
result:
ok 1 number(s): "4646485106348"
Test #25:
score: 0
Accepted
time: 182ms
memory: 12432kb
input:
27308 24579 3661 862768022 5266 18066 445716653 23679 2988 969489642 19312 17314 795242288 4196 16999 888385325 4082 25785 490546658 20278 6999 217961913 23575 3413 63174645 23253 26512 938455547 11715 7880 24996012 12751 25040 156918854 10141 15211 698329456 21632 8801 287594181 8346 4485 864856860...
output:
6953369240363
result:
ok 1 number(s): "6953369240363"
Test #26:
score: 0
Accepted
time: 287ms
memory: 19888kb
input:
40963 32397 21728 665533394 14092 25532 885841420 6996 13499 541070446 10132 14170 968034413 34862 23452 27553808 4384 18087 951007362 40193 36533 876771802 21939 255 835996912 14813 34602 396870817 23518 12878 121167193 24674 35802 634701100 30982 21854 872559058 37114 1857 748537081 14651 28035 78...
output:
10475585732428
result:
ok 1 number(s): "10475585732428"
Test #27:
score: 0
Accepted
time: 433ms
memory: 21744kb
input:
61445 36697 25963 94951597 7513 24837 819005409 854 59947 670876395 53706 28155 500385795 21808 12434 384290319 22180 9978 226530813 24817 39062 431206958 29985 44370 903111841 33782 7850 744209998 40702 37285 53291120 25414 271 438279520 4742 2959 465420139 4122 48945 880775407 42032 3922 82058901 ...
output:
15678557202606
result:
ok 1 number(s): "15678557202606"
Test #28:
score: 0
Accepted
time: 672ms
memory: 50008kb
input:
92168 56230 42965 742064775 4877 45898 159393199 59960 15737 139858988 83885 3886 29974986 7528 23740 133054240 42731 67896 795632101 65960 85613 760855118 22584 18115 872879663 74322 5174 466635717 16877 65430 512235721 42196 12741 698697046 13205 45782 999285629 9991 85074 537703269 11324 57987 99...
output:
23527389016280
result:
ok 1 number(s): "23527389016280"
Test #29:
score: 0
Accepted
time: 1134ms
memory: 52056kb
input:
138253 137028 98027 420176109 80718 126363 925205029 6738 78045 403027262 61401 88129 15744684 23837 119097 640220864 15996 46921 935267867 55975 15608 132891604 113324 22647 47973513 6441 33699 644316078 25548 66322 765816467 122863 55030 252850483 98023 67850 575671984 60006 91757 240693176 74046 ...
output:
35424061451157
result:
ok 1 number(s): "35424061451157"
Test #30:
score: 0
Accepted
time: 1022ms
memory: 56512kb
input:
131071 90672 123987 228449234 3604 102308 987422594 59810 25149 860613161 104850 269 689330493 24993 101682 976691697 78019 43297 520816902 71433 76386 821164796 5909 77441 120378040 45000 43490 35922905 17468 78999 878299743 1241 113223 90941807 110893 103555 180500551 91339 77238 493814644 13139 5...
output:
33473411344075
result:
ok 1 number(s): "33473411344075"
Test #31:
score: 0
Accepted
time: 1033ms
memory: 43700kb
input:
131072 61466 60099 43713848 4432 107280 858182963 105411 3399 116715084 97176 123606 720509750 25188 78189 197911350 63294 23532 650834189 29931 114646 773415808 83011 103448 15006743 36024 52158 574964066 104377 4278 481207906 98234 14071 880195643 95198 110017 473546968 90133 59609 136208461 322 5...
output:
33464721182174
result:
ok 1 number(s): "33464721182174"
Test #32:
score: 0
Accepted
time: 1083ms
memory: 61944kb
input:
131073 45917 103829 958666723 94319 91112 870672821 76150 4477 607817071 116729 95377 688420221 63089 57400 798542306 96986 104154 423949112 122218 10852 946616129 82316 122347 621862025 76160 94630 657810973 128606 83099 974721993 36605 86452 897502490 47480 70841 125116337 126918 109172 170092230 ...
output:
33570691146219
result:
ok 1 number(s): "33570691146219"
Test #33:
score: 0
Accepted
time: 1659ms
memory: 83432kb
input:
199995 15467 44256 880189728 11879 82576 277886095 88467 171050 502781139 34306 134775 937105286 128255 122988 6045953 191726 128000 120294449 184032 174614 229445343 39848 120710 778565003 164709 140201 284867637 170121 23229 628225839 83381 194905 423440701 105958 129062 548268870 157416 169550 53...
output:
51069618351288
result:
ok 1 number(s): "51069618351288"
Test #34:
score: 0
Accepted
time: 1793ms
memory: 112604kb
input:
199996 188022 175146 435109837 39484 18941 140354330 187252 68697 197359292 140669 100199 239571071 33378 157983 659846919 98775 148000 461407329 183074 161683 120451896 174079 107192 640918162 14142 142382 77946963 153761 156103 679585394 64357 34527 883645388 109018 133416 10586375 47249 119730 24...
output:
51185777204840
result:
ok 1 number(s): "51185777204840"
Test #35:
score: 0
Accepted
time: 1654ms
memory: 76836kb
input:
199997 73516 19739 838723435 38402 99472 365024663 187720 163332 931156594 56035 23471 580502230 49038 141873 429779646 8373 33192 396621510 68459 156696 6650869 166766 98968 254901248 181072 29231 47536080 54302 118076 773441482 66958 11176 846380382 152996 46474 8222134 7962 143671 451843263 73692...
output:
51290453888715
result:
ok 1 number(s): "51290453888715"
Test #36:
score: 0
Accepted
time: 1676ms
memory: 73920kb
input:
199998 190213 150886 166429875 135067 169295 920168970 14759 108153 278613035 34650 71509 216938350 40124 175509 223806600 177470 80553 613251251 112961 160689 560174209 199764 23352 272323852 49788 119514 140779902 65354 161950 227806555 122949 3774 996466001 38293 125522 96151161 187758 37169 9289...
output:
51151696245074
result:
ok 1 number(s): "51151696245074"
Test #37:
score: 0
Accepted
time: 1684ms
memory: 74412kb
input:
199999 50070 37886 219662346 189360 149197 851580760 22803 24921 55886162 34597 66728 448499354 129241 45304 858815568 79315 77886 941776779 184463 48502 842324713 126429 153105 303195651 15965 159721 739003078 163463 165170 474932148 173069 168053 538878285 127254 115886 829462341 58964 148360 9015...
output:
51134677983253
result:
ok 1 number(s): "51134677983253"
Test #38:
score: 0
Accepted
time: 1673ms
memory: 76140kb
input:
200000 3053 48451 852024905 130801 35304 406221494 155083 22092 637456588 27810 112924 897277150 186503 124280 165552724 1050 149205 721877548 84582 76769 721109700 36679 17354 915239240 8176 167598 89917290 66925 9658 537126621 114134 179363 318957046 140274 139241 256813774 89367 43733 432309120 1...
output:
51181746963331
result:
ok 1 number(s): "51181746963331"
Test #39:
score: 0
Accepted
time: 1661ms
memory: 62780kb
input:
200000 18032 42637 994004831 107687 93151 1 146380 46394 999999974 19029 102809 968135491 144277 176499 3 29371 27209 972804372 126179 37298 999675260 105313 136862 396494 187401 34864 999988675 9509 61833 999999678 28123 123134 998640738 27570 2355 999999982 123391 159656 20293624 134993 1821 39 67...
output:
94638840715200
result:
ok 1 number(s): "94638840715200"
Test #40:
score: 0
Accepted
time: 1548ms
memory: 85420kb
input:
199938 157289 79441 999999885 7274 59644 917 128813 125238 10018200 130060 16106 669933 82766 154952 1 136698 192241 999756229 116687 138602 958437703 190047 85657 999999514 181372 135008 28 188618 130954 999998253 90399 126826 4169878 195034 62671 16 197222 171004 999759771 93320 65646 999991932 18...
output:
94564959018584
result:
ok 1 number(s): "94564959018584"
Test #41:
score: 0
Accepted
time: 1749ms
memory: 88556kb
input:
199809 191524 2302 999999987 26322 20497 2436769 107727 105643 424785 114452 75577 999999135 95309 187395 922785002 36623 196948 999897684 108165 30068 990732739 90159 110725 5 183727 149516 8998834 46718 150948 999986688 120472 112960 999994567 137939 177875 1175 20321 24484 996529789 195674 141463...
output:
94656882862646
result:
ok 1 number(s): "94656882862646"
Test #42:
score: 0
Accepted
time: 1692ms
memory: 66084kb
input:
199992 17491 108201 999999973 46139 170475 1098 63905 14801 217 179110 151920 53 30285 18067 999998706 96817 142860 188 47164 115510 17 23612 14964 3 30832 155065 999997277 11899 78138 999999993 74893 152921 32 3832 139360 21091 140761 192714 661572950 30965 99162 1682 136835 100239 999995588 139980...
output:
94781878312984
result:
ok 1 number(s): "94781878312984"
Test #43:
score: 0
Accepted
time: 1082ms
memory: 19484kb
input:
200000 22660 177341 3567 22018 177983 5324 158816 41185 9673 25309 174692 20312 166489 33512 22798 57756 142245 24188 73331 126670 27337 165374 34627 45497 549 199452 60469 124759 75242 62821 190829 9172 67547 84954 115047 71160 107563 92438 72178 90755 109246 81895 177334 22667 83803 116754 83247 8...
output:
0
result:
ok 1 number(s): "0"
Test #44:
score: 0
Accepted
time: 827ms
memory: 19768kb
input:
199998 18464 181536 800350907 29934 170064 678248091 89768 110232 88647223 38124 161876 590541519 90347 109653 83641788 6727 193271 927757818 15941 184057 827693561 22467 177531 758262055 58102 141896 375637093 67211 132789 281572233 94971 105027 43303372 45534 154464 510865697 12500 187498 86538531...
output:
2174338990
result:
ok 1 number(s): "2174338990"
Test #45:
score: 0
Accepted
time: 872ms
memory: 19476kb
input:
200000 1838 198162 980178988 32717 167283 648985408 16439 183563 823697651 34210 165790 632775927 22279 177721 760432627 34756 165244 626834126 94621 105381 46472626 16878 183124 819737427 17225 182775 815333031 11472 188530 876842117 65451 134549 296674941 58111 141891 376235881 60467 139535 349870...
output:
16525540505
result:
ok 1 number(s): "16525540505"
Test #46:
score: 0
Accepted
time: 799ms
memory: 20100kb
input:
199993 64300 135744 613312093 34861 165183 296582475 90699 109245 899810649 6522 193522 55837460 77837 122107 760239626 59198 140746 558383193 1944 198000 16830187 96978 103066 966989068 37678 162266 327325533 33610 166434 285740280 81403 118541 798424357 51385 148559 474432054 93948 105996 93469771...
output:
49979415209
result:
ok 1 number(s): "49979415209"
Test #47:
score: 0
Accepted
time: 611ms
memory: 20048kb
input:
199998 42354 157695 381749892 13828 186221 119483284 44492 155557 404578724 58421 141628 554928734 76777 123172 750913414 39402 160547 349695544 36671 163378 319924619 82125 117824 807826958 12010 188039 103921135 16730 183319 143998331 81343 118606 799757850 68534 131415 663157579 17404 182645 1495...
output:
50018556053
result:
ok 1 number(s): "50018556053"
Test #48:
score: 0
Accepted
time: 644ms
memory: 20344kb
input:
199997 31364 168584 662489251 16582 183466 822331606 95137 104911 42838118 86187 113861 119330597 75084 124864 214540141 63036 136912 323432421 70529 129419 253944309 26697 173251 713260701 78810 121238 182722788 54878 145070 410135506 43231 156717 534310798 92735 107313 63155678 27630 172318 703432...
output:
52679513086
result:
ok 1 number(s): "52679513086"
Test #49:
score: 0
Accepted
time: 1156ms
memory: 102240kb
input:
199998 100390 189609 89319227 4497 105502 38638787 179755 110244 890868097 105743 184256 134939289 6071 103928 52121684 2867 107132 24575689 136522 153477 426056891 31727 78272 272579877 64366 45633 618496799 58222 51777 552009537 137727 152272 438789744 99557 10442 995557880 99336 190663 80119517 8...
output:
25617117364511
result:
ok 1 number(s): "25617117364511"
Test #50:
score: 0
Accepted
time: 1229ms
memory: 99648kb
input:
199992 172473 117520 810591299 133977 156016 395428073 56079 53914 523772658 172060 117933 801910595 34259 75734 302785382 153832 136161 624261219 17274 92719 150556467 126395 163598 314991478 12467 97526 106969764 85067 24926 836136880 114837 175156 214241942 135514 154479 416066013 95139 194854 45...
output:
25535687755138
result:
ok 1 number(s): "25535687755138"
Test #51:
score: 0
Accepted
time: 1277ms
memory: 102256kb
input:
199991 12522 97470 802819319 185702 104290 807693689 63844 46148 337007309 121351 168641 471822569 94328 195664 377701210 176699 113293 700491311 108772 181220 358281626 177407 112585 384993795 113861 176131 465475385 98373 191619 238407920 123640 166352 27086055 125472 164520 397508090 159076 13091...
output:
25576769610985
result:
ok 1 number(s): "25576769610985"
Test #52:
score: 0
Accepted
time: 1006ms
memory: 19704kb
input:
199991 194665 194665 22880362 3107 3107 983488233 189522 189522 44793597 23887 23887 871439617 163629 163629 156791581 11477 11477 937697588 86990 86990 531849196 92270 92270 503372412 168009 168009 137490066 198788 198788 5246074 175535 175535 105076092 183888 183888 68982828 166686 166686 14327898...
output:
0
result:
ok 1 number(s): "0"
Test #53:
score: 0
Accepted
time: 1010ms
memory: 19908kb
input:
200000 135685 135683 276563069 133790 133789 284612517 130100 130105 301317918 90945 90944 511808733 171149 171147 123345701 11075 11072 940259703 95841 95844 485551675 168545 168544 134319316 27102 27100 852732492 88048 88047 527690142 117645 117647 368426229 51895 51894 721041650 115389 115390 380...
output:
410516055
result:
ok 1 number(s): "410516055"
Test #54:
score: 0
Accepted
time: 982ms
memory: 19624kb
input:
200000 43431 43422 767501778 162822 162819 159073703 180642 180638 83681311 52882 52891 716273308 115316 115313 380561220 33959 33953 818260578 139015 139008 261290471 125193 125194 326901624 11066 11072 940585276 132861 132861 287727280 91918 91917 505656546 123165 123168 337880389 45418 45420 7570...
output:
871556481
result:
ok 1 number(s): "871556481"
Test #55:
score: 0
Accepted
time: 935ms
memory: 19524kb
input:
199992 1947 1948 989429728 72811 72812 607675580 177705 177704 94839321 90570 90570 512512422 115355 115348 378986670 2257 2254 987723936 61763 61763 667932919 60589 60589 674281673 76190 76169 589751075 136488 136487 271814239 105744 105739 430619435 105112 105116 433904613 173529 173525 112264296 ...
output:
2433218429
result:
ok 1 number(s): "2433218429"
Test #56:
score: 0
Accepted
time: 906ms
memory: 19924kb
input:
200000 120044 120036 353819339 178031 178034 93989148 61081 61062 670074633 65652 65643 645934771 131617 131642 293337624 169491 169490 130825055 75265 75242 594261748 115686 115695 377042580 60687 60696 672067171 4371 4366 976755110 180558 180564 83100105 1288 1322 992921822 160971 160984 166773279...
output:
5342162603
result:
ok 1 number(s): "5342162603"
Test #57:
score: 0
Accepted
time: 869ms
memory: 19724kb
input:
199991 155361 155350 191272932 75669 75722 592361703 33369 33332 820315371 166526 166546 143664611 112336 112343 395418448 189368 189388 45211553 109420 109361 410848808 130658 130697 297516423 34928 34931 811835858 50123 50106 729175269 75463 75505 593615400 164689 164650 151592787 10926 10937 9416...
output:
18324347126
result:
ok 1 number(s): "18324347126"
Test #58:
score: 0
Accepted
time: 836ms
memory: 19464kb
input:
199999 69680 69673 625757853 93125 93120 499747501 90770 90799 512430591 39896 39870 786840466 26436 26440 858881536 133900 133916 282190136 75085 75072 597999442 181455 181476 77737733 63427 63561 658466554 18348 18376 902113086 76503 76476 590161029 61243 61252 671292057 47942 47994 742636237 6750...
output:
32144265081
result:
ok 1 number(s): "32144265081"
Test #59:
score: 0
Accepted
time: 820ms
memory: 19472kb
input:
199992 40685 40714 781526029 141884 142044 248993684 68324 68279 634605940 15162 15307 919325223 75234 75122 597219881 54165 54070 708814795 80029 79941 571049114 8395 8339 954797483 13209 13165 929313742 17872 18147 902721612 18386 18297 901678520 72682 72575 610550756 34378 34175 816117219 3773 35...
output:
67868880549
result:
ok 1 number(s): "67868880549"
Test #60:
score: 0
Accepted
time: 816ms
memory: 20276kb
input:
200000 180023 180288 84339695 2499 1969 988336549 182981 182853 80048977 96544 96552 483533244 108433 108590 418130408 25003 24449 869103630 26731 26866 855517626 143819 143746 244244955 172089 171364 121201733 73143 73075 608477792 195980 195564 19847429 76466 76335 589350819 172043 172103 12069883...
output:
215524315357
result:
ok 1 number(s): "215524315357"
Test #61:
score: 0
Accepted
time: 797ms
memory: 20168kb
input:
200000 140014 140272 261482551 94292 93528 490714300 82979 83102 554567359 54035 53842 708467113 16263 16329 910362578 175660 176299 103658538 19891 19639 892551970 198547 199154 6175039 132306 131497 288754216 114736 114722 384104286 187150 187015 60878276 44786 43273 759685138 15902 15611 91546568...
output:
368077087270
result:
ok 1 number(s): "368077087270"
Test #62:
score: 0
Accepted
time: 813ms
memory: 20204kb
input:
200000 159885 159042 171676772 103691 103694 442815632 127446 128998 308313621 145586 145659 254582794 78720 79743 578665874 139070 140045 258727081 92082 92952 511801919 111194 113646 388001260 95066 99233 481408960 130289 129588 309463689 102289 95008 440360586 127813 127670 314619636 29043 29753 ...
output:
899562637441
result:
ok 1 number(s): "899562637441"
Test #63:
score: 0
Accepted
time: 837ms
memory: 19340kb
input:
200000 187797 188740 42619872 198841 199180 13331015 35238 31951 804803373 6982 9286 939339043 5185 13953 908046636 94468 92656 501755787 123982 124512 356115478 189172 190662 39625458 38782 42209 767060007 104824 103503 440497060 132907 136184 273456760 131849 134980 268264950 133451 140278 2586390...
output:
2275242477924
result:
ok 1 number(s): "2275242477924"
Test #64:
score: 0
Accepted
time: 902ms
memory: 19624kb
input:
200000 94194 94419 492414878 110184 113938 371446190 103753 102211 440900739 144775 142992 324610449 92645 91647 511557741 31308 43868 788108361 78850 85969 536632698 133667 128806 274034966 79534 73500 563253949 77326 74886 590355544 33941 44574 825981303 125795 135006 290961000 12746 15524 9294274...
output:
5268091599365
result:
ok 1 number(s): "5268091599365"
Test #65:
score: 0
Accepted
time: 1239ms
memory: 19108kb
input:
200000 308 224 282795304 445 35 389420214 42 323 645335271 407 91 350043207 392 269 116686718 132 421 249808242 293 149 478300532 360 178 273321598 368 390 37842579 9 193 890698340 180 83 816209952 146 148 768743126 93 1 976498424 258 44 757594451 106 409 313955917 390 216 177953826 128 372 34589343...
output:
0
result:
ok 1 number(s): "0"
Test #66:
score: 0
Accepted
time: 1240ms
memory: 19524kb
input:
200000 286 391 100338575 164 54 874525344 131 94 865756758 99 265 646778492 192 430 158301137 163 37 893988919 55 231 783990841 71 412 381880440 427 398 8067967 145 100 841337995 253 31 786642624 92 19 967907732 401 348 43132045 320 322 135804399 154 336 366222507 209 118 715978082 434 329 34800556 ...
output:
13421471
result:
ok 1 number(s): "13421471"
Test #67:
score: 0
Accepted
time: 1177ms
memory: 19448kb
input:
199732 53 253 750457201 388 273 117965351 375 218 196659836 346 407 42311575 296 423 66589884 163 131 770265332 55 50 969992410 262 129 591870816 46 328 624921970 412 166 216938906 232 433 114325177 354 339 87467146 26 421 465363872 131 58 905229223 312 22 702748704 350 201 256941654 50 262 73851907...
output:
20862654407
result:
ok 1 number(s): "20862654407"
Test #68:
score: 0
Accepted
time: 905ms
memory: 19960kb
input:
200000 370 394 43266558 182 344 297952717 335 381 63185920 178 387 236158118 278 402 103010732 228 114 685614594 284 35 744672885 240 256 342511956 418 163 212413020 29 404 512286594 228 315 268392444 269 74 695382386 297 269 228660063 318 268 218621020 63 139 890269808 32 160 906802554 66 179 83727...
output:
769301802155
result:
ok 1 number(s): "769301802155"
Test #69:
score: 0
Accepted
time: 819ms
memory: 19944kb
input:
200000 82 66 971102008 360 19 629486782 159 433 194686548 431 190 172765548 306 302 309995870 437 111 272673175 312 140 474317642 256 239 365861259 269 134 563102942 219 203 525957213 307 101 587218237 410 375 7857727 439 416 7915983 9 409 511901245 89 82 914657232 151 262 561015022 230 239 44697772...
output:
2659848140246
result:
ok 1 number(s): "2659848140246"
Test #70:
score: 0
Accepted
time: 945ms
memory: 18964kb
input:
199495 186885 186936 53942447 63364 63428 658155180 39135 39210 787642148 38290 38195 792016750 100533 100589 457796430 14283 14293 922316851 155180 155188 190770767 118554 118595 360816427 97699 97704 473523501 158696 158737 175441634 135123 135051 276375466 78174 78191 577591602 69866 69921 622577...
output:
4761393792
result:
ok 1 number(s): "4761393792"
Test #71:
score: 0
Accepted
time: 822ms
memory: 19584kb
input:
199866 93473 93524 496784247 55074 55048 705169680 38180 38072 794526037 174541 174425 106472998 125044 124789 328231227 43103 43192 768463208 82351 82379 557404313 102000 101792 451040967 158143 158311 177865622 15776 15797 915489952 19961 19887 893497541 123706 124004 335631671 7611 7396 959311787...
output:
60917392006
result:
ok 1 number(s): "60917392006"
Test #72:
score: 0
Accepted
time: 1083ms
memory: 19388kb
input:
199579 116052 184208 378285944 40711 40197 783212350 21915 28616 883560306 161639 104097 164408961 190156 91717 41037078 125756 42985 326086513 187469 164821 53031878 106240 22639 431702168 191045 117428 37106415 188484 51199 48339078 62399 563 666236836 144670 104124 237173212 27667 18292 853170850...
output:
4661887781
result:
ok 1 number(s): "4661887781"
Test #73:
score: 0
Accepted
time: 909ms
memory: 19732kb
input:
199477 66770 52520 642353176 139117 30258 259420418 118910 130349 359433032 86741 3558 536019246 116883 47197 371846538 180404 197820 82455423 39596 102857 787513284 182954 44072 71254826 16818 67019 908753505 73293 95568 606799778 111891 166100 396464386 14097 94502 923139482 198163 35335 5310742 6...
output:
59947639798
result:
ok 1 number(s): "59947639798"
Test #74:
score: 0
Accepted
time: 878ms
memory: 19528kb
input:
199869 172973 74199 115882440 128458 33567 311657243 14484 35795 922363941 58426 5657 683983409 177824 129953 93570045 33584 142329 819343206 7196 22750 961557713 43537 121952 766065477 57145 104855 692472119 165246 169176 145874102 103333 24937 444118384 173966 163586 109592228 120854 170925 350168...
output:
190495084205
result:
ok 1 number(s): "190495084205"
Test #75:
score: 0
Accepted
time: 851ms
memory: 20368kb
input:
200000 109619 178485 408525309 81039 70890 564419579 34074 11217 811059409 44154 153326 755890900 136437 95729 269493968 50874 32196 727123567 108930 4581 411273999 35873 124303 814367865 66980 25581 634176528 127023 146948 318672492 126741 30114 314855113 183755 11674 65362133 178429 157323 8966152...
output:
660425622094
result:
ok 1 number(s): "660425622094"
Test #76:
score: 0
Accepted
time: 879ms
memory: 20328kb
input:
199936 75188 24322 599819217 34622 153449 813476409 77900 180684 579662513 69879 1507 620667708 63901 134402 648640685 129397 183159 293919317 73165 65181 593464087 47031 165893 745354488 63377 92616 648540922 138973 5710 255558859 8696 147025 951555208 146927 70492 248640935 4153 37238 967436865 60...
output:
2011806766138
result:
ok 1 number(s): "2011806766138"
Extra Test:
score: 0
Extra Test Passed