QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#639448 | #68. Designated Cities | maspy | 100 ✓ | 412ms | 75784kb | C++20 | 34.2kb | 2024-10-13 19:38:09 | 2024-10-13 19:38:11 |
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 u32 = unsigned int;
using u64 = unsigned long long;
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_mod_2(int x) { return __builtin_parity(x); }
int popcnt_mod_2(u32 x) { return __builtin_parity(x); }
int popcnt_mod_2(ll x) { return __builtin_parityll(x); }
int popcnt_mod_2(u64 x) { return __builtin_parityll(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 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); }
#line 3 "main.cpp"
#line 2 "/home/maspy/compro/library/graph/tree.hpp"
#line 2 "/home/maspy/compro/library/graph/base.hpp"
template <typename T>
struct Edge {
int frm, to;
T cost;
int id;
};
template <typename T = int, bool directed = false>
struct Graph {
static constexpr bool is_directed = directed;
int N, M;
using cost_type = T;
using edge_type = Edge<T>;
vector<edge_type> edges;
vector<int> indptr;
vector<edge_type> csr_edges;
vc<int> vc_deg, vc_indeg, vc_outdeg;
bool prepared;
class OutgoingEdges {
public:
OutgoingEdges(const Graph* G, int l, int r) : G(G), l(l), r(r) {}
const edge_type* begin() const {
if (l == r) { return 0; }
return &G->csr_edges[l];
}
const edge_type* end() const {
if (l == r) { return 0; }
return &G->csr_edges[r];
}
private:
const Graph* G;
int l, r;
};
bool is_prepared() { return prepared; }
Graph() : N(0), M(0), prepared(0) {}
Graph(int N) : N(N), M(0), prepared(0) {}
void build(int n) {
N = n, M = 0;
prepared = 0;
edges.clear();
indptr.clear();
csr_edges.clear();
vc_deg.clear();
vc_indeg.clear();
vc_outdeg.clear();
}
void add(int frm, int to, T cost = 1, int i = -1) {
assert(!prepared);
assert(0 <= frm && 0 <= to && to < N);
if (i == -1) i = M;
auto e = edge_type({frm, to, cost, i});
edges.eb(e);
++M;
}
#ifdef FASTIO
// wt, off
void read_tree(bool wt = false, int off = 1) { read_graph(N - 1, wt, off); }
void read_graph(int M, bool wt = false, int off = 1) {
for (int m = 0; m < M; ++m) {
INT(a, b);
a -= off, b -= off;
if (!wt) {
add(a, b);
} else {
T c;
read(c);
add(a, b, c);
}
}
build();
}
#endif
void build() {
assert(!prepared);
prepared = true;
indptr.assign(N + 1, 0);
for (auto&& e: edges) {
indptr[e.frm + 1]++;
if (!directed) indptr[e.to + 1]++;
}
for (int v = 0; v < N; ++v) { indptr[v + 1] += indptr[v]; }
auto counter = indptr;
csr_edges.resize(indptr.back() + 1);
for (auto&& e: edges) {
csr_edges[counter[e.frm]++] = e;
if (!directed)
csr_edges[counter[e.to]++] = edge_type({e.to, e.frm, e.cost, e.id});
}
}
OutgoingEdges operator[](int v) const {
assert(prepared);
return {this, indptr[v], indptr[v + 1]};
}
vc<int> deg_array() {
if (vc_deg.empty()) calc_deg();
return vc_deg;
}
pair<vc<int>, vc<int>> deg_array_inout() {
if (vc_indeg.empty()) calc_deg_inout();
return {vc_indeg, vc_outdeg};
}
int deg(int v) {
if (vc_deg.empty()) calc_deg();
return vc_deg[v];
}
int in_deg(int v) {
if (vc_indeg.empty()) calc_deg_inout();
return vc_indeg[v];
}
int out_deg(int v) {
if (vc_outdeg.empty()) calc_deg_inout();
return vc_outdeg[v];
}
#ifdef FASTIO
void debug() {
print("Graph");
if (!prepared) {
print("frm to cost id");
for (auto&& e: edges) print(e.frm, e.to, e.cost, e.id);
} else {
print("indptr", indptr);
print("frm to cost id");
FOR(v, N) for (auto&& e: (*this)[v]) print(e.frm, e.to, e.cost, e.id);
}
}
#endif
vc<int> new_idx;
vc<bool> used_e;
// G における頂点 V[i] が、新しいグラフで i になるようにする
// {G, es}
// sum(deg(v)) の計算量になっていて、
// 新しいグラフの n+m より大きい可能性があるので注意
Graph<T, directed> rearrange(vc<int> V, bool keep_eid = 0) {
if (len(new_idx) != N) new_idx.assign(N, -1);
int n = len(V);
FOR(i, n) new_idx[V[i]] = i;
Graph<T, directed> G(n);
vc<int> history;
FOR(i, n) {
for (auto&& e: (*this)[V[i]]) {
if (len(used_e) <= e.id) used_e.resize(e.id + 1);
if (used_e[e.id]) continue;
int a = e.frm, b = e.to;
if (new_idx[a] != -1 && new_idx[b] != -1) {
history.eb(e.id);
used_e[e.id] = 1;
int eid = (keep_eid ? e.id : -1);
G.add(new_idx[a], new_idx[b], e.cost, eid);
}
}
}
FOR(i, n) new_idx[V[i]] = -1;
for (auto&& eid: history) used_e[eid] = 0;
G.build();
return G;
}
Graph<T, true> to_directed_tree(int root = -1) {
if (root == -1) root = 0;
assert(!is_directed && prepared && M == N - 1);
Graph<T, true> G1(N);
vc<int> par(N, -1);
auto dfs = [&](auto& dfs, int v) -> void {
for (auto& e: (*this)[v]) {
if (e.to == par[v]) continue;
par[e.to] = v, dfs(dfs, e.to);
}
};
dfs(dfs, root);
for (auto& e: edges) {
int a = e.frm, b = e.to;
if (par[a] == b) swap(a, b);
assert(par[b] == a);
G1.add(a, b, e.cost);
}
G1.build();
return G1;
}
private:
void calc_deg() {
assert(vc_deg.empty());
vc_deg.resize(N);
for (auto&& e: edges) vc_deg[e.frm]++, vc_deg[e.to]++;
}
void calc_deg_inout() {
assert(vc_indeg.empty());
vc_indeg.resize(N);
vc_outdeg.resize(N);
for (auto&& e: edges) { vc_indeg[e.to]++, vc_outdeg[e.frm]++; }
}
};
#line 4 "/home/maspy/compro/library/graph/tree.hpp"
// HLD euler tour をとっていろいろ。
template <typename GT>
struct Tree {
using Graph_type = GT;
GT &G;
using WT = typename GT::cost_type;
int N;
vector<int> LID, RID, head, V, parent, VtoE;
vc<int> depth;
vc<WT> depth_weighted;
Tree(GT &G, int r = 0, bool hld = 1) : G(G) { build(r, hld); }
void build(int r = 0, bool hld = 1) {
if (r == -1) return; // build を遅延したいとき
N = G.N;
LID.assign(N, -1), RID.assign(N, -1), head.assign(N, r);
V.assign(N, -1), parent.assign(N, -1), VtoE.assign(N, -1);
depth.assign(N, -1), depth_weighted.assign(N, 0);
assert(G.is_prepared());
int t1 = 0;
dfs_sz(r, -1, hld);
dfs_hld(r, t1);
}
void dfs_sz(int v, int p, bool hld) {
auto &sz = RID;
parent[v] = p;
depth[v] = (p == -1 ? 0 : depth[p] + 1);
sz[v] = 1;
int l = G.indptr[v], r = G.indptr[v + 1];
auto &csr = G.csr_edges;
// 使う辺があれば先頭にする
for (int i = r - 2; i >= l; --i) {
if (hld && depth[csr[i + 1].to] == -1) swap(csr[i], csr[i + 1]);
}
int hld_sz = 0;
for (int i = l; i < r; ++i) {
auto e = csr[i];
if (depth[e.to] != -1) continue;
depth_weighted[e.to] = depth_weighted[v] + e.cost;
VtoE[e.to] = e.id;
dfs_sz(e.to, v, hld);
sz[v] += sz[e.to];
if (hld && chmax(hld_sz, sz[e.to]) && l < i) { swap(csr[l], csr[i]); }
}
}
void dfs_hld(int v, int ×) {
LID[v] = times++;
RID[v] += LID[v];
V[LID[v]] = v;
bool heavy = true;
for (auto &&e: G[v]) {
if (depth[e.to] <= depth[v]) continue;
head[e.to] = (heavy ? head[v] : e.to);
heavy = false;
dfs_hld(e.to, times);
}
}
vc<int> heavy_path_at(int v) {
vc<int> P = {v};
while (1) {
int a = P.back();
for (auto &&e: G[a]) {
if (e.to != parent[a] && head[e.to] == v) {
P.eb(e.to);
break;
}
}
if (P.back() == a) break;
}
return P;
}
int heavy_child(int v) {
int k = LID[v] + 1;
if (k == N) return -1;
int w = V[k];
return (parent[w] == v ? w : -1);
}
int e_to_v(int eid) {
auto e = G.edges[eid];
return (parent[e.frm] == e.to ? e.frm : e.to);
}
int v_to_e(int v) { return VtoE[v]; }
int get_eid(int u, int v) {
if (parent[u] != v) swap(u, v);
assert(parent[u] == v);
return VtoE[u];
}
int ELID(int v) { return 2 * LID[v] - depth[v]; }
int ERID(int v) { return 2 * RID[v] - depth[v] - 1; }
// 目標地点へ進む個数が k
int LA(int v, int k) {
assert(k <= depth[v]);
while (1) {
int u = head[v];
if (LID[v] - k >= LID[u]) return V[LID[v] - k];
k -= LID[v] - LID[u] + 1;
v = parent[u];
}
}
int la(int u, int v) { return LA(u, v); }
int LCA(int u, int v) {
for (;; v = parent[head[v]]) {
if (LID[u] > LID[v]) swap(u, v);
if (head[u] == head[v]) return u;
}
}
int meet(int a, int b, int c) { return LCA(a, b) ^ LCA(a, c) ^ LCA(b, c); }
int lca(int u, int v) { return LCA(u, v); }
int subtree_size(int v, int root = -1) {
if (root == -1) return RID[v] - LID[v];
if (v == root) return N;
int x = jump(v, root, 1);
if (in_subtree(v, x)) return RID[v] - LID[v];
return N - RID[x] + LID[x];
}
int dist(int a, int b) {
int c = LCA(a, b);
return depth[a] + depth[b] - 2 * depth[c];
}
WT dist_weighted(int a, int b) {
int c = LCA(a, b);
return depth_weighted[a] + depth_weighted[b] - WT(2) * depth_weighted[c];
}
// a is in b
bool in_subtree(int a, int b) { return LID[b] <= LID[a] && LID[a] < RID[b]; }
int jump(int a, int b, ll k) {
if (k == 1) {
if (a == b) return -1;
return (in_subtree(b, a) ? LA(b, depth[b] - depth[a] - 1) : parent[a]);
}
int c = LCA(a, b);
int d_ac = depth[a] - depth[c];
int d_bc = depth[b] - depth[c];
if (k > d_ac + d_bc) return -1;
if (k <= d_ac) return LA(a, k);
return LA(b, d_ac + d_bc - k);
}
vc<int> collect_child(int v) {
vc<int> res;
for (auto &&e: G[v])
if (e.to != parent[v]) res.eb(e.to);
return res;
}
vc<int> collect_light(int v) {
vc<int> res;
bool skip = true;
for (auto &&e: G[v])
if (e.to != parent[v]) {
if (!skip) res.eb(e.to);
skip = false;
}
return res;
}
vc<pair<int, int>> get_path_decomposition(int u, int v, bool edge) {
// [始点, 終点] の"閉"区間列。
vc<pair<int, int>> up, down;
while (1) {
if (head[u] == head[v]) break;
if (LID[u] < LID[v]) {
down.eb(LID[head[v]], LID[v]);
v = parent[head[v]];
} else {
up.eb(LID[u], LID[head[u]]);
u = parent[head[u]];
}
}
if (LID[u] < LID[v]) down.eb(LID[u] + edge, LID[v]);
elif (LID[v] + edge <= LID[u]) up.eb(LID[u], LID[v] + edge);
reverse(all(down));
up.insert(up.end(), all(down));
return up;
}
// 辺の列の情報 (frm,to,str)
// str = "heavy_up", "heavy_down", "light_up", "light_down"
vc<tuple<int, int, string>> get_path_decomposition_detail(int u, int v) {
vc<tuple<int, int, string>> up, down;
while (1) {
if (head[u] == head[v]) break;
if (LID[u] < LID[v]) {
if (v != head[v]) down.eb(head[v], v, "heavy_down"), v = head[v];
down.eb(parent[v], v, "light_down"), v = parent[v];
} else {
if (u != head[u]) up.eb(u, head[u], "heavy_up"), u = head[u];
up.eb(u, parent[u], "light_up"), u = parent[u];
}
}
if (LID[u] < LID[v]) down.eb(u, v, "heavy_down");
elif (LID[v] < LID[u]) up.eb(u, v, "heavy_up");
reverse(all(down));
concat(up, down);
return up;
}
vc<int> restore_path(int u, int v) {
vc<int> P;
for (auto &&[a, b]: get_path_decomposition(u, v, 0)) {
if (a <= b) {
FOR(i, a, b + 1) P.eb(V[i]);
} else {
FOR_R(i, b, a + 1) P.eb(V[i]);
}
}
return P;
}
// path [a,b] と [c,d] の交わり. 空ならば {-1,-1}.
// https://codeforces.com/problemset/problem/500/G
pair<int, int> path_intersection(int a, int b, int c, int d) {
int ab = lca(a, b), ac = lca(a, c), ad = lca(a, d);
int bc = lca(b, c), bd = lca(b, d), cd = lca(c, d);
int x = ab ^ ac ^ bc, y = ab ^ ad ^ bd; // meet(a,b,c), meet(a,b,d)
if (x != y) return {x, y};
int z = ac ^ ad ^ cd;
if (x != z) x = -1;
return {x, x};
}
};
#line 2 "/home/maspy/compro/library/graph/ds/static_toptree.hpp"
/*
参考 joitour tatyam
クラスタは根が virtual なもののみであるような簡易版
N 個の (頂+辺) をマージしていって,木全体+根から親への辺とする.
single(v) : v とその親辺を合わせたクラスタ
rake(L,R) : L の boundary を維持
compress(L,R) (top-down) 順に x,y
*/
template <typename TREE>
struct Static_TopTree {
int N;
TREE &tree;
vc<int> par, lch, rch, A, B; // A, B boundary (top-down)
vc<bool> is_compress;
Static_TopTree(TREE &tree) : tree(tree) { build(); }
void build() {
N = tree.N;
par.assign(N, -1), lch.assign(N, -1), rch.assign(N, -1), A.assign(N, -1), B.assign(N, -1), is_compress.assign(N, 0);
FOR(v, N) { A[v] = tree.parent[v], B[v] = v; }
build_dfs(tree.V[0]);
assert(len(par) == 2 * N - 1);
}
// 木全体での集約値を得る
// single(v) : v とその親辺を合わせたクラスタ
// rake(x, y, u, v) uv(top down) が boundary になるように rake (maybe v=-1)
// compress(x,y,a,b,c) (top-down) 順に (a,b] + (b,c]
template <typename TREE_DP, typename F>
typename TREE_DP::value_type tree_dp(F single) {
using Data = typename TREE_DP::value_type;
auto dfs = [&](auto &dfs, int k) -> Data {
if (0 <= k && k < N) return single(k);
Data x = dfs(dfs, lch[k]), y = dfs(dfs, rch[k]);
if (is_compress[k]) {
assert(B[lch[k]] == A[rch[k]]);
return TREE_DP::compress(x, y);
}
return TREE_DP::rake(x, y);
};
return dfs(dfs, 2 * N - 2);
}
private:
int new_node(int l, int r, int a, int b, bool c) {
int v = len(par);
par.eb(-1), lch.eb(l), rch.eb(r), A.eb(a), B.eb(b), is_compress.eb(c);
par[l] = par[r] = v;
return v;
}
// height, node idx
// compress 参考:https://atcoder.jp/contests/abc351/editorial/9910
// ただし heavy path の選び方までは考慮しない
pair<int, int> build_dfs(int v) {
assert(tree.head[v] == v);
auto path = tree.heavy_path_at(v);
vc<pair<int, int>> stack;
stack.eb(0, path[0]);
auto merge_last_two = [&]() -> void {
auto [h2, k2] = POP(stack);
auto [h1, k1] = POP(stack);
stack.eb(max(h1, h2) + 1, new_node(k1, k2, A[k1], B[k2], true));
};
FOR(i, 1, len(path)) {
pqg<pair<int, int>> que;
int k = path[i];
que.emplace(0, k);
for (auto &c: tree.collect_light(path[i - 1])) { que.emplace(build_dfs(c)); }
while (len(que) >= 2) {
auto [h1, i1] = POP(que);
auto [h2, i2] = POP(que);
if (i2 == k) swap(i1, i2);
int i3 = new_node(i1, i2, A[i1], B[i1], false);
if (k == i1) k = i3;
que.emplace(max(h1, h2) + 1, i3);
}
stack.eb(POP(que));
while (1) {
int n = len(stack);
if (n >= 3 && (stack[n - 3].fi == stack[n - 2].fi || stack[n - 3].fi <= stack[n - 1].fi)) {
auto [h3, k3] = POP(stack);
merge_last_two(), stack.eb(h3, k3);
}
elif (n >= 2 && stack[n - 2].fi <= stack[n - 1].fi) { merge_last_two(); }
else break;
}
}
while (len(stack) >= 2) { merge_last_two(); }
return POP(stack);
}
};
#line 1 "/home/maspy/compro/library/convex/monotone_minima.hpp"
// select(i,j,k) : (i,j) -> (i,k) を行うかどうか
template <typename F>
vc<int> monotone_minima(int H, int W, F select) {
vc<int> min_col(H);
auto dfs = [&](auto& dfs, int x1, int x2, int y1, int y2) -> void {
if (x1 == x2) return;
int x = (x1 + x2) / 2;
int best_y = y1;
for (int y = y1 + 1; y < y2; ++y) {
if (select(x, best_y, y)) best_y = y;
}
min_col[x] = best_y;
dfs(dfs, x1, x, y1, best_y + 1);
dfs(dfs, x + 1, x2, best_y, y2);
};
dfs(dfs, 0, H, 0, W);
return min_col;
}
#line 2 "/home/maspy/compro/library/convex/minplus_convolution.hpp"
template <typename T>
vc<T> minplus_convolution_convex_convex(vc<T>& A, vc<T>& B) {
int n = len(A), m = len(B);
if (n == 0 && m == 0) return {};
vc<T> C(n + m - 1, infty<T>);
while (n > 0 && A[n - 1] == infty<T>) --n;
while (m > 0 && B[m - 1] == infty<T>) --m;
if (n == 0 || m == 0) return C;
int a = 0, b = 0;
while (a < n && A[a] == infty<T>) ++a;
while (b < m && B[b] == infty<T>) ++b;
C[a + b] = A[a] + B[b];
for (int i = a + b + 1; i < n + m - 1; ++i) {
if (b == m - 1 || (a != n - 1 && A[a + 1] + B[b] < A[a] + B[b + 1])) {
chmin(C[i], A[++a] + B[b]);
} else {
chmin(C[i], A[a] + B[++b]);
}
}
return C;
}
template <typename T>
vc<T> minplus_convolution_arbitrary_convex(vc<T>& A, vc<T>& B) {
int n = len(A), m = len(B);
if (n == 0 && m == 0) return {};
vc<T> C(n + m - 1, infty<T>);
while (m > 0 && B[m - 1] == infty<T>) --m;
if (m == 0) return C;
int b = 0;
while (b < m && B[b] == infty<T>) ++b;
auto select = [&](int i, int j, int k) -> bool {
if (i < k) return false;
if (i - j >= m - b) return true;
return A[j] + B[b + i - j] >= A[k] + B[b + i - k];
};
vc<int> J = monotone_minima(n + m - b - 1, n, select);
FOR(i, n + m - b - 1) {
T x = A[J[i]], y = B[b + i - J[i]];
if (x < infty<T> && y < infty<T>) C[b + i] = x + y;
}
return C;
}
template <typename T, bool convA, bool convB>
vc<T> minplus_convolution(vc<T>& A, vc<T>& B) {
static_assert(convA || convB);
if constexpr (convA && convB) return minplus_convolution_convex_convex(A, B);
if constexpr (convA && !convB)
return minplus_convolution_arbitrary_convex(B, A);
if constexpr (convB && !convA)
return minplus_convolution_arbitrary_convex(A, B);
return {};
}
#line 6 "main.cpp"
struct Data {
int n;
array<array<vc<ll>, 2>, 2> dp;
};
struct TDP {
using value_type = Data;
static void calc(vi& A, vi& X, vi Y, int L1, int R1, int L2, int R2) {
if (R1 - L1 <= 1 || R2 - L2 <= 1) {
FOR(i, L1, R1) FOR(j, L2, R2) chmin(A[i + j], X[i] + Y[j]);
return;
}
vi XX = {X.begin() + L1, X.begin() + R1};
vi YY = {Y.begin() + L2, Y.begin() + R2};
vi Z = minplus_convolution_convex_convex<ll>(XX, YY);
FOR(i, len(Z)) chmin(A[L1 + L2 + i], Z[i]);
}
static Data compress(Data L, Data R) {
int n1 = L.n, n2 = R.n;
int n = n1 + n2;
array<array<vc<ll>, 2>, 2> dp;
FOR(i, 2) FOR(j, 2) dp[i][j].assign(n + 1, infty<ll>);
auto upd = [&](int a, int b, int a1, int b1, int a2, int b2, int L1, int R1, int L2, int R2) -> void {
calc(dp[a][b], L.dp[a1][b1], R.dp[a2][b2], L1, R1, L2, R2);
};
// (0,0)
FOR(a, 2) FOR(b, 2) upd(a, b, a, b, a, b, 0, 1, 0, 1);
// (0,j)
FOR(a, 2) FOR(b, 2) {
int a1 = a, b1 = 1, a2 = a, b2 = b;
upd(a, b, a1, b1, a2, b2, 0, 1, 1, n2 + 1);
}
// (i,0)
FOR(a, 2) FOR(b, 2) {
int a1 = a, b1 = b, a2 = 1, b2 = b;
upd(a, b, a1, b1, a2, b2, 1, n1 + 1, 0, 1);
}
// (i,j)
FOR(a, 2) FOR(b, 2) {
int a1 = a, b1 = 1, a2 = 1, b2 = b;
upd(a, b, a1, b1, a2, b2, 1, n1 + 1, 1, n2 + 1);
}
SHOW("cp", n);
FOR(a, 2) FOR(b, 2) SHOW(a, b, L.dp[a][b]);
FOR(a, 2) FOR(b, 2) SHOW(a, b, R.dp[a][b]);
FOR(a, 2) FOR(b, 2) SHOW(a, b, dp[a][b]);
return {n, dp};
}
static Data rake(Data L, Data R) {
int n1 = L.n, n2 = R.n;
int n = n1 + n2;
array<array<vc<ll>, 2>, 2> dp;
FOR(i, 2) FOR(j, 2) dp[i][j].assign(n + 1, infty<ll>);
auto upd = [&](int a, int b, int a1, int b1, int a2, int b2, int L1, int R1, int L2, int R2) -> void {
calc(dp[a][b], L.dp[a1][b1], R.dp[a2][b2], L1, R1, L2, R2);
};
// (0,0)
FOR(a, 2) FOR(b, 2) { upd(a, b, a, b, max(a, b), 0, 0, 1, 0, 1); }
// (0,j)
FOR(a, 2) FOR(b, 2) {
int a1 = 1, b1 = b, a2 = max(a, b), b2 = 0;
upd(a, b, a1, b1, a2, b2, 0, 1, 1, n2 + 1);
}
// (i,0)
FOR(a, 2) FOR(b, 2) {
int a1 = a, b1 = b, a2 = 1, b2 = 0;
upd(a, b, a1, b1, a2, b2, 1, n1 + 1, 0, 1);
}
// (i,j)
FOR(a, 2) FOR(b, 2) {
int a1 = 1, b1 = b, a2 = 1, b2 = 0;
upd(a, b, a1, b1, a2, b2, 1, n1 + 1, 1, n2 + 1);
}
SHOW("rk", n);
FOR(a, 2) FOR(b, 2) SHOW(a, b, L.dp[a][b]);
FOR(a, 2) FOR(b, 2) SHOW(a, b, R.dp[a][b]);
FOR(a, 2) FOR(b, 2) SHOW(a, b, dp[a][b]);
return {n, dp};
}
};
void solve() {
LL(N);
vi C, D;
Graph<int, 0> G(N);
FOR(N - 1) {
INT(a, b, c, d);
--a, --b;
G.add(a, b);
C.eb(c), D.eb(d);
}
G.build();
Tree<decltype(G)> tree(G);
Static_TopTree<decltype(tree)> STT(tree);
auto single = [&](int v) -> Data {
int up = 0, down = 0;
if (v > 0) {
int e = tree.v_to_e(v);
int c = C[e], d = D[e];
if (G.edges[e].frm != v) swap(c, d);
up = c, down = d;
}
array<array<vc<ll>, 2>, 2> dp;
dp[0][0] = {up + down, up};
dp[0][1] = {up, up};
dp[1][0] = {down, 0};
dp[1][1] = {0, 0};
return {1, dp};
};
Data ANS = STT.tree_dp<TDP>(single);
LL(Q);
FOR(Q) {
INT(n);
print(ANS.dp[0][0][n]);
}
}
signed main() {
int T = 1;
// INT(T);
FOR(T) solve();
return 0;
}
詳細信息
Subtask #1:
score: 6
Accepted
Test #1:
score: 6
Accepted
time: 0ms
memory: 3764kb
input:
2 1 2 781089648 283888890 2 1 2
output:
283888890 0
result:
ok 2 lines
Test #2:
score: 6
Accepted
time: 0ms
memory: 4068kb
input:
16 6 10 160848335 124052868 7 1 241203243 110601447 14 6 290972019 163072373 11 15 938517011 154373610 12 1 138651641 741445657 7 8 60218933 280830068 16 15 203079209 633547400 11 7 199606763 919756826 14 12 266702877 916493997 15 13 905937802 481991969 2 10 234605456 722866810 3 5 366455156 4966982...
output:
6311369523 2092762454 966156735 60218933 0 0 0 0 0 0 0 0 0 0 0 0
result:
ok 16 lines
Test #3:
score: 6
Accepted
time: 0ms
memory: 4060kb
input:
16 3 4 204022014 914663555 9 10 11007340 458844696 2 7 605164817 895349276 14 11 434326485 550918606 14 7 712866927 489761842 6 1 356406033 534499656 16 8 942553720 855217399 5 10 865707145 586883622 6 13 108330979 234031340 15 8 769531307 948036095 3 16 358448538 363203546 5 2 419315988 76297418 12...
output:
7413430560 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
result:
ok 16 lines
Test #4:
score: 6
Accepted
time: 0ms
memory: 3692kb
input:
16 4 5 1000000000 1000000000 10 5 1000000000 1000000000 8 5 1000000000 1000000000 11 13 999999646 999999646 15 16 999998089 999998089 7 5 929 929 14 7 898 898 16 9 159 159 6 12 603 603 9 2 999997930 999997930 3 6 999999242 999999242 5 12 155 155 16 14 84 84 14 1 999998173 999998173 12 13 199 199 16 ...
output:
7999996107 5999996107 4999996107 3999996107 2999996107 1999996262 999998089 0 0 0 0 0 0 0 0 0
result:
ok 16 lines
Test #5:
score: 6
Accepted
time: 0ms
memory: 3868kb
input:
16 11 14 14368758 85219578 14 16 643747916 252121045 9 14 727413140 523990811 2 15 521253466 147320442 7 13 866289084 908489699 12 6 320730514 344516785 10 9 516379646 496493179 15 8 776569142 612383860 8 3 734861011 149748310 1 5 815040382 677607019 2 12 50609677 301797586 5 14 716517909 635543949 ...
output:
7189308203 2211904770 1191420780 456559769 85219578 0 0 0 0 0 0 0 0 0 0 0
result:
ok 16 lines
Test #6:
score: 6
Accepted
time: 0ms
memory: 3704kb
input:
16 13 9 720744296 759388601 13 5 458441737 833011123 1 16 698474192 71086181 3 8 861918984 114516836 15 10 278084894 710666762 4 8 287405359 250250967 1 6 741642264 735381406 2 15 792787000 825787518 6 12 261754526 230466084 13 7 938274540 78969406 12 10 202958723 294264294 12 4 98252269 169605483 3...
output:
5844026168 2690903861 1848894892 1128150596 458441737 0 0 0 0 0 0 0 0 0 0 0
result:
ok 16 lines
Test #7:
score: 6
Accepted
time: 0ms
memory: 4068kb
input:
16 1 7 765638022 679756044 10 6 759069284 453967337 5 7 726239258 178402766 4 15 242761737 318885919 1 15 723511609 915383888 9 8 553064704 380886548 12 13 822971769 782770910 6 8 525975561 603298402 11 6 724594701 141189620 13 2 8408668 628943880 12 10 299406310 356329223 5 14 795305423 974800675 8...
output:
7154270560 522076168 141189620 0 0 0 0 0 0 0 0 0 0 0 0 0
result:
ok 16 lines
Test #8:
score: 6
Accepted
time: 0ms
memory: 4068kb
input:
16 6 2 396591 824425 14 1 121765 805092 9 10 386895 457376 3 15 20413 247942 8 3 426212 748706 12 11 318841 270569 2 16 925055746 604726712 12 1 359775 784231 14 5 516354 617685 2 9 970316 896797 2 7 943776860 978585272 14 9 712667 948012 8 9 566593 580631 4 12 761761 974298 13 2 136216 831818 16 1 ...
output:
1556207783 7704211 3905589 2878333 2046515 1222090 705736 318841 0 0 0 0 0 0 0 0
result:
ok 16 lines
Test #9:
score: 6
Accepted
time: 0ms
memory: 4068kb
input:
16 2 8 119073534 555736925 5 2 866791517 685527555 11 14 180535517 448907590 2 16 393190702 164818863 6 9 298521139 301021930 2 1 808238767 844723287 4 1 221776781 268737189 10 2 551486708 14310879 2 15 363573262 106859347 2 9 622353716 714488454 13 2 908780203 288479297 13 7 897814090 253679879 2 3...
output:
6418370219 4638508078 3561532122 2638156476 1952628921 1339055967 890148377 496957675 133384413 14310879 0 0 0 0 0 0
result:
ok 16 lines
Test #10:
score: 6
Accepted
time: 0ms
memory: 3768kb
input:
16 3 12 901164666 987344195 7 11 777270351 297899178 6 14 441322434 685318792 3 4 894100390 768738682 6 10 308476613 227952988 12 2 398335684 800091780 15 9 683557377 818349714 2 8 55495903 851348261 5 10 842245631 650602672 11 16 169505872 655780963 9 8 978986177 766795908 5 13 17521706 829965580 1...
output:
8007192643 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
result:
ok 16 lines
Test #11:
score: 6
Accepted
time: 0ms
memory: 3704kb
input:
16 12 15 517822965 25354413 11 15 338190311 652436812 7 15 127729186 939448905 15 13 696913706 181993967 1 15 498822103 388824680 9 15 20787116 535387165 15 16 202795662 159091154 15 4 474628657 160994640 15 14 997130096 858493491 15 3 341451768 47792481 15 5 757815934 174503003 8 15 341732022 77854...
output:
7709225932 6581334361 5641885456 4863341388 4105525454 3408611748 2756174936 2220787771 1746159114 1337789248 948964568 569601843 228150075 25354413 0 0
result:
ok 16 lines
Subtask #2:
score: 7
Accepted
Test #12:
score: 7
Accepted
time: 0ms
memory: 3696kb
input:
2 1 2 683402985 526289818 1 1
output:
526289818
result:
ok single line: '526289818'
Test #13:
score: 7
Accepted
time: 401ms
memory: 60852kb
input:
200000 30498 170310 456566691 649436035 88553 73637 443596936 376869783 157116 8270 670934073 119072463 24742 48732 237943289 398782798 118620 71333 841086509 861755957 91523 118037 345609124 755508586 182978 92078 999023640 247489369 57480 73002 550952716 31090859 85037 151494 615937607 181113974 8...
output:
100090261531134
result:
ok single line: '100090261531134'
Test #14:
score: 7
Accepted
time: 346ms
memory: 73176kb
input:
200000 62380 190510 660465798 980286669 73494 59167 399860395 883378826 78917 156327 617261054 354160980 25845 163881 79154538 824380095 97426 144191 891448990 704743172 73271 43633 837335594 922276690 193758 169742 364918510 151494521 62996 52874 828453581 144363372 199529 178275 804482094 11831376...
output:
100066669866017
result:
ok single line: '100066669866017'
Test #15:
score: 7
Accepted
time: 401ms
memory: 58232kb
input:
200000 183258 143073 982 982 31786 177754 580 580 26332 6792 85 85 6390 70312 847 847 193105 75442 735 735 172433 196956 999926081 999926081 114861 33150 991 991 108634 161301 206 206 122529 105025 426 426 21388 86201 300 300 170711 87982 999923960 999923960 120595 43763 921 921 99462 120013 737 737...
output:
81103004367189
result:
ok single line: '81103004367189'
Test #16:
score: 7
Accepted
time: 381ms
memory: 61112kb
input:
200000 1539 92316 48323903 202410877 35890 69243 415172828 308900141 190963 50985 755719943 159735479 72146 159885 72946173 622268672 127505 64851 485107488 958218451 43378 89830 417162770 911217276 158176 69012 355971119 826228739 146386 106745 99361947 614603091 190012 95465 758111489 876554997 40...
output:
99944714663527
result:
ok single line: '99944714663527'
Test #17:
score: 7
Accepted
time: 384ms
memory: 61296kb
input:
200000 13693 159720 471504101 851110321 134244 80255 908560356 681906336 52579 127713 744119846 470734684 84038 32991 525544642 941494197 118155 105510 885724375 303139090 24258 176279 806826007 371683303 46557 54039 791816892 13705486 119090 160877 781290926 259135450 21899 55292 338745705 70209065...
output:
100142110488065
result:
ok single line: '100142110488065'
Test #18:
score: 7
Accepted
time: 393ms
memory: 59368kb
input:
200000 51485 158642 829759545 555246994 46408 182427 680884310 952048393 181386 51981 774364250 510078376 158642 137221 958595981 417456152 158642 13560 525026357 666355475 158642 119626 653370640 66503632 23721 100035 260540702 507629954 180546 101304 430322145 698388876 62412 158642 536391228 6818...
output:
100029161376725
result:
ok single line: '100029161376725'
Test #19:
score: 7
Accepted
time: 353ms
memory: 75008kb
input:
200000 172976 108672 288769649 485088836 159642 46318 971501113 486464598 120751 69878 169239703 173145059 44498 138117 820693607 695329677 158520 63527 366383754 437019528 19626 64856 939531671 635492288 21084 66469 694278429 909732840 30440 161053 573714265 203831805 160668 89739 513226897 3644949...
output:
99756547102864
result:
ok single line: '99756547102864'
Test #20:
score: 7
Accepted
time: 396ms
memory: 60040kb
input:
200000 154441 4651 747796649 453770199 137511 154441 46174763 669025918 154441 46408 501310306 365029626 154441 70897 637262505 711161748 149885 154441 906469650 910775313 56604 154441 120489234 529690198 154441 128437 857569560 602188933 154441 12895 528165172 22359068 177797 154441 947733025 70024...
output:
100044587345734
result:
ok single line: '100044587345734'
Subtask #3:
score: 9
Accepted
Test #21:
score: 9
Accepted
time: 0ms
memory: 3744kb
input:
2 2 1 92722556 873785501 1 2
output:
0
result:
ok single line: '0'
Test #22:
score: 9
Accepted
time: 397ms
memory: 60244kb
input:
200000 99982 83075 709942852 92942003 168325 12929 879930937 637190556 85628 123672 784369088 731448156 34917 117619 569166498 663184347 92257 112058 369526210 824568522 32464 109884 258245678 691717157 129594 115097 627894556 937225369 54700 187473 81636213 510866047 52020 197198 577461848 47343465...
output:
99980874607500
result:
ok single line: '99980874607500'
Test #23:
score: 9
Accepted
time: 319ms
memory: 75784kb
input:
200000 95719 149301 794275735 801652183 143736 125721 536375521 497451149 4070 82461 612985394 185791331 187444 177732 203761783 978534058 64389 115859 767852404 159121136 62787 153732 112099169 754249162 9791 45944 722996059 45421943 86166 76684 734259220 976172654 144257 171894 593459611 866106682...
output:
0
result:
ok single line: '0'
Test #24:
score: 9
Accepted
time: 388ms
memory: 58492kb
input:
200000 91072 122945 396 396 108944 92874 371 371 102962 134537 999957708 999957708 76444 112175 999974422 999974422 92013 18283 224 224 47655 149920 674 674 199293 47834 240 240 143059 145065 306 306 135615 109141 702 702 1701 49881 38 38 73750 69655 585 585 44570 126598 823 823 154521 29581 601 601...
output:
81260440461409
result:
ok single line: '81260440461409'
Test #25:
score: 9
Accepted
time: 398ms
memory: 60784kb
input:
200000 67335 151665 90056816 679694202 146132 193464 78979944 31693610 12681 195973 465813284 579615164 121902 196667 589074557 966872296 161123 6959 801681236 38291288 183137 2828 885145066 943464735 120574 8814 71857893 233909004 125797 191097 749557098 250997809 169492 36886 49204718 996198360 12...
output:
99809636135608
result:
ok single line: '99809636135608'
Test #26:
score: 9
Accepted
time: 403ms
memory: 61864kb
input:
200000 93451 53831 682115484 829322216 86322 162604 254622021 431488750 147239 61110 113915150 613534953 82511 156348 664035377 946257404 88519 17517 226289497 122021251 112417 43731 544607243 486486588 35770 121679 465952267 546169853 90586 30876 245521241 309759680 113666 65754 237364361 270831775...
output:
84393916618910
result:
ok single line: '84393916618910'
Test #27:
score: 9
Accepted
time: 388ms
memory: 60640kb
input:
200000 56712 10679 477548548 250987465 48768 10679 648414920 382252569 10679 138629 849839069 418932116 10679 196853 372927887 111589355 66660 10679 746411098 882637935 186062 10679 311457882 818901438 10679 60211 350285495 867834084 143533 10679 509730429 587741385 10679 87624 514054621 907539858 1...
output:
99896973077522
result:
ok single line: '99896973077522'
Test #28:
score: 9
Accepted
time: 376ms
memory: 66280kb
input:
200000 137614 48684 905625272 307783875 31464 61159 171680699 710988975 53283 142419 838631110 435432764 123798 38255 535935021 734147826 29584 149426 371764453 875958871 175282 48325 804482249 620893459 55526 102124 797947818 494644787 62800 128616 320838726 279002065 33102 171918 195788467 4014179...
output:
38157344174731
result:
ok single line: '38157344174731'
Test #29:
score: 9
Accepted
time: 402ms
memory: 59416kb
input:
200000 199712 1338 415002784 805964493 102372 1338 193298420 76290567 28728 1338 804225462 746940935 1338 98005 301699377 822393419 1338 162021 577703287 907659652 1338 57339 183927508 654074158 1338 168042 859700698 427766288 1338 87100 984454975 400556960 193867 1338 787582553 819174352 1338 18369...
output:
99976824303453
result:
ok single line: '99976824303453'
Subtask #4:
score: 17
Accepted
Dependency #1:
100%
Accepted
Test #30:
score: 17
Accepted
time: 0ms
memory: 4032kb
input:
2 1 2 781089648 283888890 2 1 2
output:
283888890 0
result:
ok 2 lines
Test #31:
score: 17
Accepted
time: 4ms
memory: 4640kb
input:
2000 668 1839 972599655 457068476 133 11 666838083 851019038 1194 1287 133765716 574032589 107 441 176385032 470971775 131 1040 243142030 758968684 377 1963 707275419 115749455 1599 1801 764665175 425876028 169 656 229430355 330349441 128 1885 47324906 989597389 1366 419 253887722 295321149 1520 605...
output:
1007815336129 968471364756 948794710183 931465538135 919379309781 908949503371 898863017460 889541245976 880407673956 871485748529 862948404232 854564677534 846315324929 838321505364 830946890393 824397294302 818173445062 811962023909 805811586483 799889608613 794074981118 788469743669 783290399664 ...
result:
ok 2000 lines
Test #32:
score: 17
Accepted
time: 3ms
memory: 4468kb
input:
2000 1507 1054 442165448 671661615 1248 179 87718372 57803246 177 1811 573774719 208696657 1774 45 808902498 987598144 100 667 997239116 107950700 1114 1047 90988914 625746213 818 116 312860776 925130030 1986 811 196318668 361242571 1124 1820 798979369 753656023 435 638 63026816 169722034 496 1349 9...
output:
979634806036 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
result:
ok 2000 lines
Test #33:
score: 17
Accepted
time: 4ms
memory: 4388kb
input:
2000 1525 429 147 147 1216 1496 340 340 717 1473 999975270 999975270 1114 862 697 697 1723 216 974 974 1059 865 495 495 182 210 766 766 1745 1959 999981504 999981504 1052 1914 638 638 318 1144 288 288 1401 927 176 176 1555 496 318 318 565 304 116 116 1439 265 90 90 952 790 402 402 1795 677 127 127 1...
output:
816987603536 814987603536 813987604014 812987604504 811987605268 810987606227 809987607186 808987608484 807987609782 806987611080 805987612378 804987613751 803987615124 802987616617 801987618383 800987620192 799987622058 798987623924 797987625794 796987627815 795987630118 794987632435 793987634752 7...
result:
ok 2000 lines
Test #34:
score: 17
Accepted
time: 4ms
memory: 4340kb
input:
2000 373 1642 63657133 850914336 103 774 827627582 753286797 1704 813 857134718 516101827 886 354 134978226 145183107 132 1239 17657223 582173637 1806 1813 549768976 884335257 993 1205 145864886 175216094 110 1804 554037719 889640060 1240 760 622694407 818131870 335 1049 176463161 321592201 1985 982...
output:
993439578644 956445814624 939840118265 927190958260 916391337740 906274516515 897352078924 888518216208 879966749793 871626842858 863454140478 855567065753 847681257509 840122943214 832807138112 825772780035 818957114766 812382909807 805850688392 799689205484 793683039565 788190914731 782921891017 7...
result:
ok 2000 lines
Test #35:
score: 17
Accepted
time: 4ms
memory: 4496kb
input:
2000 838 616 964972 727856 767 1966 297293 961917 1528 1174 350309 809912 94 145 528172 786328 1519 25 474782 330748 150 84 987021 119895 792 1577 188984 806709 76 1836 801862 360250 9 148 577892 890736 991 955 613442 930810 135 1623 71117 754738 1618 61 754384 824814 1921 1150 9872 832902 1416 16 3...
output:
3151729932 1490745586 970501973 936634296 916387727 896432666 882364904 871595506 861275935 852160225 843667677 835335533 827285136 819530016 812028588 804721144 798490006 792337990 786258606 780232964 774529076 768857427 763423701 758219379 753037762 747913173 742881442 737906445 732937194 72800087...
result:
ok 2000 lines
Test #36:
score: 17
Accepted
time: 4ms
memory: 4568kb
input:
2000 267 1012 29026841 359918212 1553 1061 435867283 33144312 1670 1109 988917740 68160339 948 496 231906652 737226954 610 1641 972617450 818164551 1030 931 630927532 461579893 1209 970 625011983 682844528 63 1856 458314131 670604776 1746 1008 696454538 404229917 917 813 392046602 435463075 1468 102...
output:
998853819359 967120682374 953269672580 941849331387 931241683825 921276677110 911337819540 901986725243 893200309022 884558703799 875976456800 867522290743 859558632337 851608471803 843762237099 836142232132 828919740309 821971874595 815367534376 809019317904 802895133103 796998597941 791322345111 7...
result:
ok 2000 lines
Test #37:
score: 17
Accepted
time: 0ms
memory: 4516kb
input:
2000 278 314 642322 260619 1354 1355 778536 561972 1107 765 653443 859029 810 1596 342249 271261 17 188 909841 624772 784 1153 387898 928863 230 566 503491 92369 1902 17 333718 17338 974 1777 696073 718026 358 758 956259 611920 1996 211 73914 992273 851 376 143429 561006 476 1156 762866 927086 177 7...
output:
14886853906 13166663751 12197152661 11244345647 10325387509 9436897021 8629006527 7850290167 7147075931 6474998375 5890753359 5309769240 4735542024 4172519089 3616514278 3067013296 2536143195 2014862258 1494918615 993605672 969765636 953350461 940694413 928618413 917888172 908243771 899808403 891555...
result:
ok 2000 lines
Test #38:
score: 17
Accepted
time: 0ms
memory: 4440kb
input:
2000 374 138 224422639 38871324 274 25 614140855 294378456 960 482 771284019 389463551 673 1495 327509275 759582532 1670 425 494511063 516818198 1512 234 758587972 294061250 125 416 760945280 345853400 1003 405 84717299 354546151 1935 927 394014334 986087601 1945 286 237720954 958374134 1212 502 139...
output:
1020766846606 1007002784804 999346872165 992274505754 985589793611 979434926460 973485015062 967649305774 961825435056 956057364162 950459867350 944914649107 939463540924 934278992727 929115619904 924079006080 919101029671 914194699920 909382255333 904589503356 899958668369 895331464064 890705684752...
result:
ok 2000 lines
Test #39:
score: 17
Accepted
time: 0ms
memory: 4444kb
input:
2000 1143 1229 81340832 203783547 797 1383 973573951 938965060 688 802 32619795 803180557 1430 1438 330664534 241372464 643 706 61158209 115993048 1648 106 327252353 597706939 1779 1415 293303361 360351419 692 1828 915132451 368048738 16 1709 95899611 285365876 1351 458 166747820 509256128 1727 793 ...
output:
998301212759 880537928692 870457219325 861252294892 852396337323 843981634800 835667290515 828477413156 821655401311 814870686928 808222533521 802024821337 796150817317 790387213402 784736669906 779359674398 774039179523 768840175047 763750052574 758953098983 754172321967 749445382638 744756930608 7...
result:
ok 2000 lines
Test #40:
score: 17
Accepted
time: 2ms
memory: 4552kb
input:
2000 287 975 25233696 534621398 1113 396 104395603 704259239 944 968 167901712 996060127 1820 1963 59027230 940778339 517 421 142414910 668774876 1194 987 697044445 916940725 758 1996 840435736 296316325 859 1228 942003242 410430124 267 1863 69640147 572953353 1531 664 675846017 437317470 1896 1937 ...
output:
979865969015 938524253268 919252073876 908446325642 898652991327 889092497390 880176982256 871653554541 863190891606 854923191298 846796123803 838968661922 831239262473 823590794453 815982441829 808439653715 800918039984 793492711274 786193390091 779078065331 771979068036 765125487688 758277507704 7...
result:
ok 2000 lines
Test #41:
score: 17
Accepted
time: 4ms
memory: 4468kb
input:
2000 151 987 401112 51743 1571 1615 48174 742492 1382 1435 702779 104242 4 1937 536648583 582006045 407 1292 690047 209913 18 74 609460 921874 1713 615 837107 163945 595 1110 736540 874700 104 296 336025 925055 436 1478 268683 619735 1303 213 353888 717230 238 1973 859805 102668 379 1922 238240 8461...
output:
253674247639 252146222576 251150950748 250159056506 249169328747 248179917829 247192247572 246207031683 245222508185 244239965485 243258799509 242277744406 241297414827 240317798683 239339147347 238360849518 237384439214 236408299310 235432280907 234457447152 233485340091 232513737287 231545110505 2...
result:
ok 2000 lines
Test #42:
score: 17
Accepted
time: 0ms
memory: 4672kb
input:
2000 1182 1921 605080443 886655033 1708 1921 595798016 843919086 1680 1921 860566020 131317035 975 1921 418114074 512317024 226 587 473765902 67634029 776 1921 433855395 216901660 495 1921 409271624 79315361 1921 149 936810062 509308613 132 1921 150894436 98571823 1529 1921 430693927 259969407 764 1...
output:
1009089197282 1006610361108 1004752344991 1002897699917 1001044344246 999213639830 997395170490 995584737424 993790322164 991996888755 990214477773 988434882351 986697111591 984984989073 983283340517 981585399308 979893311639 978212055868 976564068551 974938526236 973323760294 971712816971 970105147...
result:
ok 2000 lines
Test #43:
score: 17
Accepted
time: 0ms
memory: 4724kb
input:
2000 1464 1864 547333628 669063562 1110 745 632608125 908067725 1684 428 8923157 938458876 1765 1430 986598839 576426299 1927 1280 377814925 800077297 1161 731 430521772 265852180 1638 1725 909244690 745425182 111 1733 251904285 714544194 743 1824 285789564 35311843 1856 1602 316442646 397926101 214...
output:
985726096226 120339232724 118500847924 116729781772 115033477360 113477145230 112001745571 110529934958 109314993504 108147080886 106995756702 105956093186 104937429871 103931619182 102932846661 101934984607 100952729677 99971614132 98995604204 98028346026 97077956501 96128655790 95190898491 9425401...
result:
ok 2000 lines
Test #44:
score: 17
Accepted
time: 4ms
memory: 4208kb
input:
2000 1594 99 114938634 955551953 1594 535 724720583 787940175 941 1594 632758297 743357149 1594 360 540763785 555917064 1594 304 748278274 799266695 1594 352 264038818 900446954 1594 1913 669527592 537488989 1657 1594 183798298 397102870 1594 1275 186397916 822447484 1594 1982 333936723 32520282 333...
output:
985192149621 984143039445 983144785233 982146796921 981149821551 980152942601 979156406727 978161102895 977166217002 976171652235 975177196106 974184023009 973191204385 972198955355 971206748663 970214979896 969223519746 968232067678 967241269126 966250730842 965261103232 964271731653 963282385779 9...
result:
ok 2000 lines
Subtask #5:
score: 17
Accepted
Test #45:
score: 17
Accepted
time: 0ms
memory: 4052kb
input:
2 1 2 543195986 144983073 1 1
output:
144983073
result:
ok single line: '144983073'
Test #46:
score: 17
Accepted
time: 389ms
memory: 59368kb
input:
200000 73974 46059 151001152 42729969 112523 175399 580450366 914798605 65645 46109 848220487 698683602 63048 106502 596698349 144038980 98888 11174 948423025 972032422 115490 95315 788936645 231068151 5185 187319 690370465 616111588 10331 161483 606127487 195799307 133831 170948 694137989 490575964...
output:
5449143475272
result:
ok single line: '5449143475272'
Test #47:
score: 17
Accepted
time: 340ms
memory: 75296kb
input:
200000 55956 185434 219535533 77244021 65295 10318 437281446 132103674 53900 4204 965744871 874409893 67035 24879 596850278 341918390 70240 26074 837750040 304745373 116294 182996 806065306 688634320 21494 104498 465710706 695396976 71934 165575 761917591 524436924 95534 186806 199405432 534812435 1...
output:
99875550841137
result:
ok single line: '99875550841137'
Test #48:
score: 17
Accepted
time: 390ms
memory: 59544kb
input:
200000 7483 177514 697 697 3231 129745 999845999 999845999 109949 87100 999891988 999891988 29413 172327 299 299 170523 87926 999952504 999952504 124853 61455 999934698 999934698 42350 132622 91 91 69970 50413 815 815 55204 183824 999939325 999939325 59484 71281 206 206 37791 170069 451 451 50058 17...
output:
1780721830674
result:
ok single line: '1780721830674'
Test #49:
score: 17
Accepted
time: 407ms
memory: 59432kb
input:
200000 105838 73186 128349778 353598318 63031 136227 114628484 285882597 191398 198457 37866162 634787861 171869 171043 573009985 810912546 37331 137239 646433925 996743109 49856 185509 134224603 278011602 160259 37541 150993603 746491914 59331 161858 652495320 165803995 117507 178303 933794623 4222...
output:
98851135600011
result:
ok single line: '98851135600011'
Test #50:
score: 17
Accepted
time: 412ms
memory: 58740kb
input:
200000 140663 129611 636279 260017 196385 122941 547533 592198 114132 160778 43364 613890 88859 39847 443789 512911 114404 161183 856155 49796 67299 83775 31748 559092 72303 74977 250332 609125 68306 161828 565819 826801 65357 98383 789137 755350 108533 38461 214064 982695 137910 8024 674613 855905 ...
output:
121701643090
result:
ok single line: '121701643090'
Test #51:
score: 17
Accepted
time: 399ms
memory: 59944kb
input:
200000 194805 91167 96006427 746087633 19172 51672 703076613 703507534 129776 6959 147190461 210591357 107179 63438 934326702 717246383 80551 7862 340033856 42790691 174094 147100 93534123 588911952 16841 106289 330166235 144103001 127608 89570 526650289 259902042 83162 168481 830039469 619808700 97...
output:
98850979599881
result:
ok single line: '98850979599881'
Test #52:
score: 17
Accepted
time: 412ms
memory: 59628kb
input:
200000 104188 40173 518798 400873 74450 186185 454835 624317 34752 157183 496291 489884 53876 145380 544680 183688 8015 65233 387174 69062 34450 54750 507740 406375 131441 167028 859185 425529 160168 160307 565172 163779 51621 92179 414635 854124 192560 59890 67817 557177 20346 38814 909372 207112 1...
output:
2073045420823
result:
ok single line: '2073045420823'
Test #53:
score: 17
Accepted
time: 389ms
memory: 59244kb
input:
200000 36234 48499 497762619 268240611 61631 22160 249970846 76734461 96939 174559 273525596 277814042 33667 191684 350573347 320714717 66892 81318 492270419 242486005 9223 51478 302202500 1452383 110040 35016 129099352 359187439 17314 132066 183661699 778288251 110040 70931 750625996 484714051 4396...
output:
51135293866439
result:
ok single line: '51135293866439'
Test #54:
score: 17
Accepted
time: 409ms
memory: 60576kb
input:
200000 183062 61942 195495034 670262692 160284 94545 558986737 74870683 162714 101868 929690547 336544868 189299 19925 853155959 659182060 121123 106943 326206617 124808162 26384 54945 996860044 871381136 28523 100744 300454000 658917117 143026 153583 958105033 893037327 157880 138484 444666156 3319...
output:
3299654185147
result:
ok single line: '3299654185147'
Test #55:
score: 17
Accepted
time: 388ms
memory: 57824kb
input:
200000 159287 10497 134128546 375519540 54050 6880 652209391 685600434 64819 100589 468264811 669713633 21538 42057 208086343 266212316 144623 154696 891658106 589370999 187481 49088 462695361 664697185 172258 8653 138424940 735985051 42828 173282 910919433 804041217 187820 48021 69765115 86631456 1...
output:
90571973135125
result:
ok single line: '90571973135125'
Test #56:
score: 17
Accepted
time: 400ms
memory: 59348kb
input:
200000 1668 46162 335237 921785 113769 127901 853451705 934150953 1626 35497 533058 791354 111597 54552 186865 35999 126603 83723 570650 215845 130809 113769 533240830 792980919 109646 143446 640055 759014 81148 77400 102642 184563 170617 167437 530479 964975 13500 177003 968531 702011 116634 165372...
output:
11052402240814
result:
ok single line: '11052402240814'
Test #57:
score: 17
Accepted
time: 379ms
memory: 59788kb
input:
200000 169530 195889 230163362 439799818 119233 134720 559035500 953508831 8940 134720 884441063 243088533 134720 69148 680467824 593559555 134720 29050 577681718 589369589 35824 166656 841766082 244727568 134720 198916 67469622 39769615 193336 149614 866808245 894158218 192941 134720 258122702 9382...
output:
40626528262020
result:
ok single line: '40626528262020'
Test #58:
score: 17
Accepted
time: 360ms
memory: 66404kb
input:
200000 110455 115168 942917483 944057356 24250 174224 120443609 532352510 11171 74665 190086664 829576737 159411 147194 706659415 940447640 21273 60049 121436594 924345007 199052 198780 576499335 914436406 80048 25499 994151154 181108553 21097 69194 919349404 246872582 69845 47327 610809487 71576289...
output:
29337562026797
result:
ok single line: '29337562026797'
Test #59:
score: 17
Accepted
time: 411ms
memory: 58232kb
input:
200000 103057 108208 924190969 473823292 103057 183266 908503598 913830751 160109 103057 152232631 446122875 150542 103057 645333429 20388717 9111 103057 958697887 339808805 186911 103057 832784802 864166960 103057 107162 110079035 799843025 103057 41684 472282933 46971465 120852 103057 515888934 87...
output:
68177387813969
result:
ok single line: '68177387813969'
Subtask #6:
score: 44
Accepted
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
100%
Accepted
Dependency #4:
100%
Accepted
Dependency #5:
100%
Accepted
Test #60:
score: 44
Accepted
time: 0ms
memory: 4052kb
input:
2 1 2 781089648 283888890 2 1 2
output:
283888890 0
result:
ok 2 lines
Test #61:
score: 44
Accepted
time: 398ms
memory: 57780kb
input:
200000 44159 197131 891233343 986928673 108175 35372 198085304 271789370 53683 24668 495215545 450974548 89492 22897 81376180 225566918 179614 50294 694042950 467925728 138499 55918 279410537 411284019 73038 185532 724888513 746414782 55794 68935 669013578 866137236 24781 190216 824031578 574380614 ...
output:
100115113662611 99900558725947 99800093356460 99721352294060 99650961400968 99581104259681 99516838769298 99457230356039 99398333443683 99340651810941 99285949441869 99233677205373 99185132050182 99136756554355 99090108811271 99044150304377 98999685202852 98958863736021 98919786702266 98881179267175...
result:
ok 200000 lines
Test #62:
score: 44
Accepted
time: 360ms
memory: 72360kb
input:
200000 175359 168254 5931790 258081728 37021 111569 954582420 389161703 329 5513 169962574 630413033 84610 162995 919900065 471408027 130766 117286 197051215 315737739 25220 196912 588903843 373994012 178755 136124 839873329 292286218 154141 156034 311661610 996614389 96783 41805 47053107 960108409 ...
output:
99689152074699 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
result:
ok 200000 lines
Test #63:
score: 44
Accepted
time: 396ms
memory: 59124kb
input:
200000 6275 84873 459 459 84419 114902 999909322 999909322 162203 5885 510 510 14970 26320 526 526 91557 151031 614 614 11931 114770 999939970 999939970 67496 92287 999953031 999953031 162252 81104 999898937 999898937 59589 116312 999930064 999930064 74572 58923 924 924 59615 143971 314 314 92780 72...
output:
81098614130755 81096614130755 81095614130755 81094614130863 81093614131888 81092614133803 81091614135718 81090614137896 81089614140336 81088614142976 81087614145616 81086614148256 81085614151592 81084614154928 81083614158530 81082614162351 81081614166421 81080614170520 81079614174619 81078614178932 ...
result:
ok 200000 lines
Test #64:
score: 44
Accepted
time: 396ms
memory: 60424kb
input:
200000 160977 17462 678276164 881765461 11805 157245 686233376 670626811 176887 175697 650067753 751938146 119454 68583 225034481 293453725 125377 18938 5975211 852081006 60833 78935 408152568 108532377 42822 56928 439404520 765987681 187121 6426 663723325 651618633 141165 86029 635208307 955777644 ...
output:
99994866396556 99787311149239 99699510785397 99634275304509 99571493788746 99511257023245 99453038705758 99396236791850 99344957967465 99296492449687 99248153461804 99200432399944 99153351951549 99108556670752 99064044438973 99021576013095 98979290729931 98937277668964 98897952033484 98858767272483 ...
result:
ok 200000 lines
Test #65:
score: 44
Accepted
time: 392ms
memory: 59284kb
input:
200000 88924 86654 733531 771673 141960 160100 802037 579654 71983 79080 543638 631282 45923 24562 934484 895784 144862 123024 651297 361225 110714 185138 284486 109722 86175 190161 743852 103208 155099 94388 300252 22586 55327 186560 216038 593098 155886 67271 266812 987528 86819 181093 419816 3507...
output:
313374674046 311865946570 310867992772 309872953464 308882045636 307898324388 306916635955 305935287635 304954194862 303978434921 303002728876 302030065715 301057726687 300088982311 299122619149 298156853793 297196301958 296237491214 295282976419 294332110721 293382901383 292434907544 291489611566 2...
result:
ok 200000 lines
Test #66:
score: 44
Accepted
time: 400ms
memory: 59500kb
input:
200000 196350 54507 77738573 962067321 34474 44767 855892331 555193005 32985 75231 231516004 405549503 91251 134218 160305236 912262892 39911 173155 888442455 86557534 192457 143178 630855651 182512591 46813 171897 200878617 307002757 65865 72486 702445421 136847970 133759 75057 835925723 853539417 ...
output:
100015606995577 99673614491424 99572965538611 99473273254295 99377225608182 99281720114997 99186416021044 99091829318505 98997964511007 98905124043727 98812581243391 98720376428788 98628353081440 98536484273580 98445295645747 98355551099019 98265839391368 98176515337358 98089253625948 98003554855586...
result:
ok 200000 lines
Test #67:
score: 44
Accepted
time: 399ms
memory: 59416kb
input:
200000 33746 108534 972168 748690 81066 144204 515329 439784 168792 176925 569638 866120 169466 82636 408680 964236 23559 164839 3911 637859 3510 139199 142460 995179 179990 182846 183642 455753 23788 86291 504006 346529 75279 169660 309512 999230 127656 14719 393161 987180 87643 77178 976421 228652...
output:
1977997787540 1976478983619 1975479426330 1974480010545 1973480596399 1972481422387 1971482250926 1970483121254 1969484185725 1968485271867 1967486819127 1966488830936 1965490980498 1964493721308 1963496670580 1962499713632 1961503277769 1960507015573 1959511012922 1958515148392 1957519633179 195652...
result:
ok 200000 lines
Test #68:
score: 44
Accepted
time: 394ms
memory: 59796kb
input:
200000 16988 166144 110123679 170167529 113059 188862 494518328 262159447 6964 193846 821331019 825834910 77262 39605 637348267 335601010 158351 63078 147419087 463748048 42321 7360 834913593 220953771 71374 16019 261983461 160746812 95299 26299 385262538 373380596 74548 80753 890852973 277948162 19...
output:
100052435363023 100023999451422 100009195309040 99995254712109 99982248438388 99969527068423 99956911009197 99944501769306 99932129947446 99920026642913 99907947872890 99896129912455 99884525154306 99872926517424 99861436909700 99850100176480 99838768549407 99827622464782 99816531826667 998054432636...
result:
ok 200000 lines
Test #69:
score: 44
Accepted
time: 399ms
memory: 60768kb
input:
200000 149671 171876 306741618 782758924 52048 25726 72871358 318729100 111747 147371 804989847 905333520 168174 75321 229393389 752385337 76047 6475 302710715 224462330 7132 141833 137317548 77963635 57722 34042 784515193 168421253 66062 150118 670329059 398166149 181286 52819 995053932 509460416 1...
output:
99962954222748 87100127164041 87082131945093 87067612994623 87053616599472 87040256066278 87027548737868 87014974207965 87002705538513 86990881438971 86979167384193 86967649720568 86956404037901 86945165215309 86934022815003 86922886698426 86911801500106 86900747371152 86889713795123 86878750478396 ...
result:
ok 200000 lines
Test #70:
score: 44
Accepted
time: 388ms
memory: 59260kb
input:
200000 173456 156538 707322519 492268960 169758 37680 498867479 683085761 170712 90356 49286607 149373376 66956 195913 766271491 757986438 122803 113106 82162901 412469981 184142 90707 871759517 19750224 114684 25723 790593883 313027752 36644 12701 786966850 896853325 105036 135832 559064106 3531277...
output:
99687115918801 97750442670126 96778206151060 95806120392048 94835619789797 93865271232403 92895172866358 91925092641872 90955209899417 89985881931641 89021633920665 88060048459425 87102725693688 86145503795291 85189728173393 84244276699307 83301667616689 82364402937083 81433282510910 80809273410680 ...
result:
ok 200000 lines
Test #71:
score: 44
Accepted
time: 387ms
memory: 59024kb
input:
200000 122616 188874 224405 471310 27125 131453 138691 812503 107916 20134 253092 948098 53554 154062 889692 975216 6403 134365 718751 643805 186371 37794 387709 602032 553 27519 535334 98887 106465 29846 964848943 571004226 181314 142204 407162 229940 15623 173197 228878 272496 188165 184188 113218...
output:
28723918650729 28722417584475 28721417623279 28720417687972 28719417777877 28718417869160 28717417969127 28716418071793 28715418181377 28714418293691 28713418413364 28712418551057 28711418691379 28710418833346 28709418977613 28708419123626 28707419284245 28706419471842 28705419673947 28704419880260 ...
result:
ok 200000 lines
Test #72:
score: 44
Accepted
time: 391ms
memory: 59960kb
input:
200000 48461 123277 241239443 106519096 83596 43577 225945948 884545412 123277 142081 613057371 239000469 55807 123277 381705386 46477131 7533 123277 208572829 17441867 189624 54347 487099620 165831821 123277 103545 662222288 700987676 174790 123277 548605503 583110325 93602 110191 343063581 1413752...
output:
99891046616041 99882517879767 99876988077292 99871663349834 99866554601708 99861520013079 99856491099153 99851470575939 99846484840016 99841525961652 99836591312780 99831710932251 99826832634218 99821956901059 99817158925892 99812361348698 99807604707769 99802879196446 99798185823760 99793540465857 ...
result:
ok 200000 lines
Test #73:
score: 44
Accepted
time: 372ms
memory: 66580kb
input:
200000 119609 67416 691497916 297831253 80134 127685 41560838 118476118 164616 35512 982912619 931886609 30685 35847 544949786 355506043 15057 69768 392148856 169997817 22344 104975 703524354 647092332 169275 124154 649279330 133075386 99770 91069 380501252 281558941 72440 179967 883357594 361144072...
output:
99806755209267 35984759474900 35980359623204 35975997266680 35971876075059 35967768730750 35963673714372 35959618732688 35955609028773 35951599694612 35947613761661 35943671037739 35939806500561 35935991600885 35932186408974 35928389618856 35924625584792 35920908344490 35917242645953 35913598858305 ...
result:
ok 200000 lines
Test #74:
score: 44
Accepted
time: 397ms
memory: 59304kb
input:
200000 194683 176210 368911574 689024599 128374 194683 919585303 9895564 126259 194683 444046314 191665947 194683 35789 80923156 731837905 194683 76498 436333118 314499714 194683 136355 896178730 958549098 155743 194683 431886734 25863316 165622 194683 749864622 618223134 194683 77129 921121196 3056...
output:
99844912648715 99843910194425 99842910200060 99841910216675 99840910237736 99839910263691 99838910294398 99837910328670 99836910364929 99835910405431 99834910447231 99833910494926 99832910545314 99831910598200 99830910668568 99829910740824 99828910830654 99827910922645 99826911017663 99825911119470 ...
result:
ok 200000 lines
Extra Test:
score: 0
Extra Test Passed