QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#390004 | #7523. Partially Free Meal | oldyan | AC ✓ | 1753ms | 184116kb | C++23 | 40.3kb | 2024-04-14 23:44:03 | 2024-04-14 23:44:04 |
Judging History
answer
/*
lib: https://github.com/old-yan/CP-template
author: oldyan
*/
#include <algorithm>
#include <bit>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstring>
#include <functional>
#include <numeric>
#include <string>
#include <sys/mman.h>
#include <sys/stat.h>
#include <vector>
#ifndef __OY_PERSISTENTSEGTREE__
#define __OY_PERSISTENTSEGTREE__
namespace OY {
namespace PerSeg {
using index_type = uint32_t;
struct Ignore {};
template <typename ValueType>
struct BaseNode {
using value_type = ValueType;
using modify_type = ValueType;
using node_type = BaseNode<ValueType>;
static value_type op(const value_type &x, const value_type &y) { return x + y; }
static void map(const modify_type &modify, node_type *x) { x->m_val += modify; }
value_type m_val;
const value_type &get() const { return m_val; }
void set(const value_type &val) { m_val = val; }
};
template <typename ValueType, typename ModifyType, typename SizeType>
struct LazyNode {
using value_type = ValueType;
using modify_type = ModifyType;
using node_type = LazyNode<ValueType, ModifyType, SizeType>;
static value_type op(const value_type &x, const value_type &y) { return x + y; }
static void map(const modify_type &modify, node_type *x, SizeType len) { x->m_val += modify * len; }
static void com(const modify_type &modify, node_type *x) { x->m_modify += modify; }
value_type m_val;
modify_type m_modify;
const value_type &get() const { return m_val; }
void set(const value_type &val) { m_val = val; }
bool has_lazy() const { return bool(m_modify); }
const modify_type &get_lazy() const { return m_modify; }
void clear_lazy() { m_modify = 0; }
void pushup(node_type *lchild, node_type *rchild) { m_val = lchild->m_val + rchild->m_val; }
};
template <typename ValueType, typename Operation>
struct CustomNode {
using value_type = ValueType;
using node_type = CustomNode<ValueType, Operation>;
static Operation s_op;
static value_type op(const value_type &x, const value_type &y) { return s_op(x, y); }
value_type m_val;
const value_type &get() const { return m_val; }
void set(const value_type &val) { m_val = val; }
};
template <typename ValueType, typename Operation>
Operation CustomNode<ValueType, Operation>::s_op;
template <typename ValueType, typename ModifyType, typename Operation, typename Mapping, typename Composition, bool InitClearLazy, typename SizeType>
struct CustomLazyNode {
using value_type = ValueType;
using modify_type = ModifyType;
using node_type = CustomLazyNode<ValueType, ModifyType, Operation, Mapping, Composition, InitClearLazy, SizeType>;
static Operation s_op;
static Mapping s_map;
static Composition s_com;
static modify_type s_default_modify;
static value_type op(const value_type &x, const value_type &y) { return s_op(x, y); }
static void map(const modify_type &modify, node_type *x, SizeType len) { x->m_val = s_map(modify, x->m_val, len); }
static void com(const modify_type &modify, node_type *x) { x->m_modify = s_com(modify, x->m_modify); }
static constexpr bool init_clear_lazy = InitClearLazy;
value_type m_val;
modify_type m_modify;
const value_type &get() const { return m_val; }
void set(const value_type &val) { m_val = val; }
const modify_type &get_lazy() const { return m_modify; }
void clear_lazy() { m_modify = s_default_modify; }
};
template <typename ValueType, typename ModifyType, typename Operation, typename Mapping, typename Composition, bool InitClearLazy, typename SizeType>
Operation CustomLazyNode<ValueType, ModifyType, Operation, Mapping, Composition, InitClearLazy, SizeType>::s_op;
template <typename ValueType, typename ModifyType, typename Operation, typename Mapping, typename Composition, bool InitClearLazy, typename SizeType>
Mapping CustomLazyNode<ValueType, ModifyType, Operation, Mapping, Composition, InitClearLazy, SizeType>::s_map;
template <typename ValueType, typename ModifyType, typename Operation, typename Mapping, typename Composition, bool InitClearLazy, typename SizeType>
Composition CustomLazyNode<ValueType, ModifyType, Operation, Mapping, Composition, InitClearLazy, SizeType>::s_com;
template <typename ValueType, typename ModifyType, typename Operation, typename Mapping, typename Composition, bool InitClearLazy, typename SizeType>
ModifyType CustomLazyNode<ValueType, ModifyType, Operation, Mapping, Composition, InitClearLazy, SizeType>::s_default_modify;
#ifdef __cpp_lib_void_t
template <typename... Tp>
using void_t = std::void_t<Tp...>;
#else
template <typename... Tp>
struct make_void {
using type = void;
};
template <typename... Tp>
using void_t = typename make_void<Tp...>::type;
#endif
template <typename Tp, typename ValueType, typename = void>
struct Has_modify_type : std::false_type {
using type = ValueType;
};
template <typename Tp, typename ValueType>
struct Has_modify_type<Tp, ValueType, void_t<typename Tp::modify_type>> : std::true_type {
using type = typename Tp::modify_type;
};
template <typename Tp, typename = void>
struct Has_has_lazy : std::false_type {};
template <typename Tp>
struct Has_has_lazy<Tp, void_t<decltype(std::declval<Tp>().has_lazy())>> : std::true_type {};
template <typename Tp, typename = void>
struct Has_get_lazy : std::false_type {};
template <typename Tp>
struct Has_get_lazy<Tp, void_t<decltype(std::declval<Tp>().get_lazy())>> : std::true_type {};
template <typename Tp, typename NodePtr, typename SizeType, typename = void>
struct Has_pushup : std::false_type {};
template <typename Tp, typename NodePtr, typename SizeType>
struct Has_pushup<Tp, NodePtr, SizeType, void_t<decltype(std::declval<Tp>().pushup(std::declval<NodePtr>(), std::declval<NodePtr>(), std::declval<SizeType>()))>> : std::true_type {};
template <typename Tp, typename NodePtr>
struct Has_pushup<Tp, NodePtr, void, void_t<decltype(std::declval<Tp>().pushup(std::declval<NodePtr>(), std::declval<NodePtr>()))>> : std::true_type {};
template <typename Tp, typename NodePtr, typename ModifyType, typename SizeType, typename = void>
struct Has_map : std::false_type {};
template <typename Tp, typename NodePtr, typename ModifyType>
struct Has_map<Tp, NodePtr, ModifyType, void, void_t<decltype(Tp::map(std::declval<ModifyType>(), std::declval<NodePtr>()))>> : std::true_type {};
template <typename Tp, typename NodePtr, typename ModifyType, typename SizeType>
struct Has_map<Tp, NodePtr, ModifyType, SizeType, void_t<decltype(Tp::map(std::declval<ModifyType>(), std::declval<NodePtr>(), std::declval<SizeType>()))>> : std::true_type {};
template <typename Tp, typename = void>
struct Has_init_clear_lazy : std::false_type {};
template <typename Tp>
struct Has_init_clear_lazy<Tp, void_t<decltype(Tp::init_clear_lazy)>> : std::true_type {};
template <typename Node, typename RangeMapping = Ignore, bool Complete = false, bool Lock = false, typename SizeType = uint64_t, index_type MAX_NODE = 1 << 22>
struct Tree {
struct node : Node {
index_type m_lchild, m_rchild;
bool is_null() const { return this == s_buffer; }
node *lchild() const { return s_buffer + m_lchild; }
node *rchild() const { return s_buffer + m_rchild; }
};
using value_type = typename node::value_type;
using modify_type = typename Has_modify_type<node, value_type>::type;
static node s_buffer[MAX_NODE];
static index_type s_use_count;
static bool s_lock;
index_type m_root;
SizeType m_size;
static index_type _copynode(node *x) {
s_buffer[s_use_count] = *x;
return s_use_count++;
}
static void _apply(node *cur, const modify_type &modify, SizeType len) { node::map(modify, cur, len), node::com(modify, cur); }
static void _apply(node *cur, const modify_type &modify) {
if constexpr (Has_map<node, node *, modify_type, void>::value)
node::map(modify, cur);
else if constexpr (Has_map<node, node *, modify_type, SizeType>::value)
node::map(modify, cur, 1);
else
cur->set(node::op(modify, cur->get()));
}
static bool _has_lazy(node *cur) {
if constexpr (!Has_get_lazy<node>::value) return false;
if constexpr (!Has_has_lazy<node>::value)
return true;
else
return cur->has_lazy();
}
static void lock() { s_lock = true; }
static void unlock() { s_lock = false; }
static SizeType _reduce_kth(const Tree<Node, RangeMapping, Complete, Lock, SizeType, MAX_NODE> &base, const Tree<Node, RangeMapping, Complete, Lock, SizeType, MAX_NODE> &end, node *base_cur, node *end_cur, SizeType floor, SizeType ceil, value_type k) {
if (floor == ceil) return floor;
SizeType mid = (floor + ceil) >> 1;
if constexpr (Has_get_lazy<node>::value) {
if constexpr (!Has_has_lazy<node>::value)
base._pushdown_if_lazy(base_cur, floor, ceil, mid);
else if (base_cur->has_lazy())
base._pushdown_if_lazy(base_cur, floor, ceil, mid);
if constexpr (!Has_has_lazy<node>::value)
end._pushdown_if_lazy(end_cur, floor, ceil, mid);
else if (end_cur->has_lazy())
end._pushdown_if_lazy(end_cur, floor, ceil, mid);
}
value_type l = end_cur->lchild()->get() - base_cur->lchild()->get();
if (l > k)
return base_cur->m_lchild ? _reduce_kth(base, end, base_cur->lchild(), end_cur->lchild(), floor, mid, k) : end._kth(end_cur->lchild(), floor, mid, k);
else
return base_cur->m_rchild ? _reduce_kth(base, end, base_cur->rchild(), end_cur->rchild(), mid + 1, ceil, k - l) : end._kth(end_cur->rchild(), mid + 1, ceil, k - l);
}
static SizeType reduce_kth(const Tree<Node, RangeMapping, Complete, Lock, SizeType, MAX_NODE> &base, const Tree<Node, RangeMapping, Complete, Lock, SizeType, MAX_NODE> &end, value_type k) { return _reduce_kth(base, end, base._root(), end._root(), 0, base.m_size - 1, k); }
static index_type _newnode(SizeType floor, SizeType ceil) {
if constexpr (!Complete && !std::is_same<RangeMapping, Ignore>::value) s_buffer[s_use_count].set(RangeMapping()(floor, ceil));
if constexpr (Has_init_clear_lazy<node>::value)
if constexpr (node::init_clear_lazy)
s_buffer[s_use_count].clear_lazy();
return s_use_count++;
}
template <typename InitMapping>
static void _initnode(node *cur, SizeType floor, SizeType ceil, InitMapping mapping) {
if (floor == ceil) {
if constexpr (!std::is_same<InitMapping, Ignore>::value) cur->set(mapping(floor));
} else {
SizeType mid = (floor + ceil) >> 1;
cur->m_lchild = _newnode(floor, mid);
cur->m_rchild = _newnode(mid + 1, ceil);
_initnode(cur->lchild(), floor, mid, mapping);
_initnode(cur->rchild(), mid + 1, ceil, mapping);
_pushup(cur, ceil - floor + 1);
}
}
static void _copy_lchild(node *cur, SizeType floor, SizeType mid) {
if (cur->m_lchild) {
cur->m_lchild = _copynode(cur->lchild());
} else if constexpr (!Complete)
cur->m_lchild = _newnode(floor, mid);
}
static void _copy_rchild(node *cur, SizeType mid, SizeType ceil) {
if (cur->m_rchild) {
cur->m_rchild = _copynode(cur->rchild());
} else if constexpr (!Complete)
cur->m_rchild = _newnode(mid + 1, ceil);
}
static void _copy_child(node *cur, SizeType floor, SizeType ceil, SizeType mid) { _copy_lchild(cur, floor, mid), _copy_rchild(cur, mid, ceil); }
static void _pushdown_naive(node *cur, SizeType floor, SizeType ceil, SizeType mid) {
if constexpr (Has_get_lazy<node>::value) {
_apply(cur->lchild(), cur->get_lazy(), mid - floor + 1);
_apply(cur->rchild(), cur->get_lazy(), ceil - mid);
cur->clear_lazy();
}
}
static void _pushdown(node *cur, SizeType floor, SizeType ceil, SizeType mid) {
if constexpr (!Lock)
_copy_child(cur, floor, ceil, mid);
else if (!s_lock)
_copy_child(cur, floor, ceil, mid);
if (_has_lazy(cur)) _pushdown_naive(cur, floor, ceil, mid);
}
static void _pushdown_l(node *cur, SizeType floor, SizeType ceil, SizeType mid) {
if (_has_lazy(cur)) return _pushdown_if_lazy(cur, floor, ceil, mid);
if constexpr (!Lock)
_copy_lchild(cur, floor, mid);
else if (!s_lock)
_copy_lchild(cur, floor, mid);
}
static void _pushdown_r(node *cur, SizeType floor, SizeType ceil, SizeType mid) {
if (_has_lazy(cur)) return _pushdown_if_lazy(cur, floor, ceil, mid);
if constexpr (!Lock)
_copy_rchild(cur, mid, ceil);
else if (!s_lock)
_copy_rchild(cur, mid, ceil);
}
static void _pushdown_if_lazy(node *cur, SizeType floor, SizeType ceil, SizeType mid) {
if constexpr (!Lock)
_copy_child(cur, floor, ceil, mid);
else if (!s_lock)
_copy_child(cur, floor, ceil, mid);
_pushdown_naive(cur, floor, ceil, mid);
}
static void _pushup(node *cur, SizeType len) {
if constexpr (Has_pushup<node, node *, SizeType>::value)
cur->pushup(cur->lchild(), cur->rchild(), len);
else if constexpr (Has_pushup<node, node *, void>::value)
cur->pushup(cur->lchild(), cur->rchild());
else
cur->set(node::op(cur->lchild()->get(), cur->rchild()->get()));
}
static void _modify(node *cur, SizeType floor, SizeType ceil, SizeType i, const value_type &val) {
if (floor == ceil)
cur->set(val);
else {
SizeType mid = (floor + ceil) >> 1;
if (i <= mid)
_pushdown_l(cur, floor, ceil, mid), _modify(cur->lchild(), floor, mid, i, val);
else
_pushdown_r(cur, floor, ceil, mid), _modify(cur->rchild(), mid + 1, ceil, i, val);
_pushup(cur, ceil - floor + 1);
}
}
static void _add(node *cur, SizeType floor, SizeType ceil, SizeType i, const modify_type &modify) {
if (floor == ceil)
_apply(cur, modify);
else {
SizeType mid = (floor + ceil) >> 1;
if (i <= mid)
_pushdown_l(cur, floor, ceil, mid), _add(cur->lchild(), floor, mid, i, modify);
else
_pushdown_r(cur, floor, ceil, mid), _add(cur->rchild(), mid + 1, ceil, i, modify);
_pushup(cur, ceil - floor + 1);
}
}
static void _add(node *cur, SizeType floor, SizeType ceil, SizeType left, SizeType right, const modify_type &modify) {
if (left <= floor && right >= ceil)
_apply(cur, modify, ceil - floor + 1);
else {
SizeType mid = (floor + ceil) >> 1;
_pushdown(cur, floor, ceil, mid);
if (left <= mid) _add(cur->lchild(), floor, mid, left, right, modify);
if (right > mid) _add(cur->rchild(), mid + 1, ceil, left, right, modify);
_pushup(cur, ceil - floor + 1);
}
}
static value_type _query(SizeType left, SizeType right) {
if constexpr (std::is_same<RangeMapping, Ignore>::value)
return s_buffer[0].get();
else
return RangeMapping()(left, right);
}
static value_type _query(node *cur, SizeType floor, SizeType ceil, SizeType i) {
if (cur->is_null()) return _query(i, i);
if (floor == ceil) return cur->get();
SizeType mid = (floor + ceil) >> 1;
if (_has_lazy(cur)) _pushdown_if_lazy(cur, floor, ceil, mid);
return i <= mid ? _query(cur->lchild(), floor, mid, i) : _query(cur->rchild(), mid + 1, ceil, i);
}
static value_type _query(node *cur, SizeType floor, SizeType ceil, SizeType left, SizeType right) {
if (cur->is_null()) return _query(left, right);
if (left == floor && right == ceil) return cur->get();
SizeType mid = (floor + ceil) >> 1;
if (_has_lazy(cur)) _pushdown_if_lazy(cur, floor, ceil, mid);
if (left > mid) return _query(cur->rchild(), mid + 1, ceil, left, right);
if (right <= mid) return _query(cur->lchild(), floor, mid, left, right);
return node::op(_query(cur->lchild(), floor, mid, left, mid), _query(cur->rchild(), mid + 1, ceil, mid + 1, right));
}
template <typename Judger>
static SizeType _max_right(node *cur, SizeType floor, SizeType ceil, SizeType start, value_type &val, Judger &&judge) {
if (start <= floor) {
value_type a = start < floor ? node::op(val, cur->get()) : cur->get();
if (judge(a))
return val = a, ceil;
else if (floor == ceil)
return floor - 1;
}
SizeType mid = (floor + ceil) >> 1;
_pushdown(cur, floor, ceil, mid);
if (start <= mid) {
SizeType res = _max_right(cur->lchild(), floor, mid, start, val, judge);
if (res != mid) return res;
}
return _max_right(cur->rchild(), mid + 1, ceil, start, val, judge);
}
template <typename Judger>
static SizeType _min_left(node *cur, SizeType floor, SizeType ceil, SizeType start, value_type &val, Judger &&judge) {
if (start >= ceil) {
value_type a = start > ceil ? node::op(cur->get(), val) : cur->get();
if (judge(a))
return val = a, floor;
else if (floor == ceil)
return ceil + 1;
}
SizeType mid = (floor + ceil) >> 1;
_pushdown(cur, floor, ceil, mid);
if (start > mid) {
SizeType res = _min_left(cur->rchild(), mid + 1, ceil, start, val, judge);
if (res != mid + 1) return res;
}
return _min_left(cur->lchild(), floor, mid, start, val, judge);
}
static SizeType _kth(node *cur, SizeType floor, SizeType ceil, value_type k) {
if (floor == ceil) return floor;
SizeType mid = (floor + ceil) >> 1;
if (_has_lazy(cur)) _pushdown_if_lazy(cur, floor, ceil, mid);
if (cur->lchild()->get() > k)
return _kth(cur->lchild(), floor, mid, k);
else
return _kth(cur->rchild(), mid + 1, ceil, k - cur->lchild()->get());
}
node *_root() const { return s_buffer + m_root; }
Tree() = default;
template <typename InitMapping = Ignore>
Tree(SizeType length, InitMapping mapping = InitMapping()) { resize(length, mapping); }
template <typename Iterator>
Tree(Iterator first, Iterator last) { reset(first, last); }
Tree copy() const {
Tree other;
if (other.m_size = m_size) other.m_root = _copynode(_root());
return other;
}
template <typename InitMapping = Ignore>
void resize(SizeType length, InitMapping mapping = InitMapping()) {
if (m_size = length) {
m_root = _newnode(0, m_size - 1);
if constexpr (Complete || !std::is_same<InitMapping, Ignore>::value) _initnode(_root(), 0, m_size - 1, mapping);
}
}
template <typename Iterator>
void reset(Iterator first, Iterator last) {
resize(last - first, [&](SizeType i) { return *(first + i); });
}
void modify(SizeType i, const value_type &val) { _modify(_root(), 0, m_size - 1, i, val); }
void add(SizeType i, const modify_type &modify) { _add(_root(), 0, m_size - 1, i, modify); }
void add(SizeType left, SizeType right, const modify_type &modify) { _add(_root(), 0, m_size - 1, left, right, modify); }
value_type query(SizeType i) const { return _query(_root(), 0, m_size - 1, i); }
value_type query(SizeType left, SizeType right) const { return _query(_root(), 0, m_size - 1, left, right); }
value_type query_all() const { return _root()->get(); }
template <typename Judger>
SizeType max_right(SizeType left, Judger &&judge) {
value_type val;
return _max_right(_root(), 0, m_size - 1, left, val, judge);
}
template <typename Judger>
SizeType min_left(SizeType right, Judger &&judge) {
value_type val;
return _min_left(_root(), 0, m_size - 1, right, val, judge);
}
SizeType kth(value_type k) { return _kth(_root(), 0, m_size - 1, k); }
};
template <typename Ostream, typename Node, typename RangeMapping, bool Complete, bool Lock, typename SizeType, index_type MAX_NODE>
Ostream &operator<<(Ostream &out, const Tree<Node, RangeMapping, Complete, Lock, SizeType, MAX_NODE> &x) {
out << "[";
for (SizeType i = 0; i < x.m_size; i++) {
if (i) out << ", ";
out << x.query(i);
}
return out << "]";
}
template <typename Node, typename RangeMapping, bool Complete, bool Lock, typename SizeType, index_type MAX_NODE>
typename Tree<Node, RangeMapping, Complete, Lock, SizeType, MAX_NODE>::node Tree<Node, RangeMapping, Complete, Lock, SizeType, MAX_NODE>::s_buffer[MAX_NODE];
template <typename Node, typename RangeMapping, bool Complete, bool Lock, typename SizeType, index_type MAX_NODE>
index_type Tree<Node, RangeMapping, Complete, Lock, SizeType, MAX_NODE>::s_use_count = 1;
template <typename Node, typename RangeMapping, bool Complete, bool Lock, typename SizeType, index_type MAX_NODE>
bool Tree<Node, RangeMapping, Complete, Lock, SizeType, MAX_NODE>::s_lock = true;
}
template <typename Tp, bool Complete, typename RangeMapping = PerSeg::Ignore, bool Lock = false, PerSeg::index_type MAX_NODE = 1 << 22, typename SizeType, typename Operation, typename InitMapping = PerSeg::Ignore, typename TreeType = PerSeg::Tree<PerSeg::CustomNode<Tp, Operation>, RangeMapping, Complete, Lock, SizeType, MAX_NODE>>
auto make_PerSegTree(SizeType length, Operation op, InitMapping mapping = InitMapping()) -> TreeType { return TreeType(length, mapping); }
template <typename Tp, bool Complete, typename RangeMapping = PerSeg::Ignore, bool Lock = false, PerSeg::index_type MAX_NODE = 1 << 22, typename SizeType, typename InitMapping = PerSeg::Ignore, typename TreeType = PerSeg::Tree<PerSeg::CustomNode<Tp, const Tp &(*)(const Tp &, const Tp &)>, RangeMapping, Complete, Lock, SizeType, MAX_NODE>>
auto make_PerSegTree(SizeType length, const Tp &(*op)(const Tp &, const Tp &), InitMapping mapping = InitMapping()) -> TreeType { return TreeType::node::s_op = op, TreeType(length, mapping); }
template <typename Tp, bool Complete, typename RangeMapping = PerSeg::Ignore, bool Lock = false, PerSeg::index_type MAX_NODE = 1 << 22, typename SizeType, typename InitMapping = PerSeg::Ignore, typename TreeType = PerSeg::Tree<PerSeg::CustomNode<Tp, Tp (*)(Tp, Tp)>, RangeMapping, Complete, Lock, SizeType, MAX_NODE>>
auto make_PerSegTree(SizeType length, Tp (*op)(Tp, Tp), InitMapping mapping = InitMapping()) -> TreeType { return TreeType::node::s_op = op, TreeType(length, mapping); }
template <bool Lock = false, PerSeg::index_type MAX_NODE = 1 << 22, typename Iterator, typename Operation, typename Tp = typename std::iterator_traits<Iterator>::value_type, typename TreeType = PerSeg::Tree<PerSeg::CustomNode<Tp, Operation>, PerSeg::Ignore, true, Lock, uint32_t, MAX_NODE>>
auto make_PerSegTree(Iterator first, Iterator last, Operation op) -> TreeType { return TreeType(first, last); }
template <bool Lock = false, PerSeg::index_type MAX_NODE = 1 << 22, typename Iterator, typename Tp = typename std::iterator_traits<Iterator>::value_type, typename TreeType = PerSeg::Tree<PerSeg::CustomNode<Tp, const Tp &(*)(const Tp &, const Tp &)>, PerSeg::Ignore, true, Lock, uint32_t, MAX_NODE>>
auto make_PerSegTree(Iterator first, Iterator last, const Tp &(*op)(const Tp &, const Tp &)) -> TreeType { return TreeType::node::s_op = op, TreeType(first, last); }
template <bool Lock = false, PerSeg::index_type MAX_NODE = 1 << 22, typename Iterator, typename Tp = typename std::iterator_traits<Iterator>::value_type, typename TreeType = PerSeg::Tree<PerSeg::CustomNode<Tp, Tp (*)(Tp, Tp)>, PerSeg::Ignore, true, Lock, uint32_t, MAX_NODE>>
auto make_PerSegTree(Iterator first, Iterator last, Tp (*op)(Tp, Tp)) -> TreeType { return TreeType::node::s_op = op, TreeType(first, last); }
template <typename ValueType, typename ModifyType, bool InitClearLazy, bool Complete, typename RangeMapping = PerSeg::Ignore, bool Lock = false, PerSeg::index_type MAX_NODE = 1 << 22, typename SizeType, typename Operation, typename Mapping, typename Composition, typename InitMapping = PerSeg::Ignore, typename TreeType = PerSeg::Tree<PerSeg::CustomLazyNode<ValueType, ModifyType, Operation, Mapping, Composition, InitClearLazy, SizeType>, RangeMapping, Complete, Lock, SizeType, MAX_NODE>>
auto make_lazy_PerSegTree(SizeType length, Operation op, Mapping map, Composition com, const ModifyType &default_modify = ModifyType(), InitMapping mapping = InitMapping()) -> TreeType { return TreeType::node::s_default_modify = default_modify, TreeType(length, mapping); }
template <typename ValueType, typename ModifyType, bool InitClearLazy, bool Lock = false, PerSeg::index_type MAX_NODE = 1 << 22, typename Iterator, typename Operation, typename Mapping, typename Composition, typename TreeType = PerSeg::Tree<PerSeg::CustomLazyNode<ValueType, ModifyType, Operation, Mapping, Composition, InitClearLazy, uint32_t>, PerSeg::Ignore, true, Lock, uint32_t, MAX_NODE>>
auto make_lazy_PerSegTree(Iterator first, Iterator last, Operation op, Mapping map, Composition com, const ModifyType &default_modify = ModifyType()) -> TreeType { return TreeType::node::s_default_modify = default_modify, TreeType(first, last); }
template <bool Complete = false, bool Lock = false, typename SizeType = uint64_t, PerSeg::index_type MAX_NODE = 1 << 22>
using PerSegSumTree = PerSeg::Tree<PerSeg::BaseNode<int64_t>, PerSeg::Ignore, Complete, Lock, SizeType, MAX_NODE>;
template <bool Complete = false, bool Lock = false, typename SizeType = uint64_t, PerSeg::index_type MAX_NODE = 1 << 22>
using PerSegLazySumTree = PerSeg::Tree<PerSeg::LazyNode<int64_t, int64_t, SizeType>, PerSeg::Ignore, Complete, Lock, SizeType, MAX_NODE>;
}
#endif
#ifndef __OY_LINUXIO__
#define __OY_LINUXIO__
#ifdef __unix__
#endif
#if __cpp_constexpr >= 201907L
#define CONSTEXPR20 constexpr
#define INLINE20 constexpr
#else
#define CONSTEXPR20
#define INLINE20 inline
#endif
#define cin OY::LinuxIO::InputHelper<>::get_instance()
#define cout OY::LinuxIO::OutputHelper::get_instance()
#define endl '\n'
#ifndef INPUT_FILE
#define INPUT_FILE "in.txt"
#endif
#ifndef OUTPUT_FILE
#define OUTPUT_FILE "out.txt"
#endif
namespace OY {
namespace LinuxIO {
static constexpr size_t INPUT_BUFFER_SIZE = 1 << 26, OUTPUT_BUFFER_SIZE = 1 << 20;
#ifdef OY_LOCAL
static constexpr char input_file[] = INPUT_FILE, output_file[] = OUTPUT_FILE;
#else
static constexpr char input_file[] = "", output_file[] = "";
#endif
template <typename U, size_t E>
struct TenPow {
static constexpr U value = TenPow<U, E - 1>::value * 10;
};
template <typename U>
struct TenPow<U, 0> {
static constexpr U value = 1;
};
struct InputPre {
uint32_t m_data[0x10000];
CONSTEXPR20 InputPre() {
std::fill(m_data, m_data + 0x10000, -1);
for (size_t i = 0, val = 0; i != 10; i++)
for (size_t j = 0; j != 10; j++) m_data[0x3030 + i + (j << 8)] = val++;
}
};
struct OutputPre {
uint32_t m_data[10000];
CONSTEXPR20 OutputPre() {
uint32_t *c = m_data;
for (size_t i = 0; i != 10; i++)
for (size_t j = 0; j != 10; j++)
for (size_t k = 0; k != 10; k++)
for (size_t l = 0; l != 10; l++) *c++ = i + (j << 8) + (k << 16) + (l << 24) + 0x30303030;
}
};
template <size_t MMAP_SIZE = 1 << 30>
struct InputHelper {
static INLINE20 InputPre pre{};
struct stat m_stat;
char *m_p, *m_c, *m_end;
InputHelper(FILE *file = stdin) {
#ifdef __unix__
auto fd = fileno(file);
fstat(fd, &m_stat);
m_c = m_p = (char *)mmap(nullptr, m_stat.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
m_end = m_p + m_stat.st_size;
#else
uint32_t size = fread(m_c = m_p = new char[INPUT_BUFFER_SIZE], 1, INPUT_BUFFER_SIZE, file);
m_end = m_p + size;
#endif
}
static InputHelper<MMAP_SIZE> &get_instance() {
static InputHelper<MMAP_SIZE> s_obj(*input_file ? fopen(input_file, "rt") : stdin);
return s_obj;
}
template <typename Tp, typename std::enable_if<std::is_unsigned<Tp>::value & std::is_integral<Tp>::value>::type * = nullptr>
InputHelper &operator>>(Tp &x) {
x = 0;
while (!isdigit(*m_c)) m_c++;
x = *m_c++ ^ '0';
while (~pre.m_data[*reinterpret_cast<uint16_t *&>(m_c)]) x = x * 100 + pre.m_data[*reinterpret_cast<uint16_t *&>(m_c)++];
if (isdigit(*m_c)) x = x * 10 + (*m_c++ ^ '0');
return *this;
}
template <typename Tp, typename std::enable_if<std::is_signed<Tp>::value & std::is_integral<Tp>::value>::type * = nullptr>
InputHelper &operator>>(Tp &x) {
typename std::make_unsigned<Tp>::type t{};
bool sign{};
while (!isdigit(*m_c)) sign = (*m_c++ == '-');
t = *m_c++ ^ '0';
while (~pre.m_data[*reinterpret_cast<uint16_t *&>(m_c)]) t = t * 100 + pre.m_data[*reinterpret_cast<uint16_t *&>(m_c)++];
if (isdigit(*m_c)) t = t * 10 + (*m_c++ ^ '0');
x = sign ? -t : t;
return *this;
}
InputHelper &operator>>(char &x) {
while (*m_c <= ' ') m_c++;
x = *m_c++;
return *this;
}
InputHelper &operator>>(std::string &x) {
while (*m_c <= ' ') m_c++;
char *c = m_c;
while (*c > ' ') c++;
x.assign(m_c, c - m_c), m_c = c;
return *this;
}
InputHelper &operator>>(std::string_view &x) {
while (*m_c <= ' ') m_c++;
char *c = m_c;
while (*c > ' ') c++;
x = std::string_view(m_c, c - m_c), m_c = c;
return *this;
}
};
struct OutputHelper {
static INLINE20 OutputPre pre{};
FILE *m_file;
char m_p[OUTPUT_BUFFER_SIZE], *m_c, *m_end;
OutputHelper(FILE *file = stdout) {
m_file = file;
m_c = m_p, m_end = m_p + OUTPUT_BUFFER_SIZE;
}
~OutputHelper() { flush(); }
static OutputHelper &get_instance() {
static OutputHelper s_obj(*output_file ? fopen(output_file, "wt") : stdout);
return s_obj;
}
void flush() { fwrite(m_p, 1, m_c - m_p, m_file), m_c = m_p; }
OutputHelper &operator<<(char x) {
if (m_end - m_c < 20) flush();
*m_c++ = x;
return *this;
}
OutputHelper &operator<<(std::string_view s) {
if (m_end - m_c < s.size()) flush();
memcpy(m_c, s.data(), s.size()), m_c += s.size();
return *this;
}
OutputHelper &operator<<(uint64_t x) {
if (m_end - m_c < 20) flush();
#define CASEW(w) \
case TenPow<uint64_t, w - 1>::value... TenPow<uint64_t, w>::value - 1: \
*(uint32_t *)m_c = pre.m_data[x / TenPow<uint64_t, w - 4>::value]; \
m_c += 4, x %= TenPow<uint64_t, w - 4>::value;
switch (x) {
CASEW(19);
CASEW(15);
CASEW(11);
CASEW(7);
case 100 ... 999:
*(uint32_t *)m_c = pre.m_data[x * 10];
m_c += 3;
break;
CASEW(18);
CASEW(14);
CASEW(10);
CASEW(6);
case 10 ... 99:
*(uint32_t *)m_c = pre.m_data[x * 100];
m_c += 2;
break;
CASEW(17);
CASEW(13);
CASEW(9);
CASEW(5);
case 0 ... 9:
*m_c++ = '0' + x;
break;
default:
*(uint32_t *)m_c = pre.m_data[x / TenPow<uint64_t, 16>::value];
m_c += 4;
x %= TenPow<uint64_t, 16>::value;
CASEW(16);
CASEW(12);
CASEW(8);
case 1000 ... 9999:
*(uint32_t *)m_c = pre.m_data[x];
m_c += 4;
break;
}
#undef CASEW
return *this;
}
OutputHelper &operator<<(uint32_t x) {
if (m_end - m_c < 20) flush();
#define CASEW(w) \
case TenPow<uint32_t, w - 1>::value... TenPow<uint32_t, w>::value - 1: \
*(uint32_t *)m_c = pre.m_data[x / TenPow<uint32_t, w - 4>::value]; \
m_c += 4, x %= TenPow<uint32_t, w - 4>::value;
switch (x) {
default:
*(uint32_t *)m_c = pre.m_data[x / TenPow<uint32_t, 6>::value];
m_c += 4;
x %= TenPow<uint32_t, 6>::value;
CASEW(6);
case 10 ... 99:
*(uint32_t *)m_c = pre.m_data[x * 100];
m_c += 2;
break;
CASEW(9);
CASEW(5);
case 0 ... 9:
*m_c++ = '0' + x;
break;
CASEW(8);
case 1000 ... 9999:
*(uint32_t *)m_c = pre.m_data[x];
m_c += 4;
break;
CASEW(7);
case 100 ... 999:
*(uint32_t *)m_c = pre.m_data[x * 10];
m_c += 3;
break;
}
#undef CASEW
return *this;
}
OutputHelper &operator<<(int64_t x) {
if (x >= 0)
return (*this) << uint64_t(x);
else
return (*this) << '-' << uint64_t(-x);
}
OutputHelper &operator<<(int32_t x) {
if (x >= 0)
return (*this) << uint32_t(x);
else
return (*this) << '-' << uint32_t(-x);
}
};
}
}
#endif
/*
lib code is above
temp code is below
*/
static constexpr uint32_t N = 200000;
struct node {
uint32_t a, b;
} arr[N];
uint64_t res[N];
using Tree1 = OY::PerSeg::Tree<OY::PerSeg::BaseNode<uint32_t>, OY::PerSeg::Ignore, false, false, uint32_t, 1 << 25>;
using Tree2 = OY::PerSeg::Tree<OY::PerSeg::BaseNode<uint64_t>, OY::PerSeg::Ignore, false, false, uint32_t, 1 << 25>;
Tree1 S1[N + 1];
Tree2 S2[N + 1];
void solve_perseg() {
uint32_t n;
cin >> n;
uint32_t maxa = 0;
for (uint32_t i = 0; i < n; i++) cin >> arr[i].a >> arr[i].b, maxa = std::max(maxa, arr[i].a);
std::sort(arr, arr + n, [](auto &x, auto &y) { return x.b < y.b; });
S1[0].resize(maxa + 1);
for (uint32_t i = 1; i <= n; i++) (S1[i] = S1[i - 1].copy()).add(arr[i - 1].a, 1);
S2[0].resize(maxa + 1);
for (uint32_t i = 1; i <= n; i++) (S2[i] = S2[i - 1].copy()).add(arr[i - 1].a, arr[i - 1].a);
auto getsum = [&](uint32_t last, uint32_t k) -> uint64_t {
if (last + 1 < k) return UINT64_MAX / 2;
if (k == 1) return arr[last].a + arr[last].b;
uint32_t mx = S1[last].kth(k - 1);
auto cnt = mx ? S1[last].query(0, mx - 1) : 0;
uint64_t sum = (mx ? S2[last].query(0, mx - 1) : 0) + mx * (k - 1 - cnt);
return sum + arr[last].a + arr[last].b;
};
auto dfs = [&](auto self, uint32_t l, uint32_t lpos, uint32_t r, uint32_t rpos) -> void {
if (l >= r) return;
uint32_t mid = (l + r) >> 1, pos;
res[mid] = UINT64_MAX / 2;
for (uint32_t i = lpos; i != rpos; i++) {
auto sum = getsum(i, mid + 1);
if (sum < res[mid]) res[mid] = sum, pos = i;
}
self(self, l, lpos, mid, pos + 1);
self(self, mid + 1, pos, r, rpos);
};
dfs(dfs, 0, 0, n, n);
for (uint32_t k = 0; k < n; k++) cout << res[k] << '\n';
}
int main() {
solve_perseg();
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5884kb
input:
3 2 5 4 3 3 7
output:
7 11 16
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 1379ms
memory: 184000kb
input:
200000 466436993 804989151 660995237 756645598 432103296 703610564 6889895 53276988 873617076 822481192 532911431 126844295 623111499 456772252 937464699 762157133 708503076 786039753 78556972 5436013 582960979 398984169 786333369 325119902 930705057 615928139 924915828 506145001 164984329 208212435...
output:
1318594 3208018 5570526 7340845 9223347 11149865 12332210 13476823 14788280 16172895 17768627 19336633 20693779 22005236 23389851 25073157 26760338 28509336 30294967 32093959 33976461 35893858 37754030 39588384 41470886 43388283 45309771 47309654 48837539 50417767 52079411 53762717 55190044 56577630...
result:
ok 200000 lines
Test #3:
score: 0
Accepted
time: 1363ms
memory: 184060kb
input:
200000 847759212 808195187 499393947 158845704 286713001 829058634 347836790 268095042 525802369 342098012 260721485 611292083 95451146 853465743 666288241 921988396 958024432 522176958 284971271 952579505 408975858 657474613 444942472 596256250 291446883 538551864 942712385 142670067 239468458 9590...
output:
1398661 1990331 2912658 4186260 5510021 7421286 8925937 10233209 11427663 12466304 13739906 15048281 16438721 17917204 19556134 21034617 22945882 24964675 27046288 28988324 30624067 32102550 33629849 35258767 36683909 38129744 39608227 41135526 42764444 44559165 46466041 48377306 49860205 51250645 5...
result:
ok 200000 lines
Test #4:
score: 0
Accepted
time: 1412ms
memory: 184008kb
input:
200000 453045091 809721921 853476741 595698118 218851090 887561745 864896419 760665890 291906050 833777661 706333418 479486544 207093005 36386646 969262171 137545723 501777026 470632513 238108337 821895650 757244578 277013047 715147479 651214680 995278884 359331973 20441197 903583173 61588145 378817...
output:
1629450 3451675 5862264 7342961 8475016 9707673 11350240 13021035 14824028 16466595 18145506 19755199 21397766 23219991 25058891 26869771 28383182 29992875 31635442 33457667 35296567 37269548 39205891 41028116 42867016 44839997 46268352 47600752 48988255 50421419 51854715 53368126 54897681 56507374 ...
result:
ok 200000 lines
Test #5:
score: 0
Accepted
time: 852ms
memory: 128956kb
input:
200000 724371 812164590 786885 853213841 375367 446887348 442587 266053048 910413 644441954 304737 493015342 449866 304716006 711453 152694644 405700 232509173 921335 223801102 979624 725734275 524990 894904581 975621 908452940 211492 159635302 996047 882815311 201533 598711233 152477 256633677 9411...
output:
112065 210146 299616 337074 391448 445884 500608 562757 637222 714160 812241 882389 944538 1019003 1095941 1179290 1276070 1329394 1383830 1438554 1500703 1564162 1638627 1715565 1798914 1886244 1975154 2064372 2159112 2230385 2293760 2357219 2421075 2486440 2560905 2636978 2713916 2797265 2883902 2...
result:
ok 200000 lines
Test #6:
score: 0
Accepted
time: 623ms
memory: 110988kb
input:
200000 82260 816973645 63190 30304976 15365 98123005 79313 698909248 88351 460688945 45258 145977968 35624 362819795 34062 929296068 13142 373585892 93631 33870837 47414 576582646 25940 764754575 8424 255583152 73559 151261046 51329 935294030 89414 108264540 14984 966447646 70866 477634636 7290 9827...
output:
13886 30185 60597 84857 106218 121551 137850 159549 187975 207878 228613 247795 267766 282648 297981 314280 332886 353621 374388 396087 418706 437819 458554 479321 499571 520306 541073 562772 582630 603365 624132 645831 668408 688579 709314 730081 751780 774399 798048 821818 847209 872827 901523 930...
result:
ok 200000 lines
Test #7:
score: 0
Accepted
time: 367ms
memory: 92596kb
input:
200000 1286 819121925 8997 273901462 8502 181755051 7515 175443695 5821 856272297 7390 111029219 5073 269357259 1581 35806553 7694 913461554 8300 307364045 8256 33038036 5700 229695181 250 919848697 7280 624783228 434 719961279 1232 128882963 8258 924021143 3834 843971163 5625 811204037 1492 2383695...
output:
10995 13359 18477 23804 38945 55481 60947 66065 70271 75389 80027 84800 89342 93179 97100 101148 106126 111244 116478 121825 128995 137178 145792 155005 164337 174083 183478 191218 197417 203657 211242 219019 226857 233378 240963 248740 256578 264569 272752 280960 289628 298655 306432 314270 322261 ...
result:
ok 200000 lines
Test #8:
score: 0
Accepted
time: 172ms
memory: 73800kb
input:
200000 567 821597362 373 531417185 779 814789710 275 754605445 952 666936589 710 124558017 702 537686619 862 50955474 368 675370982 298 782978552 302 481759264 979 473352314 43 395227840 286 954544414 336 150250305 150 259994546 687 928911202 544 406240134 464 667581860 838 887654894 448 771976144 6...
output:
2235 2529 8117 9377 11127 12070 13052 14782 17841 27938 30643 32380 33341 34322 35554 40606 41587 48349 49885 50880 55974 61036 62947 63942 65127 67401 71096 73392 83699 85485 91937 97919 99466 100691 109601 116546 117649 119086 120067 121062 123036 127602 135828 136809 137804 139170 140993 143831 1...
result:
ok 200000 lines
Test #9:
score: 0
Accepted
time: 585ms
memory: 184116kb
input:
200000 342509701 342369477 832528915 833461380 305083321 305636073 97787821 97798679 401112695 400166019 206883814 207488357 445079803 443330686 821303339 823004195 951351563 950383862 236686106 237217287 770566641 771324127 877496005 877642151 663255937 664202372 135673848 136103612 150951930 15070...
output:
4774 13192 28262 41294 54737 69177 87401 108979 136735 171516 203369 235932 272900 312322 349380 390783 439807 483352 532557 582602 633629 687385 738524 790936 844462 900935 961981 1024307 1084112 1146567 1211897 1274425 1338357 1406537 1479843 1556923 1633866 1711704 1791657 1881450 1970659 2062277...
result:
ok 200000 lines
Test #10:
score: 0
Accepted
time: 1753ms
memory: 184000kb
input:
200000 424022414 503814435 806902283 120847887 159591289 767965342 995943523 2143610 92544520 834485542 527264427 400514062 828167614 99803183 413473955 513851792 24326747 951399406 6268451 987557869 6272849 987547914 870148328 65988204 303041365 624808224 484331263 443537008 37039932 926091659 4153...
output:
925350356 999391812 999994451 1000006025 1000021200 1000037835 1000056852 1000076740 1000097083 1000120901 1000147884 1000181988 1000216572 1000251650 1000286776 1000323768 1000366528 1000422287 1000481162 1000540533 1000608040 1000675799 1000746490 1000821377 1000897452 1000976676 1001058192 100114...
result:
ok 200000 lines
Test #11:
score: 0
Accepted
time: 1332ms
memory: 147572kb
input:
200000 9759806 12862172 8415499 95736535 1664414 820629803 7565617 186586129 261111 972339624 7956621 143743367 6294429 322756312 4413454 523200143 3368006 635522804 7403517 204183948 608424 934830718 4422409 522274240 1913974 793736435 8057121 133077799 5980092 355887936 3993010 567818961 4942527 4...
output:
10000783 20011188 30022081 40022551 50024199 60026734 70028178 80028243 90028965 100046652 110055224 120055198 130055194 140057106 150062462 160062436 170062432 180064899 190064522 200064261 210064094 220063840 230063579 240063412 250063301 260063275 270063271 280063802 290064997 300063037 310060827...
result:
ok 200000 lines
Test #12:
score: 0
Accepted
time: 1023ms
memory: 128924kb
input:
200000 496345 466577657 386215 586183375 35313 961776167 224787 757007012 129801 860004317 534510 426004787 538049 421998089 582677 373345535 638985 313251583 440542 527987482 314859 661869183 464254 501661850 381786 590849519 336796 638644881 436826 532036806 967339 17549076 948496 27686222 435981 ...
output:
1002712 2004799 3009688 4018445 5020295 6024231 7024510 8027273 9033770 10033936 11035128 12037972 13041280 14044477 15046153 16047926 17051947 18054285 19055635 20058952 21060245 22064572 23064761 24066353 25066487 26068892 27069602 28071028 29071938 30075808 31076639 32077776 33081667 34082393 350...
result:
ok 200000 lines
Test #13:
score: 0
Accepted
time: 590ms
memory: 110784kb
input:
200000 15216 836840562 70964 236430015 63200 319769248 72638 218445383 50711 453882897 7142 922491104 31371 662544679 60197 352769322 41403 554098222 76954 173314909 83661 102670370 92697 39042364 10030 892110253 39376 576601232 48265 480542224 74934 195010760 92547 39963180 7838 915208475 81256 128...
output:
104238 207651 309282 409662 510001 616589 720325 821076 925357 1030343 1131525 1232102 1332478 1433483 1538744 1642201 1747262 1847472 1947556 2047760 2154162 2255836 2355863 2457381 2557722 2657969 2757985 2861246 2968808 3073504 3180373 3284338 3388918 3489105 3589161 3692633 3794227 3904391 40047...
result:
ok 200000 lines
Test #14:
score: 0
Accepted
time: 321ms
memory: 92612kb
input:
200000 4678 497931091 2640 716453432 6128 342231079 8613 73961599 6966 252076583 3235 652413490 6687 281932985 5435 417357447 8145 123716301 1029 890108476 8087 130103799 9604 21356741 3855 586162704 3077 669287066 6905 258832414 8309 106104565 9921 4362813 4232 545009314 5371 423589629 3869 5846781...
output:
14579 25122 38514 54746 65555 76413 99719 113491 128752 140022 153279 167111 179004 192410 202723 215381 226126 236576 247249 257830 267919 280431 294595 304934 315546 328726 341429 358430 371825 382901 394180 405288 417371 431424 442612 453822 473579 493771 503880 521850 533608 544570 556337 568376...
result:
ok 200000 lines
Test #15:
score: 0
Accepted
time: 179ms
memory: 73808kb
input:
200000 27 972604774 156 832885943 161 827754255 877 67082798 943 31056414 243 740861264 60 937391032 229 756995050 222 763374572 716 231870198 445 522461729 509 452792900 588 369495498 661 290499149 818 122716973 63 933851278 128 863054306 528 431656637 270 710563993 979 12062387 276 703934949 483 4...
output:
6882 15009 18343 26780 28171 30634 48686 50820 57412 58718 60404 61525 68888 74001 75071 77154 78786 80464 88174 91233 94246 95615 97463 103806 106975 110006 113520 115308 123130 128798 137120 140594 142982 145385 146791 148761 155966 158695 162930 164268 165619 166792 170367 172525 176505 178059 18...
result:
ok 200000 lines
Test #16:
score: 0
Accepted
time: 124ms
memory: 55840kb
input:
200000 11 892126160 2 986862649 83 118159385 50 474606235 30 681179212 92 43004615 77 181587331 94 33800665 26 726163332 19 800955104 7 933100010 9 911106127 32 663731276 58 382884421 78 172731234 41 568328829 67 290835641 49 480293195 13 861453787 21 784813797 28 708545692 79 159193875 83 113012768...
output:
317 11873 13115 14025 14330 14983 19602 27044 28254 28746 32462 33642 38161 42404 44581 48582 49445 50652 55013 56448 61812 61939 62720 63555 64046 68780 72247 75938 77932 79081 81666 83359 85092 88610 92584 93935 101257 109306 111290 117823 119842 121331 123366 124841 124962 128531 135178 136626 13...
result:
ok 200000 lines