QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#106530 | #5249. Bandits | maspy | AC ✓ | 1067ms | 66048kb | C++23 | 30.9kb | 2023-05-18 00:23:17 | 2023-05-18 00:23:19 |
Judging History
answer
#line 1 "library/my_template.hpp"
#if defined(LOCAL)
#include <my_template_compiled.hpp>
#else
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using u32 = unsigned int;
using u64 = unsigned long long;
using i128 = __int128;
template <class T>
constexpr T infty = 0;
template <>
constexpr int infty<int> = 1'000'000'000;
template <>
constexpr ll infty<ll> = ll(infty<int>) * infty<int> * 2;
template <>
constexpr u32 infty<u32> = infty<int>;
template <>
constexpr u64 infty<u64> = infty<ll>;
template <>
constexpr i128 infty<i128> = i128(infty<ll>) * infty<ll>;
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); }
// (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, typename U>
T ceil(T x, U y) {
return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U>
T floor(T x, U y) {
return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T, typename U>
pair<T, T> divmod(T x, U y) {
T q = floor(x, y);
return {q, x - q * y};
}
template <typename T, typename U>
T SUM(const vector<U> &A) {
T sum = 0;
for (auto &&a: A) sum += a;
return sum;
}
#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define LB(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define UB(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define UNIQUE(x) \
sort(all(x)), x.erase(unique(all(x)), x.end()), 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) {
assert(!que.empty());
T a = que.top();
que.pop();
return a;
}
template <typename T>
T POP(vc<T> &que) {
assert(!que.empty());
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;
tie(ok, ng) = (check(x) ? mp(x, ng) : mp(ok, x));
}
return ok;
}
template <typename F>
double binary_search_real(F check, double ok, double ng, int iter = 100) {
FOR(iter) {
double x = (ok + ng) / 2;
tie(ok, ng) = (check(x) ? mp(x, ng) : mp(ok, x));
}
return (ok + ng) / 2;
}
template <class T, class S>
inline bool chmax(T &a, const S &b) {
return (a < b ? a = b, 1 : 0);
}
template <class T, class S>
inline bool chmin(T &a, const S &b) {
return (a > b ? a = b, 1 : 0);
}
// ? は -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;
}
#endif
#line 1 "library/other/io.hpp"
// based on yosupo's fastio
#include <unistd.h>
namespace fastio {
#define FASTIO
// クラスが read(), print() を持っているかを判定するメタ関数
struct has_write_impl {
template <class T>
static auto check(T &&x) -> decltype(x.write(), std::true_type{});
template <class T>
static auto check(...) -> std::false_type;
};
template <class T>
class has_write : public decltype(has_write_impl::check<T>(std::declval<T>())) {
};
struct has_read_impl {
template <class T>
static auto check(T &&x) -> decltype(x.read(), std::true_type{});
template <class T>
static auto check(...) -> std::false_type;
};
template <class T>
class has_read : public decltype(has_read_impl::check<T>(std::declval<T>())) {};
struct Scanner {
FILE *fp;
char line[(1 << 15) + 1];
size_t st = 0, ed = 0;
void reread() {
memmove(line, line + st, ed - st);
ed -= st;
st = 0;
ed += fread(line + ed, 1, (1 << 15) - ed, fp);
line[ed] = '\0';
}
bool succ() {
while (true) {
if (st == ed) {
reread();
if (st == ed) return false;
}
while (st != ed && isspace(line[st])) st++;
if (st != ed) break;
}
if (ed - st <= 50) {
bool sep = false;
for (size_t i = st; i < ed; i++) {
if (isspace(line[i])) {
sep = true;
break;
}
}
if (!sep) reread();
}
return true;
}
template <class T, enable_if_t<is_same<T, string>::value, int> = 0>
bool read_single(T &ref) {
if (!succ()) return false;
while (true) {
size_t sz = 0;
while (st + sz < ed && !isspace(line[st + sz])) sz++;
ref.append(line + st, sz);
st += sz;
if (!sz || st != ed) break;
reread();
}
return true;
}
template <class T, enable_if_t<is_integral<T>::value, int> = 0>
bool read_single(T &ref) {
if (!succ()) return false;
bool neg = false;
if (line[st] == '-') {
neg = true;
st++;
}
ref = T(0);
while (isdigit(line[st])) { ref = 10 * ref + (line[st++] & 0xf); }
if (neg) ref = -ref;
return true;
}
template <typename T,
typename enable_if<has_read<T>::value>::type * = nullptr>
inline bool read_single(T &x) {
x.read();
return true;
}
bool read_single(double &ref) {
string s;
if (!read_single(s)) return false;
ref = std::stod(s);
return true;
}
bool read_single(char &ref) {
string s;
if (!read_single(s) || s.size() != 1) return false;
ref = s[0];
return true;
}
template <class T>
bool read_single(vector<T> &ref) {
for (auto &d: ref) {
if (!read_single(d)) return false;
}
return true;
}
template <class T, class U>
bool read_single(pair<T, U> &p) {
return (read_single(p.first) && read_single(p.second));
}
template <size_t N = 0, typename T>
void read_single_tuple(T &t) {
if constexpr (N < std::tuple_size<T>::value) {
auto &x = std::get<N>(t);
read_single(x);
read_single_tuple<N + 1>(t);
}
}
template <class... T>
bool read_single(tuple<T...> &tpl) {
read_single_tuple(tpl);
return true;
}
void read() {}
template <class H, class... T>
void read(H &h, T &... t) {
bool f = read_single(h);
assert(f);
read(t...);
}
Scanner(FILE *fp) : fp(fp) {}
};
struct Printer {
Printer(FILE *_fp) : fp(_fp) {}
~Printer() { flush(); }
static constexpr size_t SIZE = 1 << 15;
FILE *fp;
char line[SIZE], small[50];
size_t pos = 0;
void flush() {
fwrite(line, 1, pos, fp);
pos = 0;
}
void write(const char val) {
if (pos == SIZE) flush();
line[pos++] = val;
}
template <class T, enable_if_t<is_integral<T>::value, int> = 0>
void write(T val) {
if (pos > (1 << 15) - 50) flush();
if (val == 0) {
write('0');
return;
}
if (val < 0) {
write('-');
val = -val; // todo min
}
size_t len = 0;
while (val) {
small[len++] = char(0x30 | (val % 10));
val /= 10;
}
for (size_t i = 0; i < len; i++) { line[pos + i] = small[len - 1 - i]; }
pos += len;
}
void write(const string s) {
for (char c: s) write(c);
}
void write(const char *s) {
size_t len = strlen(s);
for (size_t i = 0; i < len; i++) write(s[i]);
}
void write(const double x) {
ostringstream oss;
oss << fixed << setprecision(15) << x;
string s = oss.str();
write(s);
}
void write(const long double x) {
ostringstream oss;
oss << fixed << setprecision(15) << x;
string s = oss.str();
write(s);
}
template <typename T,
typename enable_if<has_write<T>::value>::type * = nullptr>
inline void write(T x) {
x.write();
}
template <class T>
void write(const vector<T> val) {
auto n = val.size();
for (size_t i = 0; i < n; i++) {
if (i) write(' ');
write(val[i]);
}
}
template <class T, class U>
void write(const pair<T, U> val) {
write(val.first);
write(' ');
write(val.second);
}
template <size_t N = 0, typename T>
void write_tuple(const T t) {
if constexpr (N < std::tuple_size<T>::value) {
if constexpr (N > 0) { write(' '); }
const auto x = std::get<N>(t);
write(x);
write_tuple<N + 1>(t);
}
}
template <class... T>
bool write(tuple<T...> tpl) {
write_tuple(tpl);
return true;
}
template <class T, size_t S>
void write(const array<T, S> val) {
auto n = val.size();
for (size_t i = 0; i < n; i++) {
if (i) write(' ');
write(val[i]);
}
}
void write(i128 val) {
string s;
bool negative = 0;
if (val < 0) {
negative = 1;
val = -val;
}
while (val) {
s += '0' + int(val % 10);
val /= 10;
}
if (negative) s += "-";
reverse(all(s));
if (len(s) == 0) s = "0";
write(s);
}
};
Scanner scanner = Scanner(stdin);
Printer printer = Printer(stdout);
void flush() { printer.flush(); }
void print() { printer.write('\n'); }
template <class Head, class... Tail>
void print(Head &&head, Tail &&... tail) {
printer.write(head);
if (sizeof...(Tail)) printer.write(' ');
print(forward<Tail>(tail)...);
}
void read() {}
template <class Head, class... Tail>
void read(Head &head, Tail &... tail) {
scanner.read(head);
read(tail...);
}
} // namespace fastio
using fastio::print;
using fastio::flush;
using fastio::read;
#define INT(...) \
int __VA_ARGS__; \
read(__VA_ARGS__)
#define LL(...) \
ll __VA_ARGS__; \
read(__VA_ARGS__)
#define STR(...) \
string __VA_ARGS__; \
read(__VA_ARGS__)
#define CHAR(...) \
char __VA_ARGS__; \
read(__VA_ARGS__)
#define DBL(...) \
double __VA_ARGS__; \
read(__VA_ARGS__)
#define VEC(type, name, size) \
vector<type> name(size); \
read(name)
#define VV(type, name, h, w) \
vector<vector<type>> name(h, vector<type>(w)); \
read(name)
void YES(bool t = 1) { print(t ? "YES" : "NO"); }
void NO(bool t = 1) { YES(!t); }
void Yes(bool t = 1) { print(t ? "Yes" : "No"); }
void No(bool t = 1) { Yes(!t); }
void yes(bool t = 1) { print(t ? "yes" : "no"); }
void no(bool t = 1) { yes(!t); }
#line 3 "main.cpp"
#line 2 "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 {
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; }
constexpr bool is_directed() { return directed; }
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;
}
// 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();
}
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];
}
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);
}
}
// G における頂点 V[i] が、新しいグラフで i になるようにする
Graph<T, directed> rearrange(vc<int> V) {
int n = len(V);
map<int, int> MP;
FOR(i, n) MP[V[i]] = i;
Graph<T, directed> G(n);
for (auto&& e: edges) {
if (MP.count(e.frm) && MP.count(e.to)) {
G.add(MP[e.frm], MP[e.to], e.cost);
}
}
G.build();
return G;
}
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 2 "library/graph/centroid.hpp"
// (v,w) or (v,-1)
template <typename GT>
pair<int, int> find_centroids(GT& G) {
int N = G.N;
vc<int> par(N, -1);
vc<int> V(N);
vc<int> sz(N);
int l = 0, r = 0;
V[r++] = 0;
while (l < r) {
int v = V[l++];
for (auto&& e: G[v])
if (e.to != par[v]) {
par[e.to] = v;
V[r++] = e.to;
}
}
FOR_R(i, N) {
int v = V[i];
sz[v] += 1;
int p = par[v];
if (p != -1) sz[p] += sz[v];
}
int M = N / 2;
auto check = [&](int v) -> bool {
if (N - sz[v] > M) return false;
for (auto&& e: G[v]) {
if (e.to != par[v] && sz[e.to] > M) return false;
}
return true;
};
pair<int, int> ANS = {-1, -1};
FOR(v, N) if (check(v)) {
if (ANS.fi != -1) {
ANS.se = v;
} else {
ANS.fi = v;
}
}
return ANS;
}
template <typename GT>
struct Centroid_Decomposition {
using edge_type = typename GT::edge_type;
GT& G;
int N;
vc<int> sz;
vc<int> par;
vector<int> cdep; // depth in centroid tree
bool calculated;
Centroid_Decomposition(GT& G)
: G(G), N(G.N), sz(G.N), par(G.N), cdep(G.N, -1) {
calculated = 0;
build();
}
private:
int find(int v) {
vc<int> V = {v};
par[v] = -1;
int p = 0;
while (p < len(V)) {
int v = V[p++];
sz[v] = 0;
for (auto&& e: G[v]) {
if (e.to == par[v] || cdep[e.to] != -1) continue;
par[e.to] = v;
V.eb(e.to);
}
}
while (len(V)) {
int v = V.back();
V.pop_back();
sz[v] += 1;
if (p - sz[v] <= p / 2) return v;
sz[par[v]] += sz[v];
}
return -1;
}
void build() {
assert(G.is_prepared());
assert(!G.is_directed());
assert(!calculated);
calculated = 1;
vc<pair<int, int>> st;
st.eb(0, 0);
while (!st.empty()) {
auto [lv, v] = st.back();
st.pop_back();
auto c = find(v);
cdep[c] = lv;
for (auto&& e: G[c]) {
if (cdep[e.to] == -1) { st.eb(lv + 1, e.to); }
}
}
}
public:
// vector of pairs (v, path data v)
template <typename E, typename F>
vc<vc<pair<int, E>>> collect(int root, E root_val, F f) {
vc<vc<pair<int, E>>> res = {{{root, root_val}}};
for (auto&& e: G[root]) {
int nxt = e.to;
if (cdep[nxt] < cdep[root]) continue;
vc<pair<int, E>> dat;
int p = 0;
dat.eb(nxt, f(root_val, e));
par[nxt] = root;
while (p < len(dat)) {
auto [v, val] = dat[p++];
for (auto&& e: G[v]) {
if (e.to == par[v]) continue;
if (cdep[e.to] < cdep[root]) continue;
par[e.to] = v;
dat.eb(e.to, f(val, e));
}
}
res.eb(dat);
res[0].insert(res[0].end(), all(dat));
}
return res;
}
vc<vc<pair<int, int>>> collect_dist(int root) {
auto f = [&](int x, auto e) -> int { return x + 1; };
return collect(root, 0, f);
}
// (V, H), (V[i] in G) = (i in H).
// 0,1,2... is a dfs order in H.
pair<vc<int>, Graph<typename GT::cost_type, true>> get_subgraph(int root) {
static vc<int> conv;
while (len(conv) < N) conv.eb(-1);
vc<int> V;
using cost_type = typename GT::cost_type;
vc<tuple<int, int, cost_type>> edges;
auto dfs = [&](auto& dfs, int v, int p) -> void {
conv[v] = len(V);
V.eb(v);
for (auto&& e: G[v]) {
int to = e.to;
if (to == p) continue;
if (cdep[to] < cdep[root]) continue;
dfs(dfs, to, v);
edges.eb(conv[v], conv[to], e.cost);
}
};
dfs(dfs, root, -1);
int n = len(V);
Graph<typename GT::cost_type, true> H(n);
for (auto&& [a, b, c]: edges) H.add(a, b, c);
H.build();
for (auto&& v: V) conv[v] = -1;
return {V, H};
}
};
#line 2 "library/graph/tree.hpp"
#line 4 "library/graph/tree.hpp"
// HLD euler tour をとっていろいろ。
// 木以外、非連結でも dfs 順序や親がとれる。
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 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 ELID(int v) { return 2 * LID[v] - depth[v]; }
int ERID(int v) { return 2 * RID[v] - depth[v] - 1; }
/* k: 0-indexed */
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;
}
}
// root を根とした場合の lca
int LCA_root(int u, int v, int root) {
return LCA(u, v) ^ LCA(u, root) ^ LCA(v, root);
}
int lca(int u, int v) { return LCA(u, v); }
int lca_root(int u, int v, int root) { return LCA_root(u, v, root); }
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<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;
}
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;
}
};
#line 2 "library/ds/segtree/dual_segtree.hpp"
template <typename Monoid>
struct Dual_SegTree {
using MA = Monoid;
using A = typename MA::value_type;
int n, log, size;
vc<A> laz;
Dual_SegTree() : Dual_SegTree(0) {}
Dual_SegTree(int n) { build(n); }
void build(int m) {
n = m;
log = 1;
while ((1 << log) < n) ++log;
size = 1 << log;
laz.assign(size << 1, MA::unit());
}
A get(int p) {
assert(0 <= p && p < n);
p += size;
for (int i = log; i >= 1; i--) push(p >> i);
return laz[p];
}
vc<A> get_all() {
FOR(i, size) push(i);
return {laz.begin() + size, laz.begin() + size + n};
}
void apply(int l, int r, const A& a) {
assert(0 <= l && l <= r && r <= n);
if (l == r) return;
l += size, r += size;
if (!MA::commute) {
for (int i = log; i >= 1; i--) {
if (((l >> i) << i) != l) push(l >> i);
if (((r >> i) << i) != r) push((r - 1) >> i);
}
}
while (l < r) {
if (l & 1) all_apply(l++, a);
if (r & 1) all_apply(--r, a);
l >>= 1, r >>= 1;
}
}
private:
void push(int k) {
if (laz[k] == MA::unit()) return;
all_apply(2 * k, laz[k]), all_apply(2 * k + 1, laz[k]);
laz[k] = MA::unit();
}
void all_apply(int k, A a) { laz[k] = MA::op(laz[k], a); }
};
#line 2 "library/alg/monoid/add.hpp"
template <typename X>
struct Monoid_Add {
using value_type = X;
static constexpr X op(const X &x, const X &y) noexcept { return x + y; }
static constexpr X inverse(const X &x) noexcept { return -x; }
static constexpr X power(const X &x, ll n) noexcept { return X(n) * x; }
static constexpr X unit() { return X(0); }
static constexpr bool commute = true;
};
#line 9 "main.cpp"
void solve() {
LL(N);
Graph<ll, 0> G(N);
G.read_tree(1);
LL(Q);
using T = tuple<int, int, int>;
vc<T> query;
vvc<int> VtoQ(N), EtoQ(N - 1);
FOR(q, Q) {
STR(S);
INT(idx);
--idx;
if (S == "+") {
LL(R);
query.eb(0, idx, R);
VtoQ[idx].eb(q);
} else {
query.eb(1, idx, 0);
EtoQ[idx].eb(q);
}
}
vi ANS(Q);
// query idx, query type, idx, val
using T4 = tuple<int, int, int, int>;
auto solve = [&](Graph<ll, 1> G, vc<T4> QUERY) -> void {
ll N = G.N;
vc<int> EV(N - 1);
FOR(i, N - 1) {
auto e = G.edges[i];
EV[e.id] = e.to;
}
for (auto&& [qid, t, idx, val]: QUERY)
if (t == 1) idx = EV[idx];
vi dist(N), grp(N, 0);
vvc<int> V(N);
auto dfs = [&](auto& dfs, int v, int g, ll d) -> void {
grp[v] = g, dist[v] = d;
for (auto&& e: G[v]) dfs(dfs, e.to, g, d + e.cost);
};
for (auto&& e: G[0]) dfs(dfs, e.to, e.to, e.cost);
V[0] = {0};
FOR(v, 1, N) V[0].eb(v), V[grp[v]].eb(v);
FOR(g, N) {
sort(all(V[g]),
[&](auto& a, auto& b) -> bool { return dist[a] < dist[b]; });
}
using SEG = Dual_SegTree<Monoid_Add<int>>;
vc<SEG> seg(N);
FOR(i, N) seg[i].build(len(V[i]));
vvc<ll> D(N);
FOR(g, N) for (auto&& v: V[g]) D[g].eb(dist[v]);
vc<int> IDX0(N), IDX1(N);
FOR(i, N) IDX0[V[0][i]] = i;
FOR(g, 1, N) {
FOR(i, len(V[g])) { IDX1[V[g][i]] = i; }
}
vc<int> ADD(N);
for (auto&& [qid, t, v, val]: QUERY) {
if (t == 0) {
ll x = val - dist[v];
if (x < 0) continue;
ll k = UB(D[0], x);
seg[0].apply(0, k, 1);
if (v > 0) {
int g = grp[v];
ADD[g]++;
ll k = UB(D[g], x);
seg[g].apply(0, k, 1);
}
} else {
ll ans = 0;
ans += ADD[v];
ans += seg[0].get(IDX0[v]);
int g = grp[v];
ans -= seg[g].get(IDX1[v]);
ANS[qid] += ans;
}
}
};
Centroid_Decomposition<decltype(G)> CD(G);
Tree<decltype(G)> tree(G);
vc<int> new_idx(N, -1);
FOR(root, N) {
auto [V, G1] = CD.get_subgraph(root);
FOR(i, len(V)) new_idx[V[i]] = i;
vc<T4> sub_query;
for (auto&& v: V) {
for (auto&& qid: VtoQ[v]) {
auto [a, b, c] = query[qid];
sub_query.eb(qid, 0, new_idx[v], c);
}
}
for (auto&& e: G1.edges) {
int a = V[e.frm], b = V[e.to];
int k = (tree.parent[a] == b ? tree.v_to_e(a) : tree.v_to_e(b));
for (auto&& qid: EtoQ[k]) { sub_query.eb(qid, 1, e.id, 0); }
}
FOR(i, len(V)) new_idx[V[i]] = -1;
sort(all(sub_query));
solve(G1, sub_query);
}
FOR(q, Q) {
auto [t, i, x] = query[q];
if (t == 1) print(ANS[q]);
}
}
signed main() {
solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1067ms
memory: 63604kb
input:
100000 2670 75097 4080 87477 75802 1712 51835 36626 2883 19412 25923 5852 23976 19312 2520 82536 19514 2492 27160 66601 4483 99087 15088 3504 47050 58820 2964 37063 5696 9901 7717 1496 4891 79136 5448 4340 22575 81285 9289 96280 3803 9877 41980 32139 2855 44236 64938 3298 5983 99947 9666 95856 62545...
output:
0 0 0 2 2 5 2 2 3 4 4 7 8 9 11 10 14 12 12 10 11 10 10 9 10 11 11 9 15 11 14 13 14 16 11 17 15 13 15 14 14 20 15 20 22 22 20 17 23 23 24 29 24 26 30 31 36 28 37 39 35 34 45 39 46 45 43 46 42 49 44 50 43 47 52 50 49 57 51 56 61 58 68 66 69 69 61 63 67 63 72 74 78 72 73 78 77 73 85 76 86 82 85 76 82 8...
result:
ok 50000 lines
Test #2:
score: 0
Accepted
time: 657ms
memory: 58872kb
input:
100000 30038 18547 1594 65857 34063 4575 36600 72585 2328 99199 77595 1590 64257 48199 589 72301 40302 5083 69474 97536 606 60079 67381 9331 65982 39033 205 84122 65285 8508 18167 44905 3704 93490 94986 5941 27155 46374 6616 36232 62969 2212 79807 68652 7199 87352 59101 6880 94571 53224 3552 63610 8...
output:
0 1 3 3 3 3 4 6 10 10 12 14 14 16 18 19 19 19 19 22 22 23 23 23 23 24 25 26 26 26 26 26 26 28 31 31 31 31 31 34 34 36 40 41 41 42 42 42 42 42 44 44 44 47 48 48 48 48 48 48 48 48 48 49 50 50 53 54 54 55 55 56 56 56 56 56 59 62 62 62 62 62 62 62 62 62 62 63 65 67 69 69 69 73 73 73 74 76 76 76 76 76 79...
result:
ok 50000 lines
Test #3:
score: 0
Accepted
time: 876ms
memory: 59272kb
input:
100000 61878 94907 27495452 40498 66053 163324081 9987 91760 269034612 88613 6169 634714395 87422 83687 263182872 22328 64374 595886322 57437 38976 201931120 75020 26926 516189886 88639 96262 269100132 88285 44915 173237252 88407 91931 174315082 12843 50312 641940581 13297 52746 120211351 89089 4638...
output:
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 0 0 0 0 0 0 ...
result:
ok 50000 lines
Test #4:
score: 0
Accepted
time: 841ms
memory: 59540kb
input:
100000 45843 69600 747867718 13793 70429 681785830 79985 74443 517803908 38369 67457 257059055 49843 59820 901603712 26439 25214 598556764 10275 5998 613157018 13517 10279 61272074 45577 49749 153772596 30727 68824 827689136 21752 9334 936611496 49173 73121 899562409 67808 9217 665070707 38351 13721...
output:
0 0 0 0 3 0 0 0 0 1 1 0 4 2 0 1 1 0 2 0 3 1 0 0 0 1 1 0 1 2 1 0 0 1 0 1 1 2 2 2 0 0 0 0 2 0 1 1 0 0 3 2 0 0 0 0 0 1 0 1 0 1 0 0 0 2 2 2 0 0 1 0 0 1 1 0 0 0 1 3 2 0 0 0 0 0 0 2 2 0 0 0 0 3 2 3 1 1 0 0 3 1 1 0 2 1 1 2 1 0 1 2 1 0 4 2 1 3 1 1 1 0 0 0 0 1 3 1 1 1 2 1 2 1 0 1 1 0 0 0 2 0 0 0 3 3 1 0 1 1 ...
result:
ok 50000 lines
Test #5:
score: 0
Accepted
time: 2ms
memory: 3388kb
input:
10 1 6 50 5 7 60 10 7 57 1 7 7 8 10 71 9 8 66 1 3 79 9 4 92 8 2 41 8 ? 5 ? 2 + 5 159 ? 7 ? 4 + 9 184 ? 7 + 3 291
output:
0 0 1 1 1
result:
ok 5 lines
Test #6:
score: 0
Accepted
time: 951ms
memory: 60188kb
input:
100000 34346 47902 18 27392 33766 77 6756 26094 49 22936 48815 19 5650 6237 49 30025 40524 59 54595 38103 73 31226 14746 66 90535 30187 7 31954 7326 41 88688 84625 35 87060 2678 4 51031 33729 53 78866 33403 76 16783 75299 96 96244 52833 50 72746 8315 62 3610 74402 43 5479 75776 55 98976 97524 74 261...
output:
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 1 1 0 0 0 0 0 0 1 0 0 0 1 0 1 0 0 0 1 0 0 0 1 0 0 0 0 0 0 1 1 0 0 1 1 0 2 0 0 3 0 1 0 1 0 2 3 0 0 0 0 0 0 1 3 0 1 0 0 1 0 0 1 0 2 2 0 0 1 0 0 0 0 1 0 0 0 0 0 1 0 0 0 1 1 1 0 0 1 2 3 0 0 1 1 2 1 1 2 0 0 1 0 0 3 1 0 0 1 2 1 1 0 1 0 1 1 0 2 0 1 ...
result:
ok 50000 lines
Test #7:
score: 0
Accepted
time: 945ms
memory: 61360kb
input:
100000 64148 54183 29 11068 35332 64 25618 18806 90 77040 76732 10 84812 90880 38 42283 75749 18 16322 30644 94 36973 59934 83 29747 75832 83 65108 11462 34 56098 73933 71 13086 78104 88 61180 33475 85 14006 4857 5 3734 96760 71 71250 14549 2 33684 24761 9 14693 12183 86 16730 80793 35 4985 57321 20...
output:
0 0 3 3 3 5 8 10 10 11 12 13 12 13 13 13 14 14 15 16 16 18 17 21 23 22 23 22 22 26 26 33 36 37 36 36 37 36 38 39 41 38 39 42 43 42 42 46 46 46 48 53 49 52 53 54 53 56 58 57 54 59 59 58 58 59 59 55 58 62 58 62 62 60 60 68 68 65 64 70 69 70 72 78 78 76 76 76 77 80 79 80 82 80 84 85 84 86 89 87 83 90 9...
result:
ok 50000 lines
Test #8:
score: 0
Accepted
time: 943ms
memory: 60388kb
input:
100000 14082 229 36 27210 94270 83 4742 68213 50 87953 67081 92 51909 51726 24 90045 60667 69 24283 69653 69 315 54923 19 44878 20782 60 65714 37239 18 18550 90268 99 90511 90267 26 74527 52573 9 44461 37153 92 94712 75548 81 54222 86266 71 99559 95348 72 19824 84320 53 57415 91290 10 1848 64264 73 ...
output:
29569 22292 26968 29422 29480 29605 28379 19743 24389 24969 24814 19826 28407 22403 29124 28900 24214 21261 20969 29297 22382 27345 16938 24009 21936 21580 28754 27089 26016 28921 28981 26058 26175 17364 29296 20002 27815 29591 23866 26980 26606 20345 27293 19831 20130 18982 27761 25353 21109 16845 ...
result:
ok 50000 lines
Test #9:
score: 0
Accepted
time: 0ms
memory: 3416kb
input:
10 5 9 19 10 7 2 7 8 62 4 6 79 1 4 34 2 10 44 2 3 27 6 3 52 1 9 65 8 + 7 67 ? 2 + 2 15 ? 5 ? 5 ? 5 + 9 6 ? 9
output:
1 0 0 0 0
result:
ok 5 lines
Test #10:
score: 0
Accepted
time: 952ms
memory: 63316kb
input:
100000 76345 58764 90 38618 20579 17 64447 62815 58 59951 76798 55 74438 62576 95 53180 2222 89 11870 17020 38 39889 48984 74 16333 40563 97 25845 69446 58 5310 92817 62 3253 1870 7 89005 49525 84 82761 65333 77 84354 79477 21 580 24067 88 37079 78987 1 71193 72699 69 74616 30155 89 57080 85169 71 6...
output:
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 1 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 1 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 ...
result:
ok 50000 lines
Test #11:
score: 0
Accepted
time: 1035ms
memory: 66048kb
input:
100000 93170 87268 37 92583 41762 3 93445 95084 53 73369 81234 79 22891 43413 79 16715 69518 7 24171 20852 78 85174 42270 89 66924 67254 49 43354 42747 38 49859 42160 93 40042 50857 22 4048 65749 86 24257 79582 28 87393 44008 99 72905 724 0 91334 97136 21 94537 97499 73 25630 70522 17 60066 15405 10...
output:
0 0 0 0 1 1 1 1 3 4 3 4 4 4 7 7 7 7 7 8 7 9 10 10 10 10 10 14 15 15 17 17 17 17 17 17 19 18 19 23 26 26 24 27 26 29 28 30 30 26 31 35 36 37 38 39 40 41 40 42 40 38 36 42 36 39 40 38 40 50 51 50 54 42 44 56 45 56 59 61 51 63 61 68 62 67 62 69 55 70 68 70 72 72 74 65 66 60 67 74 79 81 67 76 71 90 88 9...
result:
ok 50000 lines
Test #12:
score: 0
Accepted
time: 982ms
memory: 64780kb
input:
100000 19572 74611 8 48607 74319 78 93319 98288 59 52549 90890 45 94797 90913 3 39349 35315 61 38406 98513 80 93016 86528 75 8738 42441 86 30903 41462 74 10393 85631 20 42211 49293 9 94579 14667 32 12354 61859 3 74498 17678 30 73444 85087 70 66415 69027 94 43638 69756 59 39651 46403 85 85460 86047 9...
output:
9967 10077 10052 9942 10077 10159 9742 9523 8936 9982 9997 9033 10148 10124 10094 10155 10003 10077 10088 10116 9958 10208 6409 8007 10173 10046 9956 10078 8473 10167 9797 6675 10136 10067 10098 10107 10033 10138 9480 7747 10040 9954 10013 8801 9980 5539 9953 10077 10072 9992 10040 10153 10134 7920 ...
result:
ok 50000 lines
Test #13:
score: 0
Accepted
time: 2ms
memory: 3380kb
input:
10 2 9 4 7 9 90 9 6 18 9 3 17 9 4 36 8 9 4 9 5 11 9 1 99 9 10 75 10 + 2 5 + 6 75 ? 8 + 10 14 ? 4 ? 2 ? 4 + 5 96 ? 8 + 10 53
output:
0 1 0 1 0
result:
ok 5 lines
Test #14:
score: 0
Accepted
time: 188ms
memory: 62016kb
input:
100000 49647 87470 68018 49647 66838 706542 90701 49647 804547 49647 49695 565349 89649 49647 58330 85202 49647 867857 49647 36014 819333 72467 49647 976326 49647 79763 583342 70175 49647 517474 49647 33568 520456 1985 49647 345782 66678 49647 972856 49647 68759 529647 49647 74524 568714 61394 49647...
output:
2 2 3 3 0 0 3 1 7 7 7 0 0 8 6 8 6 4 7 1 6 8 4 7 6 14 5 10 0 4 13 3 14 1 15 7 12 5 3 7 5 15 18 7 4 8 0 3 22 8 5 5 2 16 3 15 6 0 14 5 26 27 3 4 4 28 9 4 0 4 21 5 21 33 3 30 4 14 13 10 14 21 8 36 6 27 38 10 5 32 12 7 0 35 7 7 10 17 10 38 5 2 0 5 5 37 2 45 44 0 44 39 8 4 31 11 2 20 31 10 37 0 0 16 12 1 ...
result:
ok 50000 lines
Test #15:
score: 0
Accepted
time: 184ms
memory: 62032kb
input:
100000 89731 79663 351984 79663 48602 135355 79663 1628 661293 37635 79663 426439 42597 79663 617809 80941 79663 434012 79663 55353 351562 70259 79663 728593 56083 79663 465864 79663 49873 535094 79663 82032 99951 79663 72331 884689 4287 79663 744479 53983 79663 394859 79663 11490 97473 23469 79663 ...
output:
1 1 0 5 3 2 5 3 9 4 12 9 8 13 7 7 5 8 16 5 9 14 11 6 9 7 9 9 17 10 18 22 10 20 18 31 8 23 34 23 27 15 10 25 42 12 10 30 12 29 37 22 14 12 15 20 17 21 17 46 50 46 25 13 17 15 25 21 46 33 48 52 15 31 13 54 47 51 41 27 13 17 36 13 17 28 42 13 54 16 55 20 43 52 40 20 19 28 34 60 52 20 41 36 40 48 56 38 ...
result:
ok 50000 lines
Test #16:
score: 0
Accepted
time: 203ms
memory: 62368kb
input:
100000 21181 45480 383856 34048 21181 325232 21181 11533 106623 38797 21181 537777 14756 21181 106703 21181 95747 645967 21181 31947 917286 21181 83178 496425 21181 40900 130293 73538 21181 904098 21181 80057 191948 83460 21181 805492 21181 24716 460337 21181 27955 783121 21181 26269 144971 70919 21...
output:
1 1 1 1 3 4 5 7 7 7 7 7 7 10 10 10 10 16 18 18 18 18 19 19 20 20 20 20 20 22 26 26 31 31 34 35 34 34 34 36 36 37 38 39 40 41 43 43 46 46 47 48 49 50 49 53 52 55 55 55 55 55 57 60 58 58 58 62 62 62 61 66 68 67 68 69 68 70 72 73 77 73 76 74 79 78 80 81 81 82 83 84 87 87 89 89 89 89 89 89 91 90 92 94 9...
result:
ok 50000 lines
Test #17:
score: 0
Accepted
time: 2ms
memory: 3504kb
input:
10 10 4 0 7 3 0 10 6 1 5 1 1 5 10 1 8 6 0 10 2 1 1 9 1 1 7 1 10 ? 4 + 6 2 + 9 0 ? 8 + 8 1 + 10 0 ? 4 + 4 2 ? 5 ? 7
output:
0 0 0 2 2
result:
ok 5 lines
Test #18:
score: 0
Accepted
time: 596ms
memory: 59188kb
input:
100000 50403 23870 1 2269 77786 0 88236 65765 0 28248 4408 0 74558 79109 1 75664 73208 1 10792 28375 1 98567 27634 0 90845 81177 0 32096 76545 1 11733 25888 1 68554 31308 0 1066 2492 0 93224 8314 1 69887 89588 1 16083 47361 1 60248 97232 1 86630 50173 0 31340 46107 0 20258 51269 0 39376 44028 0 8841...
output:
0 0 0 0 0 1 0 3 1 3 1 1 1 0 0 0 0 0 1 2 3 5 5 4 9 6 8 0 5 9 0 6 7 7 0 2 7 7 5 10 0 0 0 8 5 7 16 13 2 4 7 3 4 1 1 10 18 2 8 18 1 15 5 13 16 3 11 0 6 13 21 6 0 6 5 16 6 5 1 1 6 24 0 3 20 9 16 4 24 5 14 15 0 0 8 8 11 0 20 10 0 8 7 10 6 8 5 35 2 6 22 1 7 8 3 2 7 4 8 0 8 10 1 13 5 2 4 7 12 36 3 10 2 1 38...
result:
ok 50000 lines
Test #19:
score: 0
Accepted
time: 600ms
memory: 59284kb
input:
100000 49730 265 0 78809 9153 1 65275 81703 0 50422 28990 1 72969 40778 0 21604 34831 0 59452 1530 0 98737 82518 1 37741 5473 1 13736 17478 0 25982 68500 1 86711 84227 0 54130 17469 0 65309 37081 0 35584 46216 1 4853 59899 1 49822 85278 1 8445 72686 0 59147 22165 1 73035 65850 0 16437 25280 0 29017 ...
output:
0 1 1 2 3 4 5 5 10 11 11 12 12 15 16 17 20 21 22 22 22 23 23 24 25 25 26 28 26 28 28 29 29 29 29 31 32 33 34 38 38 38 38 41 41 41 41 43 43 43 44 44 45 45 45 45 45 45 48 48 50 56 56 56 57 57 60 63 63 66 67 68 67 67 67 72 72 72 72 73 73 74 75 77 79 82 82 82 82 83 83 83 84 84 86 87 88 89 89 89 89 89 89...
result:
ok 50000 lines
Test #20:
score: 0
Accepted
time: 560ms
memory: 59192kb
input:
100000 41258 62882 0 64868 74025 1 5722 19530 1 14796 1252 0 2193 72766 0 12881 43335 1 33209 41103 0 35704 53796 0 67373 87901 0 29628 65583 1 30449 73872 0 59461 97707 1 18695 10840 1 92554 59053 1 57943 91567 0 53267 47642 1 41900 45739 0 34663 52104 0 73490 62510 0 31199 75399 1 89391 16176 1 15...
output:
49582 49377 49616 49360 49414 49523 49574 49515 49518 49675 49575 49418 49488 49169 49359 49515 49515 49619 49514 49418 49573 49451 49516 49390 49515 49582 49520 49582 49620 49331 49616 49601 49238 49383 49480 49547 49573 49412 49434 49471 49222 49501 49539 49514 49514 49404 49455 49515 49680 49657 ...
result:
ok 50000 lines
Test #21:
score: 0
Accepted
time: 2ms
memory: 3416kb
input:
10 10 2 81 9 6 39 1 6 85 7 9 31 9 3 99 9 5 71 7 8 91 4 9 72 5 10 15 10 + 8 167 ? 5 ? 9 + 3 61 + 5 239 ? 1 + 3 157 + 6 247 ? 6 ? 9
output:
0 0 1 2 2
result:
ok 5 lines
Test #22:
score: 0
Accepted
time: 603ms
memory: 59224kb
input:
100000 33416 72400 76 8810 46018 53 95687 39082 5 54088 16213 60 12596 96485 53 33591 76915 28 86310 6156 80 23776 4482 31 53780 58274 11 16040 62125 13 98537 85883 54 81308 3654 55 30235 20146 96 49716 61880 26 48285 79037 35 8521 48481 15 75112 63257 49 60693 5439 28 66775 33657 69 10262 64007 3 3...
output:
1 5 8 9 10 12 12 12 12 12 12 13 13 13 13 14 14 15 15 19 19 19 20 23 23 24 26 25 25 26 29 30 30 31 32 33 36 38 38 40 40 40 41 42 43 46 46 46 50 51 52 51 52 54 54 54 54 57 56 58 60 60 60 61 62 61 63 64 64 67 67 68 72 72 71 73 74 76 75 79 79 81 81 81 81 83 85 83 81 85 83 86 85 84 86 87 87 89 88 86 92 9...
result:
ok 50000 lines
Test #23:
score: 0
Accepted
time: 647ms
memory: 58972kb
input:
100000 77041 19377 18 97744 17616 36 37860 32974 94 42455 71716 21 27458 30336 73 99486 65469 87 64427 17284 83 28704 96602 34 41036 61624 7 45693 45912 85 51979 49553 95 99543 7021 74 24055 32520 97 12339 70810 57 27835 77595 41 47527 49193 67 35004 99001 31 11 88065 84 42722 19293 81 97216 27174 9...
output:
2 3 6 6 6 6 6 6 6 8 8 8 10 10 10 13 14 16 17 18 19 20 20 20 20 23 24 24 24 26 27 27 27 28 28 28 32 32 34 34 35 35 35 35 35 36 36 36 41 41 41 41 41 41 41 42 42 42 42 42 44 45 45 45 45 47 49 49 49 52 52 53 55 57 60 60 61 61 64 64 66 67 68 69 70 70 70 71 71 75 76 77 82 82 83 83 83 84 84 84 84 85 87 87 ...
result:
ok 50000 lines
Test #24:
score: 0
Accepted
time: 596ms
memory: 59096kb
input:
100000 67832 80824 45 57521 11588 3 73893 20303 89 99243 98124 35 28565 32549 48 92669 41118 87 40495 44528 22 78924 44280 6 79988 76789 22 55691 15711 75 91688 75476 11 5712 34840 50 46462 46471 55 77521 45788 51 68055 93814 25 36090 33652 72 78695 16093 48 52374 18265 32 61073 63876 2 99193 69139 ...
output:
49955 49934 49947 49942 49934 49937 49901 49937 49929 49960 49935 49936 49949 49945 49917 49945 49917 49949 49954 49920 49937 49916 49936 49940 49928 49945 49918 49929 49949 49922 49940 49923 49928 49913 49921 49939 49939 49939 49934 49929 49947 49936 49935 49920 49910 49948 49917 49945 49937 49914 ...
result:
ok 50000 lines