QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#714781 | #8002. 字符树 | hos_lyric# | 60 | 2547ms | 40964kb | C++14 | 15.0kb | 2024-11-06 07:13:01 | 2024-11-06 07:13:03 |
Judging History
answer
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")
struct Hld {
int n, rt;
// needs to be tree
// vertex lists
// modified in build(rt) (parent removed, heavy child first)
vector<vector<int>> graph;
vector<int> sz, par, dep;
int zeit;
vector<int> dis, fin, sid;
// head vertex (minimum depth) in heavy path
vector<int> head;
Hld() : n(0), rt(-1), zeit(0) {}
explicit Hld(int n_) : n(n_), rt(-1), graph(n), zeit(0) {}
void ae(int u, int v) {
assert(0 <= u); assert(u < n);
assert(0 <= v); assert(v < n);
graph[u].push_back(v);
graph[v].push_back(u);
}
void dfsSz(int u) {
sz[u] = 1;
for (const int v : graph[u]) {
auto it = std::find(graph[v].begin(), graph[v].end(), u);
if (it != graph[v].end()) graph[v].erase(it);
par[v] = u;
dep[v] = dep[u] + 1;
dfsSz(v);
sz[u] += sz[v];
}
}
void dfsHld(int u) {
dis[u] = zeit++;
const int deg = graph[u].size();
if (deg > 0) {
int vm = graph[u][0];
int jm = 0;
for (int j = 1; j < deg; ++j) {
const int v = graph[u][j];
if (sz[vm] < sz[v]) {
vm = v;
jm = j;
}
}
swap(graph[u][0], graph[u][jm]);
head[vm] = head[u];
dfsHld(vm);
for (int j = 1; j < deg; ++j) {
const int v = graph[u][j];
head[v] = v;
dfsHld(v);
}
}
fin[u] = zeit;
}
void build(int rt_) {
assert(0 <= rt_); assert(rt_ < n);
rt = rt_;
sz.assign(n, 0);
par.assign(n, -1);
dep.assign(n, -1);
dep[rt] = 0;
dfsSz(rt);
zeit = 0;
dis.assign(n, -1);
fin.assign(n, -1);
head.assign(n, -1);
head[rt] = rt;
dfsHld(rt);
assert(zeit == n);
sid.assign(n, -1);
for (int u = 0; u < n; ++u) sid[dis[u]] = u;
}
friend ostream &operator<<(ostream &os, const Hld &hld) {
const int maxDep = *max_element(hld.dep.begin(), hld.dep.end());
vector<string> ss(2 * maxDep + 1);
int pos = 0, maxPos = 0;
for (int j = 0; j < hld.n; ++j) {
const int u = hld.sid[j];
const int d = hld.dep[u];
if (hld.head[u] == u) {
if (j != 0) {
pos = maxPos + 1;
ss[2 * d - 1].resize(pos, '-');
ss[2 * d - 1] += '+';
}
} else {
ss[2 * d - 1].resize(pos, ' ');
ss[2 * d - 1] += '|';
}
ss[2 * d].resize(pos, ' ');
ss[2 * d] += std::to_string(u);
if (maxPos < static_cast<int>(ss[2 * d].size())) {
maxPos = ss[2 * d].size();
}
}
for (int d = 0; d <= 2 * maxDep; ++d) os << ss[d] << '\n';
return os;
}
bool contains(int u, int v) const {
return (dis[u] <= dis[v] && dis[v] < fin[u]);
}
int lca(int u, int v) const {
assert(0 <= u); assert(u < n);
assert(0 <= v); assert(v < n);
for (; head[u] != head[v]; ) (dis[u] > dis[v]) ? (u = par[head[u]]) : (v = par[head[v]]);
return (dis[u] > dis[v]) ? v : u;
}
int jumpUp(int u, int d) const {
assert(0 <= u); assert(u < n);
assert(d >= 0);
if (dep[u] < d) return -1;
const int tar = dep[u] - d;
for (u = head[u]; ; u = head[par[u]]) {
if (dep[u] <= tar) return sid[dis[u] + (tar - dep[u])];
}
}
int jump(int u, int v, int d) const {
assert(0 <= u); assert(u < n);
assert(0 <= v); assert(v < n);
assert(d >= 0);
const int l = lca(u, v);
const int du = dep[u] - dep[l], dv = dep[v] - dep[l];
if (d <= du) {
return jumpUp(u, d);
} else if (d <= du + dv) {
return jumpUp(v, du + dv - d);
} else {
return -1;
}
}
// [u, v) or [u, v]
template <class F> void doPathUp(int u, int v, bool inclusive, F f) const {
assert(contains(v, u));
for (; head[u] != head[v]; u = par[head[u]]) f(dis[head[u]], dis[u] + 1);
if (inclusive) {
f(dis[v], dis[u] + 1);
} else {
if (v != u) f(dis[v] + 1, dis[u] + 1);
}
}
// not path order, include lca(u, v) or not
template <class F> void doPath(int u, int v, bool inclusive, F f) const {
const int l = lca(u, v);
doPathUp(u, l, false, f);
doPathUp(v, l, inclusive, f);
}
// (vs, ps): compressed tree
// vs: DFS order (sorted by dis)
// vs[ps[x]]: the parent of vs[x]
// ids[vs[x]] = x, not set for non-tree vertex
vector<int> ids;
pair<vector<int>, vector<int>> compress(vector<int> us) {
// O(n) first time
ids.resize(n, -1);
std::sort(us.begin(), us.end(), [&](int u, int v) -> bool {
return (dis[u] < dis[v]);
});
us.erase(std::unique(us.begin(), us.end()), us.end());
int usLen = us.size();
assert(usLen >= 1);
for (int x = 1; x < usLen; ++x) us.push_back(lca(us[x - 1], us[x]));
std::sort(us.begin(), us.end(), [&](int u, int v) -> bool {
return (dis[u] < dis[v]);
});
us.erase(std::unique(us.begin(), us.end()), us.end());
usLen = us.size();
for (int x = 0; x < usLen; ++x) ids[us[x]] = x;
vector<int> ps(usLen, -1);
for (int x = 1; x < usLen; ++x) ps[x] = ids[lca(us[x - 1], us[x])];
return make_pair(us, ps);
}
};
////////////////////////////////////////////////////////////////////////////////
struct Set {
// max{ceil(log_64(n)), 1}
int log64N, n;
vector<unsigned long long> a[6];
explicit Set(int n_ = 0) : n(n_) {
assert(n >= 0);
int m = n ? n : 1;
for (int d = 0; ; ++d) {
m = (m + 63) >> 6;
a[d].assign(m, 0);
if (m == 1) {
log64N = d + 1;
break;
}
}
}
bool empty() const {
return !a[log64N - 1][0];
}
bool contains(int x) const {
return (a[0][x >> 6] >> (x & 63)) & 1;
}
void insert(int x) {
for (int d = 0; d < log64N; ++d) {
const int q = x >> 6, r = x & 63;
a[d][q] |= 1ULL << r;
x = q;
}
}
void erase(int x) {
for (int d = 0; d < log64N; ++d) {
const int q = x >> 6, r = x & 63;
if ((a[d][q] &= ~(1ULL << r))) break;
x = q;
}
}
// max s.t. <= x (or -1)
int prev(int x) const {
if (x > n - 1) x = n - 1;
for (int d = 0; d <= log64N; ++d) {
if (x < 0) break;
const int q = x >> 6, r = x & 63;
const unsigned long long lower = a[d][q] << (63 - r);
if (lower) {
x -= __builtin_clzll(lower);
for (int e = d; --e >= 0; ) x = x << 6 | (63 - __builtin_clzll(a[e][x]));
return x;
}
x = q - 1;
}
return -1;
}
// min s.t. >= x (or n)
int next(int x) const {
if (x < 0) x = 0;
for (int d = 0; d < log64N; ++d) {
const int q = x >> 6, r = x & 63;
if (static_cast<unsigned>(q) >= a[d].size()) break;
const unsigned long long upper = a[d][q] >> r;
if (upper) {
x += __builtin_ctzll(upper);
for (int e = d; --e >= 0; ) x = x << 6 | __builtin_ctzll(a[e][x]);
return x;
}
x = q + 1;
}
return n;
}
};
// prefix max staircase
// always cut at x = xs[n]
template <class X, class Y, class T> struct SegPreMax {
static constexpr Y Y_MIN = 0;//numeric_limits<Y>::min();
int n, nn;
vector<X> xs;
// max y
vector<Y> ys;
// area above max y of left child
vector<T> ts;
explicit SegPreMax(const vector<X> &xs_) : xs(xs_) {
n = (int)xs.size() - 1;
assert(n >= 0);
for (nn = 1; nn < n; nn <<= 1) {}
ys.assign(nn << 1, +Y_MIN); // + for compiler
ts.resize(nn);
for (int u = nn; --u; ) pull(u);
}
void pull(int u) {
ys[u] = max(ys[u << 1], ys[u << 1 | 1]);
ts[u] = cut(u << 1 | 1, ys[u << 1]);
}
// area above y
T cut(int u, Y y) const {
if (y >= ys[u] || u >= nn + n) return T();
if (u >= nn) return T(xs[n] - xs[u - nn]) * T(ys[u] - y);
if (y > ys[u << 1]) return cut(u << 1 | 1, y);
return cut(u << 1, y) + ts[u];
}
void changeY(int a, Y y) {
assert(0 <= a); assert(a < n);
ys[a += nn] = y;
for (; a >>= 1; ) pull(a);
}
Y getMaxY(int a, int b) const {
assert(0 <= a); assert(a <= b); assert(b <= n);
Y y = Y_MIN;
for (a += nn, b += nn; a < b; a >>= 1, b >>= 1) {
if (a & 1) chmax(y, ys[a++]);
if (b & 1) chmax(y, ys[--b]);
}
return y;
}
pair<T, Y> all() const {
return make_pair(cut(1, Y_MIN), ys[1]);
}
pair<T, Y> get(int a, int b, Y y) const {
assert(0 <= a); assert(a <= b); assert(b <= n);
return getRec(1, 0, nn, a, b, y);
}
pair<T, Y> getRec(int u, int l, int r, int a, int b, Y y) const {
if (b <= l || r <= a) return make_pair(T(), y);
if (a <= l && r <= b) return make_pair(cut(u, y), max(y, ys[u]));
const int mid = (l + r) >> 1;
const auto resL = getRec(u << 1 , l, mid, a, b, y);
const auto resR = getRec(u << 1 | 1, mid, r, a, b, resL.second);
return make_pair(resL.first + resR.first, resR.second);
}
}; // SegPreMax<X, Y, T>
////////////////////////////////////////////////////////////////////////////////
int N;
vector<int> P, C;
vector<int> W, A;
vector<Int> brute() {
vector<string> S(N);
for (int u = 1; u < N; ++u) {
S[u] = S[P[u]] + "01"[C[u]];
}
vector<Int> ans(N, 0);
for (int u = 0; u < N; ++u) {
for (int d = 0; d <= (int)S[u].size(); ++d) {
int mx = 0;
for (int v = 0; v < N; ++v) {
if (d >= A[v] &&
S[u].size() <= S[v].size() &&
S[u] == S[v].substr(S[v].size() - S[u].size()) &&
S[u].substr(0, d) == S[v].substr(0, d)) {
chmax(mx, W[v]);
}
}
ans[u] += mx;
}
}
return ans;
}
int nxt[500'010][2];
vector<int> fail;
void bfs() {
fail.assign(N, 0);
queue<int> que;
que.push(0);
for (; que.size(); ) {
const int u = que.front();
que.pop();
for (int e = 0; e < 2; ++e) {
int &v = nxt[u][e];
if (~v) {
fail[v] = u ? nxt[fail[u]][e] : 0;
que.push(v);
} else {
v = u ? nxt[fail[u]][e] : 0;
}
}
}
// cerr<<"fail = "<<fail<<endl;
}
Hld G, H;
vector<int> vs;
namespace slow {
vector<Int> ans;
vector<int> stack;
vector<int> ls;
void dfs(int u) {
stack[G.dep[u]] = u;
// ls[dis[v]] := dep[lca(u, v)]
for (int d = 0; d < G.dep[u]; ++d) fill(ls.begin() + G.dis[stack[d]], ls.begin() + G.dis[stack[d + 1]], d);
fill(ls.begin() + G.dis[u], ls.begin() + G.fin[u], G.dep[u]);
for (int d = G.dep[u]; --d >= 0; ) fill(ls.begin() + G.fin[stack[d + 1]], ls.begin() + G.fin[stack[d]], d);
// for(int v=0;v<N;++v)assert(ls[G.dis[v]]==G.dep[G.lca(u,v)]);
Set yet(G.dep[u] + 1);
for (int d = 0; d <= G.dep[u]; ++d) yet.insert(d);
for (const int v : vs) if (H.contains(u, v)) {
const int dL = A[v];
const int dR = ls[G.dis[v]];
if (dL <= dR) {
for (int d = dL; (d = yet.next(d)) <= dR; ) {
ans[u] += W[v];
yet.erase(d);
}
}
}
for (const int v : G.graph[u]) {
dfs(v);
}
stack[G.dep[u]] = -1;
}
vector<Int> run() {
cerr<<"[slow::run]"<<endl;
ans.assign(N, 0);
stack.assign(N, -1);
ls.assign(N, -1);
dfs(0);
return ans;
}
} // slow
namespace slow2 {
vector<Int> run() {
cerr<<"[slow2::run]"<<endl;
vector<Int> ans(N, 0);
for (int u = 0; u < N; ++u) {
vector<int> mxs(G.dep[u] + 1, 0);
for (int k = H.dis[u]; k < H.fin[u]; ++k) {
const int v = H.sid[k];
const int dL = A[v];
const int dR = G.dep[G.lca(u, v)];
for (int d = dL; d <= dR; ++d) {
chmax(mxs[d], W[v]);
}
}
for (int d = 0; d <= G.dep[u]; ++d) {
ans[u] += mxs[d];
}
}
return ans;
}
} // slow2
namespace chain {
// ans[u] = \sum[0<=d<=u] max[A[v]<=d<=u<=v] W[v]
vector<Int> run() {
cerr<<"[chain::run]"<<endl;
for (int u = 1; u < N; ++u) assert(P[u] == u - 1);
vector<int> xs(N + 2);
for (int x = 0; x <= N + 1; ++x) xs[x] = x;
SegPreMax<int, int, Int> seg(xs);
vector<int> ws(N + 1, 0);
vector<Int> ans(N);
for (int u = N; --u >= 0; ) {
if (chmax(ws[A[u]], W[u])) {
seg.changeY(A[u], W[u]);
}
const auto res = seg.get(0, u + 1, 0);
// cerr<<"ws = "<<ws<<", res = "<<res<<endl;
ans[u] = res.first - (Int)((N + 1) - (u + 1)) * res.second;
}
return ans;
}
} // chain
int main() {
for (int numCases; ~scanf("%d", &numCases); ) { for (int caseId = 1; caseId <= numCases; ++caseId) {
scanf("%d", &N);
P.assign(N, -1);
C.assign(N, -1);
for (int u = 1; u < N; ++u) {
scanf("%d%d", &P[u], &C[u]);
--P[u];
}
W.resize(N);
for (int u = 0; u < N; ++u) {
scanf("%d", &W[u]);
}
A.resize(N);
for (int u = 0; u < N; ++u) {
scanf("%d", &A[u]);
}
for (int u = 0; u < N; ++u) nxt[u][0] = nxt[u][1] = -1;
for (int u = 1; u < N; ++u) nxt[P[u]][C[u]] = u;
bfs();
G = Hld(N);
H = Hld(N);
for (int u = 1; u < N; ++u) {
G.ae(P[u], u);
H.ae(fail[u], u);
}
G.build(0);
H.build(0);
// cerr<<G<<H<<endl;
vs.resize(N);
for (int v = 0; v < N; ++v) vs[v] = v;
sort(vs.begin(), vs.end(), [&](int v0, int v1) -> bool {
return (W[v0] > W[v1]);
});
bool speA = true;
for (int u = 1; u < N; ++u) speA = speA && (C[u] == 0);
bool speB = true;
for (int u = 1; u < N; ++u) speB = speB && (P[u] == (u + 1) / 2 - 1);
vector<Int> ans;
if (speA) {
ans = chain::run();
} else if (speB) {
ans = slow2::run();
} else {
ans = slow::run();
}
for (int u = 0; u < N; ++u) {
if (u) printf(" ");
printf("%lld", ans[u]);
}
puts("");
#ifdef LOCAL
const auto brt=brute();
if(brt!=ans){
cerr<<"brt = "<<brt<<endl;
cerr<<"ans = "<<ans<<endl;
assert(false);
}
#endif
}
#ifndef LOCAL
break;
#endif
}
return 0;
}
詳細信息
Pretests
Final Tests
Test #1:
score: 5
Accepted
time: 1ms
memory: 3912kb
input:
5 100 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 0 10 0 11 0 12 0 13 0 14 0 15 0 16 0 17 0 18 0 19 0 20 0 21 0 22 0 23 0 24 0 25 0 26 0 27 0 28 0 29 0 30 0 31 0 32 0 33 0 34 0 35 0 36 0 37 0 38 0 39 0 40 0 41 0 42 0 43 0 44 0 45 0 46 0 47 0 48 0 49 0 50 0 51 0 52 0 53 0 54 0 55 0 56 0 57 0 58 0 59 0 60 0 61 ...
output:
898192584 1872556072 2796790614 3758907885 4721025156 5540285037 6473830830 7439177386 8387406282 9352752838 10318099394 11283445950 12283445950 13283445950 14283445950 15144832174 15985150482 16950497038 17445491372 18445491372 19445491372 20445491372 21364928322 21962113072 22881550022 23800986972...
result:
ok 500 numbers
Test #2:
score: 5
Accepted
time: 1ms
memory: 3944kb
input:
5 100 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 0 10 0 11 0 12 0 13 0 14 0 15 0 16 0 17 0 18 0 19 0 20 0 21 0 22 0 23 0 24 0 25 0 26 0 27 0 28 0 29 0 30 0 31 0 32 0 33 0 34 0 35 0 36 0 37 0 38 0 39 0 40 0 41 0 42 0 43 0 44 0 45 0 46 0 47 0 48 0 49 0 50 0 51 0 52 0 53 0 54 0 55 0 56 0 57 0 58 0 59 0 60 0 61 ...
output:
981392440 1962784880 2955924472 3949064064 4942203656 5935343248 6908906778 7908906778 8895185962 9888325554 10881465146 11874604738 12867744330 13860883922 14860883922 15860883922 16840302698 17840302698 18840302698 19517274953 20432088180 21432088180 22432088180 23318505816 24290110225 25261714634...
result:
ok 500 numbers
Test #3:
score: 5
Accepted
time: 102ms
memory: 5248kb
input:
5 2000 1 0 1 1 2 0 2 1 3 0 3 1 4 0 4 1 5 0 5 1 6 0 6 1 7 0 7 1 8 0 8 1 9 0 9 1 10 0 16 0 21 0 22 0 23 0 24 0 25 0 26 0 27 0 28 0 29 0 30 0 31 0 32 0 33 0 34 0 35 0 36 0 37 0 38 0 39 0 40 0 41 0 42 0 43 0 44 0 45 0 46 0 47 0 48 0 49 0 50 0 51 0 52 0 53 0 54 0 55 0 56 0 57 0 58 0 59 0 60 0 61 0 62 0 6...
output:
1000000000 1998400828 993283036 2997601242 1982118880 2974350138 1000000000 3995472424 1965887128 3985959244 3000000000 2956494828 2000000000 2959713978 0 4994340530 2940499173 3941189620 2944137507 0 5993208636 6992076742 7990944848 8989812954 9988681060 10988681060 11988681060 12988681060 13984153...
result:
ok 10000 numbers
Test #4:
score: 5
Accepted
time: 98ms
memory: 5236kb
input:
5 2000 1 0 1 1 2 0 2 1 3 0 3 1 4 0 4 1 5 0 5 1 6 0 6 1 7 0 7 1 8 0 8 1 9 0 9 1 10 0 16 0 21 0 22 0 23 0 24 0 25 0 26 0 27 0 28 0 29 0 30 0 31 0 32 0 33 0 34 0 35 0 36 0 37 0 38 0 39 0 40 0 41 0 42 0 43 0 44 0 45 0 46 0 47 0 48 0 49 0 50 0 51 0 52 0 53 0 54 0 55 0 56 0 57 0 58 0 59 0 60 0 61 0 62 0 6...
output:
1000000000 1989496542 1996067849 2985991461 1991714992 2960477667 2983449306 3982486380 3983429984 1969526880 1996565664 2953748358 1980701322 1994377494 3970332948 4978981299 1000000000 2954038725 4991414160 3956583228 5975476218 6971971137 7968466056 8964960975 9961455894 10957950813 11954445732 1...
result:
ok 10000 numbers
Test #5:
score: 5
Accepted
time: 100ms
memory: 5240kb
input:
5 2000 1 0 1 1 2 0 2 1 3 0 3 1 4 0 4 1 5 0 5 1 6 0 6 1 7 0 7 1 8 0 8 1 9 0 9 1 10 0 16 0 21 0 22 0 23 0 24 0 25 0 26 0 27 0 28 0 29 0 30 0 31 0 32 0 33 0 34 0 35 0 36 0 37 0 38 0 39 0 40 0 41 0 42 0 43 0 44 0 45 0 46 0 47 0 48 0 49 0 50 0 51 0 52 0 53 0 54 0 55 0 56 0 57 0 58 0 59 0 60 0 61 0 62 0 6...
output:
1000000000 1997363842 2000000000 2996045763 2954596806 1995148332 3000000000 3996045763 0 2983043281 2977715897 1970005876 1989593130 2999881107 2976355872 4993409605 0 3942019132 3999426588 2935916472 5992091526 6990773447 7990773447 8970557459 9958230246 10954121175 11950012104 12942775649 1393866...
result:
ok 10000 numbers
Test #6:
score: 5
Accepted
time: 2519ms
memory: 15200kb
input:
5 10000 1 0 1 1 2 0 2 1 3 0 3 1 4 0 4 1 5 0 5 1 6 0 6 1 7 0 7 1 8 0 8 1 9 0 9 1 10 0 10 1 11 0 11 1 12 0 12 1 13 0 13 1 14 0 14 1 15 0 15 1 16 0 16 1 17 0 17 1 18 0 18 1 19 0 19 1 20 0 20 1 21 0 21 1 22 0 22 1 23 0 23 1 24 0 24 1 25 0 25 1 26 0 26 1 27 0 27 1 28 0 28 1 29 0 29 1 30 0 30 1 31 0 31 1 ...
output:
1000000000 1997525692 1996985317 2997129200 2991179348 2997161779 2996319570 3989223081 3991374635 3991946500 3992002124 3994749088 3987611669 3982661232 3992639140 4979350080 3976024017 4992360483 4985259115 3996723498 2995609011 4975872060 2981189242 4997695335 4973608855 3986790024 4974234480 399...
result:
ok 50000 numbers
Test #7:
score: 5
Accepted
time: 2547ms
memory: 15144kb
input:
5 10000 1 0 1 1 2 0 2 1 3 0 3 1 4 0 4 1 5 0 5 1 6 0 6 1 7 0 7 1 8 0 8 1 9 0 9 1 10 0 10 1 11 0 11 1 12 0 12 1 13 0 13 1 14 0 14 1 15 0 15 1 16 0 16 1 17 0 17 1 18 0 18 1 19 0 19 1 20 0 20 1 21 0 21 1 22 0 22 1 23 0 23 1 24 0 24 1 25 0 25 1 26 0 26 1 27 0 27 1 28 0 28 1 29 0 29 1 30 0 30 1 31 0 31 1 ...
output:
999967682 1999743789 1999734462 2999173761 2994260277 2999967682 2996718891 3998898348 3994925097 3999296003 3999068044 3988921256 3985522278 3981187872 3991168544 4991213080 4986062038 4983561919 4989364086 4988276002 4983340123 3989911805 3982210105 4984791488 4999336155 4999838410 4992867765 4979...
result:
ok 50000 numbers
Test #8:
score: 5
Accepted
time: 2536ms
memory: 17200kb
input:
5 10000 1 0 1 1 2 0 2 1 3 0 3 1 4 0 4 1 5 0 5 1 6 0 6 1 7 0 7 1 8 0 8 1 9 0 9 1 10 0 10 1 11 0 11 1 12 0 12 1 13 0 13 1 14 0 14 1 15 0 15 1 16 0 16 1 17 0 17 1 18 0 18 1 19 0 19 1 20 0 20 1 21 0 21 1 22 0 22 1 23 0 23 1 24 0 24 1 25 0 25 1 26 0 26 1 27 0 27 1 28 0 28 1 29 0 29 1 30 0 30 1 31 0 31 1 ...
output:
998876645 1997338029 1997339516 2996329925 2996629935 2997539420 2996852099 3991437240 3987402020 3992793244 3993161552 3993525624 3991071983 3992608450 3993426205 4976844461 4985337711 4973415221 4980643476 4975351325 4994383225 4984438057 4992192815 4980003495 4992314355 4994728129 3980284364 2997...
result:
ok 50000 numbers
Test #9:
score: 5
Accepted
time: 382ms
memory: 40664kb
input:
5 100000 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 0 10 0 11 0 12 0 13 0 14 0 15 0 16 0 17 0 18 0 19 0 20 0 21 0 22 0 23 0 24 0 25 0 26 0 27 0 28 0 29 0 30 0 31 0 32 0 33 0 34 0 35 0 36 0 37 0 38 0 39 0 40 0 41 0 42 0 43 0 44 0 45 0 46 0 47 0 48 0 49 0 50 0 51 0 52 0 53 0 54 0 55 0 56 0 57 0 58 0 59 0 60 0 ...
output:
999958881 1999893258 2999843477 3999772224 4999748473 5999724722 6999700971 7999700971 8999700971 9999629718 10999605967 11999582216 12999548314 13999548314 14999467815 15999440982 16999414149 17999333929 18999333929 19999307096 20999226597 21999199764 22999172931 23999146098 24999119265 25999092432...
result:
ok 500000 numbers
Test #10:
score: 5
Accepted
time: 389ms
memory: 40964kb
input:
5 100000 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 0 10 0 11 0 12 0 13 0 14 0 15 0 16 0 17 0 18 0 19 0 20 0 21 0 22 0 23 0 24 0 25 0 26 0 27 0 28 0 29 0 30 0 31 0 32 0 33 0 34 0 35 0 36 0 37 0 38 0 39 0 40 0 41 0 42 0 43 0 44 0 45 0 46 0 47 0 48 0 49 0 50 0 51 0 52 0 53 0 54 0 55 0 56 0 57 0 58 0 59 0 60 0 ...
output:
999915392 1999903890 2999903890 3999903890 4999892388 5999857882 6999808669 7999797167 8999785665 9999785665 10999762661 11999751159 12999739657 13999728155 14999716653 15999168106 16999083194 17998513012 18998440066 19998367120 20998294174 21998221228 22998148282 23998075336 24998002390 25997929444...
result:
ok 500000 numbers
Test #11:
score: 5
Accepted
time: 656ms
memory: 25656kb
input:
5 100000 1 0 1 1 2 0 2 1 3 0 3 1 4 0 4 1 5 0 5 1 6 0 6 1 7 0 7 1 8 0 8 1 9 0 9 1 10 0 10 1 11 0 11 1 12 0 12 1 13 0 13 1 14 0 14 1 15 0 15 1 16 0 16 1 17 0 17 1 18 0 18 1 19 0 19 1 20 0 20 1 21 0 21 1 22 0 22 1 23 0 23 1 24 0 24 1 25 0 25 1 26 0 26 1 27 0 27 1 28 0 28 1 29 0 29 1 30 0 30 1 31 0 31 1...
output:
1000000000 1999851068 2000000000 2999203805 2999695590 2999589046 2999368209 3998889336 3998839612 3999702136 3999182977 3998258275 3999101959 3999285480 3998372379 4998560200 4998052058 4998439925 4998765415 4997362737 4999492650 4997430254 4997019523 4992645858 4998271828 4998163182 4998910700 499...
result:
ok 500000 numbers
Test #12:
score: 5
Accepted
time: 656ms
memory: 27500kb
input:
5 100000 1 0 1 1 2 0 2 1 3 0 3 1 4 0 4 1 5 0 5 1 6 0 6 1 7 0 7 1 8 0 8 1 9 0 9 1 10 0 10 1 11 0 11 1 12 0 12 1 13 0 13 1 14 0 14 1 15 0 15 1 16 0 16 1 17 0 17 1 18 0 18 1 19 0 19 1 20 0 20 1 21 0 21 1 22 0 22 1 23 0 23 1 24 0 24 1 25 0 25 1 26 0 26 1 27 0 27 1 28 0 28 1 29 0 29 1 30 0 30 1 31 0 31 1...
output:
999955807 1999783719 1999858914 2999654721 2999761161 2999867421 2999583758 3999654721 3999825363 3998724964 3999081545 3998042034 3998532108 3998283824 3998977721 4999138457 4999104220 4996782381 4998076718 4995657098 4998743457 4993644957 4999294570 4998078495 4994738883 4998316980 4998756700 4997...
result:
ok 500000 numbers
Test #13:
score: 0
Time Limit Exceeded
input:
5 100000 1 0 1 1 2 0 2 1 3 0 3 1 4 0 4 1 5 0 5 1 6 0 6 1 7 0 7 1 8 0 8 1 9 0 9 1 10 0 10 1 11 0 11 1 12 0 12 1 13 0 13 1 14 0 14 1 15 0 15 1 16 0 16 1 17 0 17 1 18 0 18 1 19 0 19 1 20 0 20 1 21 0 21 1 22 0 22 1 23 0 23 1 24 0 24 1 25 0 25 1 26 0 26 1 27 0 27 1 28 0 28 1 29 0 29 1 30 0 30 1 31 0 31 1...
output:
result:
Test #14:
score: 0
Time Limit Exceeded
input:
5 100000 1 0 1 1 2 0 2 1 3 0 3 1 4 0 4 1 5 0 5 1 6 0 6 1 7 0 7 1 8 0 8 1 9 0 9 1 10 0 10 1 11 0 11 1 12 0 12 1 13 0 13 1 14 0 14 1 15 0 15 1 16 0 16 1 17 0 17 1 18 0 18 1 19 0 19 1 20 0 20 1 21 0 21 1 22 0 22 1 23 0 23 1 24 0 24 1 25 0 25 1 26 0 26 1 27 0 27 1 28 0 28 1 29 0 29 1 30 0 30 1 31 0 31 1...
output:
result:
Test #15:
score: 0
Time Limit Exceeded
input:
5 100000 1 0 1 1 2 0 2 1 3 0 3 1 4 0 4 1 5 0 5 1 6 0 6 1 7 0 7 1 8 0 8 1 9 0 9 1 10 0 10 1 11 0 11 1 12 0 12 1 13 0 13 1 14 0 14 1 15 0 15 1 16 0 16 1 17 0 17 1 18 0 18 1 19 0 19 1 20 0 20 1 21 0 21 1 22 0 22 1 23 0 23 1 24 0 24 1 25 0 25 1 26 0 26 1 27 0 27 1 28 0 28 1 29 0 29 1 30 0 30 1 31 0 31 1...
output:
result:
Test #16:
score: 0
Time Limit Exceeded
input:
5 100000 1 0 1 1 2 0 2 1 3 0 3 1 4 0 4 1 5 0 5 1 6 0 6 1 7 0 7 1 8 0 8 1 9 0 9 1 10 0 10 1 11 0 11 1 12 0 12 1 13 0 13 1 14 0 14 1 15 0 15 1 16 0 16 1 17 0 17 1 18 0 18 1 19 0 19 1 20 0 20 1 21 0 21 1 22 0 22 1 23 0 23 1 24 0 24 1 25 0 25 1 26 0 26 1 27 0 27 1 28 0 28 1 29 0 29 1 30 0 30 1 31 0 31 1...
output:
result:
Test #17:
score: 0
Time Limit Exceeded
input:
5 500000 1 0 1 1 2 0 2 1 3 0 3 1 4 0 4 1 5 0 5 1 6 0 6 1 7 0 7 1 8 0 8 1 9 0 9 1 10 0 10 1 11 0 11 1 12 0 12 1 13 0 13 1 14 0 14 1 15 0 15 1 16 0 16 1 17 0 17 1 18 0 18 1 19 0 19 1 20 0 20 1 21 0 21 1 22 0 22 1 23 0 23 1 24 0 24 1 25 0 25 1 26 0 26 1 27 0 27 1 28 0 28 1 29 0 29 1 30 0 30 1 31 0 31 1...
output:
result:
Test #18:
score: 0
Time Limit Exceeded
input:
5 500000 1 0 1 1 2 0 2 1 3 0 3 1 4 0 4 1 5 0 5 1 6 0 6 1 7 0 7 1 8 0 8 1 9 0 9 1 10 0 10 1 11 0 11 1 12 0 12 1 13 0 13 1 14 0 14 1 15 0 15 1 16 0 16 1 17 0 17 1 18 0 18 1 19 0 19 1 20 0 20 1 21 0 21 1 22 0 22 1 23 0 23 1 24 0 24 1 25 0 25 1 26 0 26 1 27 0 27 1 28 0 28 1 29 0 29 1 30 0 30 1 31 0 31 1...
output:
result:
Test #19:
score: 0
Time Limit Exceeded
input:
5 500000 1 0 1 1 2 0 2 1 3 0 3 1 4 0 4 1 5 0 5 1 6 0 6 1 7 0 7 1 8 0 8 1 9 0 9 1 10 0 10 1 11 0 11 1 12 0 12 1 13 0 13 1 14 0 14 1 15 0 15 1 16 0 16 1 17 0 17 1 18 0 18 1 19 0 19 1 20 0 20 1 21 0 21 1 22 0 22 1 23 0 23 1 24 0 24 1 25 0 25 1 26 0 26 1 27 0 27 1 28 0 28 1 29 0 29 1 30 0 30 1 31 0 31 1...
output:
result:
Test #20:
score: 0
Time Limit Exceeded
input:
5 500000 1 0 1 1 2 0 2 1 3 0 3 1 4 0 4 1 5 0 5 1 6 0 6 1 7 0 7 1 8 0 8 1 9 0 9 1 10 0 10 1 11 0 11 1 12 0 12 1 13 0 13 1 14 0 14 1 15 0 15 1 16 0 16 1 17 0 17 1 18 0 18 1 19 0 19 1 20 0 20 1 21 0 21 1 22 0 22 1 23 0 23 1 24 0 24 1 25 0 25 1 26 0 26 1 27 0 27 1 28 0 28 1 29 0 29 1 30 0 30 1 31 0 31 1...