QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#42305 | #4428. Fence | antiravel | AC ✓ | 298ms | 66068kb | C++23 | 9.6kb | 2022-08-01 21:14:29 | 2022-08-01 21:14:30 |
Judging History
answer
#include <algorithm>
#include <bitset>
#include <cinttypes>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
namespace impl
{
inline void force_templates()
{
#define FORCE(type) \
{ \
[[maybe_unused]] auto f = [] type {}; \
}
FORCE((std::pair<int, int>))
FORCE((std::vector<int>))
FORCE((std::vector<std::pair<int, int>>))
#undef FORCE
}
} // namespace impl
#include <iostream>
#include <iterator>
#include <string>
#include <tuple>
#include <utility>
namespace cm
{
class logger
{
public:
logger(std::ostream &) {}
logger &set_ostream(std::ostream &)
{
return *this;
}
logger &set_sep(const std::string &)
{
return *this;
}
logger &assert_push_enable()
{
return *this;
}
logger &assert_push_disable()
{
return *this;
}
logger &assert_exit()
{
return *this;
}
logger &assert_noexit()
{
return *this;
}
logger &endl()
{
return *this;
}
template <class... T>
logger &log(T...)
{
return *this;
}
template <class T>
logger &hint(T...)
{
return *this;
}
template <class... T>
logger &operator()(T...)
{
return *this;
}
template <class... T>
logger &assert_(T...)
{
return *this;
}
};
namespace impl
{
logger cm_logger(std::cout);
}
} // namespace cm
// clang-format off
#define see(...)
#define asee(...)
#define cm_assert(...)
// clang-format on
// #include "/home/jack/cm/intm.hpp"
// #include "/home/jack/cm/math_util.hpp"
#include <cctype>
#include <cstdio>
namespace cm
{
template <class _Type, size_t _buf_size>
class buffer_reader
{
protected:
FILE *src;
_Type *const buff;
_Type *buff_end;
_Type *buff_pos;
void _flush()
{
buff_end = buff + fread(buff, sizeof(_Type), _buf_size, src);
buff_pos = buff;
if (buff_end == buff)
{
*buff_end = '\n';
buff_end++;
}
}
public:
explicit buffer_reader(FILE *_src) : src(_src), buff(new _Type[_buf_size])
{
_flush();
}
buffer_reader(const buffer_reader &) = delete;
buffer_reader(buffer_reader &&) = delete;
buffer_reader &operator=(const buffer_reader &) = delete;
buffer_reader &operator=(buffer_reader &&) = delete;
_Type get() const
{
return *buff_pos;
}
_Type next()
{
_Type result = get();
buff_pos++;
if (buff_pos == buff_end)
_flush();
return result;
}
~buffer_reader()
{
if (src != stdin)
fclose(src);
delete[] buff;
}
};
template <class _BufferReader>
class scanner : protected _BufferReader
{
private:
using _BufferReader::get;
using _BufferReader::next;
inline bool _is_ws(char c)
{
return c <= ' ';
}
inline bool _is_cr(char c)
{
return c == '\n' || c == '\r';
}
int _get_sign()
{
while (!isdigit(get()) && get() != '-')
next();
if (get() == '-')
return next(), -1;
return 1;
}
public:
scanner() = delete;
using _BufferReader::_BufferReader;
char next_char()
{
while (_is_ws(get()))
next();
return next();
}
char *next_token(char *s)
{
while (_is_ws(get()))
next();
while (!_is_ws(get()))
*s++ = next();
*s = '\0';
return s;
}
char *next_line(char *s)
{
while (_is_ws(get()))
next();
while (!_is_cr(get()))
*s++ = next();
*s = '\0';
return s;
}
template <class _Integer>
_Integer next_integer()
{
_Integer sign = _get_sign();
_Integer result(0);
while (isdigit(get()))
result = result * _Integer(10) + _Integer(next() - '0');
return sign * result;
}
int next_int()
{
return next_integer<int>();
}
long long next_long()
{
return next_integer<long long>();
}
double next_double()
{
int sign = _get_sign();
double result = 0;
while (isdigit(get()))
result = result * 10 + (next() - '0');
if (get() == '.')
{
next();
double cur_ep = 0.1;
while (isdigit(get()))
result += cur_ep * (next() - '0'), cur_ep *= 0.1;
}
return sign * result;
}
};
} // namespace cm
namespace cm
{
using optimal_reader = buffer_reader<char, 1 << 16>;
}
#define DEFINE_SCANNER(sc, filename) \
cm::scanner<cm::optimal_reader> sc(fopen(filename, "r"));
// #include "/home/jack/cm/segment_tree.hpp"
// #include "/home/jack/cm/string.hpp"
#include <array>
#include <iterator>
#include <type_traits>
#include <utility>
#include <vector>
namespace cm
{
template <class T>
inline bool check_min(T &a, const T &b)
{
return b < a ? a = b, 1 : 0;
}
template <class T>
inline bool check_max(T &a, const T &b)
{
return a < b ? a = b, 1 : 0;
}
struct once_t
{
bool _once = true;
bool operator()()
{
return _once ? (_once = false, true) : false;
}
};
template <class T, class vt = std::vector<std::vector<T>>>
vt vec_transpose(const vt &v)
{
size_t n = v.size();
size_t m = v[0].size();
vt r(m, std::vector<T>(n));
for (size_t i = 0; i < n; i++)
for (size_t j = 0; j < m; j++)
r[j][i] = v[i][j];
return r;
}
template <class value_type = int>
struct counter_t
{
private:
value_type _value{};
public:
value_type operator()()
{
return _value++;
}
value_type size() const
{
return _value;
}
void clear()
{
_value = value_type{};
}
};
namespace impl
{
template <class T, std::size_t n0, std::size_t... n1>
struct __array
{
using type = std::array<typename __array<T, n1...>::type, n0>;
};
template <class T, std::size_t n0>
struct __array<T, n0>
{
using type = std::array<T, n0>;
};
} // namespace impl
template <class T, std::size_t... n0>
using array = typename impl::__array<T, n0...>::type;
#if __cplusplus >= 201402L
template <class F>
struct y_combinate_t
{
F f;
template <class... Args>
decltype(auto) operator()(Args &&...args) const
{
return f(*this, std::forward<Args>(args)...);
}
};
template <class F>
y_combinate_t<std::decay_t<F>> y_combinate(F &&f)
{
return {std::forward<F>(f)};
};
auto vec_take(size_t id)
{
return [id](const auto &v) { return v[id]; };
}
template <class F, class... T>
auto vec_map(F &&f, const std::vector<T> &...v)
{
using mapped_t = decltype(f(std::declval<T>()...));
std::size_t n = [](auto x, auto...) { return x; }(v.size()...);
std::vector<mapped_t> r;
r.reserve(n);
cm::y_combinate([&](auto &&self, std::size_t cnt, auto... its) -> void {
if (cnt > 0)
{
r.emplace_back(f((*its)...));
self(cnt - 1, std::next(its)...);
}
})(n, v.begin()...);
return r;
}
template <class F>
auto mapper(F &&f)
{
return [f](auto v) { return vec_map(f, v); };
}
template <class T>
auto transfer(T &&v)
{
return std::forward<T>(v);
}
template <class T, class F0, class... F1>
auto transfer(T &&v, F0 &&f0, F1 &&...f1)
{
return transfer(f0(std::forward<T>(v)), f1...);
}
#endif
} // namespace cm
using cm::check_max;
using cm::check_min;
#define CONSTRAINT(n, a, b) constexpr auto n = a;
#include <algorithm>
#include <vector>
cm::scanner<cm::optimal_reader> sc(stdin);
int main()
{
int t = sc.next_int();
for (int i = 0; i < t; i++)
{
int n = sc.next_int();
std::vector<int> as(n);
for (int i = 0; i < n; i++)
as[i] = sc.next_int();
int m = *std::max_element(as.begin(), as.end()) + 1;
auto [first_hop, next_hop] = [&] {
std::vector<int> last(m, n);
std::vector<std::vector<int>> a(n);
for (int i = n - 1; i >= 0; i--)
{
a[i] = {last.begin(), last.begin() + as[i]};
std::fill(last.begin(), last.begin() + as[i], i);
}
return std::make_pair(std::move(last), std::move(a));
}();
auto pre2_sum = [&] {
std::vector<int> a(n + 2);
a[n + 1] = 0;
a[n] = 0;
for (int i = n - 1; i >= 0; i--)
a[i] = as[i] + a[i + 2];
return a;
}();
for (int thr = 1; thr < m; thr++)
{
int cb = 0;
int cs = 0;
auto trans_below = [&](int l, int r) {
int il = l + cb;
int ir = (r % 2 == il % 2) ? r : r + 1;
cs += pre2_sum[il] - pre2_sum[ir];
cb = ir - r;
};
auto trans_above = cm::y_combinate([&](auto &&self, int v) -> void {
if (cb == 1)
{
cb = 0;
self(v - thr);
}
else
{
int vq = (v - 1) / thr;
cs += ((vq + 1) / 2) * thr;
if (vq % 2 == 0)
{
cs += (v - 1) % thr + 1;
cb = 1;
}
else
{
cb = 0;
}
}
});
int p = first_hop[thr];
trans_below(0, p);
for (; p != n; p = next_hop[p][thr])
{
// see(p);
trans_above(as[p]);
trans_below(p + 1, next_hop[p][thr]);
}
printf("%d\n", cs);
}
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 298ms
memory: 28664kb
input:
5 333834 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
output:
500000 500000 499995 499987 500000 500032 499996 499987 500032 500000 499994 499998 499981 499996 500080 500090 500077 500032 499980 499915 500035 499941 500055 499923 500000 499980 499935 500042 500174 499905 500002 499998 500218 499899 499965 500010 500144 500242 499839 499915 499987 500010 500122...
result:
ok 2500000 lines
Test #2:
score: 0
Accepted
time: 141ms
memory: 13652kb
input:
5 48356 1 1 2 2 1 1 1 1 2 4 8 4 1 2 128 4 1 1 2 1 1 2 2 1 1 1 4 1 1 1 2 1 2 8 8 1 1 1 1 8 1 2 1 2 1 1 1 1 8 1 2 1 2 1 2 1 2 1 1 8 1 2 4 1 1 1 1 1 4 1 2 1 1 1 2 1 2 64 1 256 1 1 1 1 1 2 32 1 1 2 1 1 2 2 1 1 1 1 1 1 4 1 1 2 2 1 1 1 1 1 1 2 1 2 256 4 1 1 2 1 2 1 2 2 1 1 2 2 2 2 1 1 1 2 1 32 1 1 1 4 1 1...
output:
500000 499939 500012 499925 499701 499996 499780 499879 500247 499914 500226 500164 500084 500054 499449 499819 500132 500378 500533 500517 499941 499527 500493 500808 500635 499680 500903 500128 500111 500413 499462 500244 500233 499885 499983 500105 499925 500185 499961 499466 500376 500081 498569...
result:
ok 987898 lines
Test #3:
score: 0
Accepted
time: 133ms
memory: 15128kb
input:
5 100000 1 10 9 6 2 9 5 8 6 8 3 10 10 4 8 10 5 4 8 1 3 3 10 6 8 2 1 1 7 4 4 7 3 3 2 7 3 8 4 8 8 8 9 7 1 6 7 5 1 6 5 6 10 7 1 7 10 4 9 6 7 3 4 2 7 7 8 9 7 1 8 4 1 6 10 1 3 8 8 5 6 4 10 5 10 3 4 1 8 2 8 4 6 1 7 2 10 2 2 3 3 3 4 6 6 6 6 7 8 8 8 9 9 9 9 9 10 10 4 5 10 3 1 5 6 7 9 5 3 2 2 3 1 2 1 6 1 1 6...
output:
275038 275208 276333 274460 274715 278680 279579 271029 278720 274871 251536 251586 251550 251533 251687 251362 251680 251736 251758 251640 252228 251127 251367 250702 251853 250779 250632 250725 251045 251774 251515 249096 250101 253104 247732 248767 248976 249529 253658 252323 252069 251541 251651...
result:
ok 1010971 lines
Test #4:
score: 0
Accepted
time: 203ms
memory: 66068kb
input:
5 1413 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 1...
output:
499496 499496 499494 499848 499491 500202 499487 500553 499498 500905 499497 501264 499498 501599 499446 501961 499443 502306 499413 502649 499443 503017 499414 503329 499499 503710 499498 504049 499501 504360 499310 504777 499233 505155 499499 505440 499170 505761 499498 506160 499091 506583 499505...
result:
ok 502830 lines
Test #5:
score: 0
Accepted
time: 2ms
memory: 3628kb
input:
5 1 1 1 3 2 1 1 2 1 2 2 3 1
output:
1 2 2 3 1 2 1 2 3 3
result:
ok 10 lines
Extra Test:
score: 0
Extra Test Passed