QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#190006 | #4924. 蜘蛛爬树 | hos_lyric# | 40 | 1038ms | 200236kb | C++14 | 13.9kb | 2023-09-28 05:58:16 | 2024-07-04 02:11:08 |
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 <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);
}
};
////////////////////////////////////////////////////////////////////////////////
constexpr Int INF = 2001001001001001001LL;
// a + b x
// b: decreasing
// x: increasing
struct Cht {
int head;
vector<pair<Int, Int>> ps;
Cht() : head(0) {}
void add(Int a, Int b) {
for (; (int)ps.size() - head >= 2; ps.pop_back()) {
const Int a2 = ps[ps.size() - 2].first, b2 = ps[ps.size() - 2].second;
const Int a1 = ps[ps.size() - 1].first, b1 = ps[ps.size() - 1].second;
if ((__int128)(a1 - a2) * (b1 - b) < (__int128)(a - a1) * (b2 - b1)) break;
}
ps.emplace_back(a, b);
// cerr<<"ps = "<<ps<<endl;
}
Int get(Int x) {
for (; (int)ps.size() - head >= 2 && ps[head].first + ps[head].second * x >= ps[head + 1].first + ps[head + 1].second * x; ++head) {}
if ((int)ps.size() - head == 0) return INF;
return ps[head].first + ps[head].second * x;
}
};
Int M;
int N, Q;
vector<Int> D;
vector<int> A, B;
vector<Int> C;
vector<Int> L;
vector<int> S, T;
vector<vector<int>> G;
namespace brute {
Int dist[5010][5010];
void dfs(int r, int u, int p, Int d) {
dist[r][u] = d;
for (const int i : G[u]) {
const int v = A[i] ^ B[i] ^ u;
if (p != v) {
dfs(r, v, u, d + C[i]);
}
}
}
vector<Int> run() {
for (int r = 0; r < N; ++r) {
dfs(r, r, -1, 0);
}
vector<Int> ans(Q, INF);
for (int q = 0; q < Q; ++q) {
for (int u = 0; u < N; ++u) {
chmin(ans[q], dist[S[q]][u] + L[q] * D[u] + dist[T[q]][u]);
}
}
return ans;
}
} // brute
namespace sub3 {
vector<Int> cs, dp;
void dfs(Int l, int u, int p, Int c) {
cs[u] = c;
dp[u] = l * D[u];
for (const int i : G[u]) {
const int v = A[i] ^ B[i] ^ u;
if (p != v) {
dfs(l, v, u, c + C[i]);
chmin(dp[u], 2 * C[i] + dp[v]);
}
}
}
int segN;
vector<Int> segs[2];
Int get(int h, int a, int b) {
Int ret = INF;
for (a += segN, b += segN; a < b; a >>= 1, b >>= 1) {
if (a & 1) chmin(ret, segs[h][a++]);
if (b & 1) chmin(ret, segs[h][--b]);
}
return ret;
}
vector<Int> run() {
const int rt = 0;
Hld hld(N);
for (int i = 0; i < N - 1; ++i) hld.ae(A[i], B[i]);
hld.build(rt);
// cerr<<hld<<flush;
for (segN = 1; segN < N; segN <<= 1) {}
for (int h = 0; h < 2; ++h) {
segs[h].assign(segN << 1, INF);
}
vector<vector<int>> qss(M);
for (int q = 0; q < Q; ++q) {
qss[L[q]].push_back(q);
}
vector<Int> ans(Q, INF);
for (Int l = 0; l < M; ++l) {
cs.assign(N, 0);
dp.assign(N, INF);
dfs(l, rt, -1, 0);
// cerr<<"l = "<<l<<", cs = "<<cs<<", dp = "<<dp<<endl;
for (int j = 0; j < N; ++j) {
const int u = hld.sid[j];
segs[0][segN + j] = dp[u];
segs[1][segN + j] = dp[u] - 2 * cs[u];
}
for (int h = 0; h < 2; ++h) {
for (int a = segN; --a; ) {
segs[h][a] = min(segs[h][a << 1], segs[h][a << 1 | 1]);
}
}
for (const int q : qss[l]) {
const int s = S[q], t = T[q];
const int u = hld.lca(s, t);
hld.doPathUp(s, u, false, [&](int a, int b) -> void {
chmin(ans[q], get(0, a, b));
});
hld.doPathUp(t, u, false, [&](int a, int b) -> void {
chmin(ans[q], get(0, a, b));
});
hld.doPathUp(u, rt, true, [&](int a, int b) -> void {
chmin(ans[q], get(1, a, b) + 2 * cs[u]);
});
ans[q] += (cs[s] - cs[u]) + (cs[t] - cs[u]);
}
}
return ans;
}
} // sub3
namespace sub4 {
vector<int> dep;
vector<Int> cs;
void dfs(int u, int p, int d, Int c) {
dep[u] = d;
cs[u] = c;
for (const int i : G[u]) {
const int v = A[i] ^ B[i] ^ u;
if (p != v) {
dfs(v, u, d + 1, c + C[i]);
}
}
}
int segN;
vector<Cht> segs[3];
Int get(int h, int a, int b, Int x) {
Int ret = INF;
for (a += segN, b += segN; a < b; a >>= 1, b >>= 1) {
if (a & 1) chmin(ret, segs[h][a++].get(x));
if (b & 1) chmin(ret, segs[h][--b].get(x));
}
return ret;
}
vector<Int> run() {
dep.assign(N, -1);
cs.assign(N, 0);
for (int u = 0; u < N; ++u) if (G[u].size() == 1) {
dfs(u, -1, 0, 0);
break;
}
// cerr<<"dep = "<<dep<<", cs = "<<cs<<endl;
for (segN = 1; segN < N; segN <<= 1) {}
for (int h = 0; h < 3; ++h) {
segs[h].assign(segN << 1, Cht());
}
{
vector<int> us(N);
for (int u = 0; u < N; ++u) us[u] = u;
sort(us.begin(), us.end(), [&](int u, int v) -> bool {
return (D[u] > D[v]);
});
for (const int u : us) {
for (int a = segN + dep[u]; a; a >>= 1) {
segs[0][a].add(- cs[u] - cs[u], D[u]);
segs[1][a].add(+ cs[u] - cs[u], D[u]);
segs[2][a].add(+ cs[u] + cs[u], D[u]);
}
}
}
vector<Int> ans(Q, INF);
{
vector<int> qs(Q);
for (int q = 0; q < Q; ++q) qs[q] = q;
sort(qs.begin(), qs.end(), [&](int q0, int q1) -> bool {
return (L[q0] < L[q1]);
});
for (const int q : qs) {
int s = S[q], t = T[q];
int x = dep[s], y = dep[t];
if (x > y) {
swap(s, t);
swap(x, y);
}
chmin(ans[q], + cs[s] + get(0, 0, x, L[q]) + cs[t]);
chmin(ans[q], - cs[s] + get(1, x, y + 1, L[q]) + cs[t]);
chmin(ans[q], - cs[s] + get(2, y + 1, N, L[q]) - cs[t]);
}
}
return ans;
}
} // sub4
namespace sub5 {
vector<Int> run() {
int r = -1;
for (int u = 0; u < N; ++u) if ((int)G[u].size() == N - 1) {
r = u;
break;
}
vector<Int> cs(N, 0);
for (int i = 0; i < N - 1; ++i) {
cs[A[i] ^ B[i] ^ r] = C[i];
}
// cerr<<"r = "<<r<<", cs = "<<cs<<endl;
Cht cht;
{
vector<int> us(N);
for (int u = 0; u < N; ++u) us[u] = u;
sort(us.begin(), us.end(), [&](int u, int v) -> bool {
return (D[u] > D[v]);
});
for (const int u : us) {
cht.add(2 * cs[u], D[u]);
}
}
vector<Int> ans(Q, INF);
{
vector<int> qs(Q);
for (int q = 0; q < Q; ++q) qs[q] = q;
sort(qs.begin(), qs.end(), [&](int q0, int q1) -> bool {
return (L[q0] < L[q1]);
});
for (const int q : qs) {
if (S[q] == T[q]) {
chmin(ans[q], D[S[q]] * L[q]);
} else {
chmin(ans[q], D[S[q]] * L[q] + cs[S[q]] + cs[T[q]]);
chmin(ans[q], cs[S[q]] + cs[T[q]] + D[T[q]] * L[q]);
}
chmin(ans[q], cs[S[q]] + cht.get(L[q]) + cs[T[q]]);
}
}
return ans;
}
} // sub5
int main() {
for (; ~scanf("%d%lld%d", &N, &M, &Q); ) {
D.resize(N);
for (int u = 0; u < N; ++u) {
scanf("%lld", &D[u]);
}
A.resize(N - 1);
B.resize(N - 1);
C.resize(N - 1);
for (int i = 0; i < N - 1; ++i) {
scanf("%d%d%lld", &A[i], &B[i], &C[i]);
--A[i];
--B[i];
}
L.resize(Q);
S.resize(Q);
T.resize(Q);
for (int q = 0; q < Q; ++q) {
Int s, t;
scanf("%lld%lld", &s, &t);
--s;
--t;
L[q] = abs(s / N - t / N);
S[q] = s % N;
T[q] = t % N;
}
G.assign(N, {});
for (int i = 0; i < N - 1; ++i) {
G[A[i]].push_back(i);
G[B[i]].push_back(i);
}
vector<int> freqDeg(N, 0);
for (int u = 0; u < N; ++u) {
++freqDeg[G[u].size()];
}
vector<Int> ans;
if (M <= 20) {
ans = sub3::run();
} else if (freqDeg[1] <= 2) {
ans = sub4::run();
} else if (freqDeg[N - 1] >= 1) {
ans = sub5::run();
} else {
ans = brute::run();
}
for (int q = 0; q < Q; ++q) {
printf("%lld\n", ans[q]);
}
#ifdef LOCAL
const auto brt=brute::run();
cerr<<"brt = "<<brt<<endl;
cerr<<"ans = "<<ans<<endl;
assert(brt==ans);
#endif
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 3
Accepted
Test #1:
score: 3
Accepted
time: 2ms
memory: 8000kb
input:
97 99 1000 763118300 558295517 80676328 362318619 473105413 468927175 311496507 936935430 176032966 304576040 308583326 681580095 549392233 518152994 829474320 751189715 542810029 587869244 878512027 530678371 832766129 535259635 799122942 596982955 884696876 605325753 495661541 506105495 561218313 ...
output:
6130845802041 10806758605627 3440559556796 5426989115608 4458875959622 1566659300400 7908007295597 1846030561682 5112206409383 6968388472340 4706970599850 5270158948178 4633066810868 3176122148295 2331646415266 961435137842 14353365296423 9675072605938 4256954122467 7333255321628 8376795894537 12319...
result:
ok 1000 lines
Test #2:
score: 3
Accepted
time: 2ms
memory: 8264kb
input:
96 100 1000 31199641 534644486 57980198 794620020 322548308 524438614 467991232 68617179 243820212 229414440 471419229 316085673 271698528 136252783 926625435 615138376 200446739 551914057 483498389 879166147 512229523 45850421 337184110 799426876 46405170 427929494 235848997 861270528 291868400 616...
output:
2436336301732 4467388472930 6498834342013 6450642313333 4049880787954 7509100670176 5831628235154 4150554274586 3112250048344 202594784082 2974050754796 8714737807242 7727115169865 1321297431165 3071603311467 4662413775237 5469193332429 2306749862693 6240860740176 1297819731517 5602374629655 5876108...
result:
ok 1000 lines
Test #3:
score: 3
Accepted
time: 2ms
memory: 8172kb
input:
96 100 1000 557703101 38662752 91559144 406758463 248251717 279124287 667387330 272252891 892434115 281731667 162886140 786660171 350559478 909940602 476034354 78826379 748607300 381191755 708777514 223906483 954905399 405424569 356033791 565979037 5787205 21241249 399771402 280058652 527147793 5875...
output:
80606469890 86777173467 35481695596 11498756054 87983213070 37171191055 33172639202 31451029430 105454750479 31626589074 105218154775 46986908645 14488184465 20368758481 41150521804 57639739744 45269689956 24620398400 51392609182 44732144926 72097558763 13572235163 78364419227 40255815091 1195379951...
result:
ok 1000 lines
Test #4:
score: 3
Accepted
time: 1ms
memory: 6072kb
input:
96 96 1000 651436202 969634688 411838043 313319930 906863003 709869271 467187062 352351954 116039480 172098032 933097773 469945118 162439715 767382758 713254949 387661957 387494696 343642279 730353853 607472395 431993920 231539946 570437226 454446439 941394569 230535263 758579901 173778951 636556431...
output:
81136576805 65057090263 57308140599 70187240654 42682272024 83341639885 53487742661 53219947761 14656518493 18143524741 27930061212 75815621849 67528908552 39936561353 44548681818 122544815339 64143328818 13510734748 16412423500 108236922255 83503599273 53331146110 59331932211 93957710008 3825533077...
result:
ok 1000 lines
Test #5:
score: 3
Accepted
time: 0ms
memory: 6060kb
input:
100 97 1000 9442498 799978686 853182282 938513473 647407813 233204982 473300672 884708491 641608620 453797741 412704210 204494322 711344505 287815571 401113141 110034416 590478367 831110886 255614524 234577289 759353531 774504637 366342991 154214800 692604750 308540773 768713312 121270668 425512518 ...
output:
5006945326 9445360831 13045856109 4494648380 6833826505 3769548416 11380661054 5754815524 8246147623 4801077020 5798520769 1392753490 6948207422 12106173499 6097834765 4210216111 3541517785 5402770609 8790748574 10564152311 2826265999 5688050930 7790838243 2760570076 4835335024 5099967138 3178901350...
result:
ok 1000 lines
Test #6:
score: 3
Accepted
time: 1ms
memory: 6180kb
input:
100 100 1000 72360333 314738290 34206178 541145218 174183915 396182816 34673830 913434757 537587312 731274646 498514633 251108131 102959912 646618466 457048174 475505598 769612876 452196872 718739596 624410437 9031420 286458655 569299852 299007318 306647081 98662275 920437282 210801779 674405507 219...
output:
3655918495 8154487755 14137574021 9267685665 7011313073 12013474026 11488238672 8912382325 14741526855 17840835926 8748441239 7607949288 7949030269 10402650219 7895349896 9942798476 19632481428 6001424701 5150011606 14328944041 7536672479 10941755235 8915887826 11121022173 5570869661 5489621389 7171...
result:
ok 1000 lines
Test #7:
score: 3
Accepted
time: 0ms
memory: 6060kb
input:
100 100 1000 671289501 901524700 187943785 477991411 752983691 647246158 953320691 934684418 412368667 925367409 762075316 358848462 963075530 457549089 783006165 5363230 270806670 315603863 281313188 630063184 613102269 512390085 496057389 735900160 98801654 915737591 295267905 169463128 895274860 ...
output:
109982431024 38431175833 69772178732 48480356522 11451380583 20622728312 34853416584 49223376377 50708590192 23464488129 66396102290 49072787090 63071461232 100259758746 39605337609 43518034110 69171797185 76120124501 31732771736 43824267429 50401683487 18812219611 17592704047 40305088337 8902132735...
result:
ok 1000 lines
Test #8:
score: 3
Accepted
time: 1ms
memory: 3840kb
input:
100 100 1000 97012332 782222818 959933898 427265795 145416034 1879121 649904335 612684991 536487830 163534103 503165874 529288026 317196350 758782134 932469419 45296081 275446181 306725071 736168208 601979715 145679830 269223691 287672389 93736686 102440922 49242307 14300820 7040380 666185124 780231...
output:
43197564487 61281841688 44768770079 49385322040 35679440075 61129947858 71570620926 54095812113 65913522420 61326476305 50331061951 39723327870 52634647963 37572255373 44983995360 20296010788 65756945356 16562779626 52036714858 19671474013 46849723315 81935125579 28823217661 58491548742 63997977890 ...
result:
ok 1000 lines
Test #9:
score: 3
Accepted
time: 0ms
memory: 4044kb
input:
1 2 5 1000000000 1 1 1 2 2 1 2 2 1 1
output:
0 1000000000 1000000000 0 0
result:
ok 5 lines
Test #10:
score: 3
Accepted
time: 0ms
memory: 4000kb
input:
2 1 5 2 1 1 2 1000000000000 1 1 1 2 2 2 1 1 2 1
output:
0 1000000000000 0 0 1000000000000
result:
ok 5 lines
Subtask #2:
score: 5
Accepted
Dependency #1:
100%
Accepted
Test #11:
score: 5
Accepted
time: 576ms
memory: 198864kb
input:
4968 1000000000 4947 35398 17280 28501 30106 20289 12704 8742 38872 40600 32757 4709 49509 18925 8232 12657 5856 35298 16182 34878 29788 22757 3667 6147 33251 10280 21807 9932 43760 25234 21837 2000 42316 42227 30480 48217 18842 12065 3569 33962 10434 9965 6816 46030 14352 7696 39388 37027 2641 4927...
output:
27171080853044 16475800995047 47858729923137 38839226619025 68829717991555 66238455750161 69391451769289 61015426629738 34984939995941 46894448125681 66492516637760 84920329286569 37539473678478 26863746705396 24228771920185 20757319444368 62547461012321 29240639472051 33274823206812 29763531850641 ...
result:
ok 4947 lines
Test #12:
score: 5
Accepted
time: 611ms
memory: 199356kb
input:
4981 1000000000 4953 151742 15587 142065 128832 78714 10584 76914 106299 31568 52704 188707 28416 12984 61582 32999 186530 140703 147751 47543 175894 7752 191829 63929 114837 92045 50348 9699 45344 118713 116457 164914 29571 114745 130797 196228 187265 10152 1229 3383 97088 55723 174984 127564 39677...
output:
39175214953945 26200723643487 46943276265557 28283755650448 27784497704623 47477663513975 25153955655196 34658568119723 36390677477885 33283868432417 45462962712646 12634898326814 12553555762696 29763136584312 59969070638872 32014006456467 32113426391414 28135433219086 47248493737483 56523379856914 ...
result:
ok 4953 lines
Test #13:
score: 5
Accepted
time: 716ms
memory: 200092kb
input:
5000 1000000000 5000 7709 49516 81404 252939 337304 22843 327351 119119 469819 411352 375305 439834 224988 108405 27787 377575 382742 28074 255120 112472 244686 267973 224537 126626 101857 58364 298859 89790 474293 329321 441367 108105 278126 181944 246403 415680 273376 409094 169364 339149 196519 3...
output:
224644098442606 54861440986602 467147774410064 30362267317869 296379104994566 473075396075640 122083966788904 272566888272189 216858876719405 215746767255802 347849462280931 520897037387102 19480747175957 76784800656757 227716313122157 66425147109923 371507621482925 352677699283994 15598007683275 59...
result:
ok 5000 lines
Test #14:
score: 5
Accepted
time: 666ms
memory: 200236kb
input:
5000 1000000000 5000 253265 289565 480218 817881 388719 980412 67414 134135 762536 232380 406531 204614 200869 487447 967573 799195 802628 529421 333062 23170 711366 781842 202481 635401 256687 178162 589701 440119 691724 314358 566777 600174 401029 556684 811778 442351 501890 561627 65781 824606 38...
output:
229741484116980 164175833276967 99443665231144 54979925948709 767846577154984 82615685235989 491961122361479 258830345532802 337194117311972 330754218569722 208052850590856 109736272716532 772091540293926 46512912591879 222739255582971 104104517451050 155728909685296 619218590510841 329616510853980 ...
result:
ok 5000 lines
Test #15:
score: 5
Accepted
time: 638ms
memory: 200144kb
input:
5000 1000000000 5000 9165442 10032926 9324284 18687554 9961685 9532269 9821667 10084498 8903944 10118365 9775765 19733471 25638562 9383006 8825736 10428746 9066921 9401601 11694769 9998610 8896431 9186888 9834954 10583130 9321162 8943766 18203176 9463949 9187659 9612570 15398089 9597271 9774891 1006...
output:
3346954835952024 9683326417379824 3034185194974329 5653331361714484 4883637125911652 4144529883528686 1550288375157255 4849179484656607 7780090186793507 8760876193430258 2791370216037543 7961795785990098 3625625101008354 830776458752577 1201598422493424 5284514192781053 4673390841578381 221202738816...
result:
ok 5000 lines
Test #16:
score: 5
Accepted
time: 621ms
memory: 199988kb
input:
5000 1000000000 5000 10328285 10154180 9849852 9978950 9899905 10007975 9932544 9993918 9897530 10042306 9913325 9834599 10081669 9949843 12994559 10008823 9910840 11562770 9903505 10076660 9980716 9890836 9934511 12177770 9904174 9911365 10195395 9827430 9905113 10026600 9830577 9852209 10069231 99...
output:
1647385331743507 5524865815859729 3059643445230206 9470053705989838 9178562810279320 7549445324071426 2027312277087798 8273023856964174 9615573793436228 8112830816194948 8931306355319079 5885476349335756 1381279438337504 8765067046522175 2086999576794297 4002632440712670 7924144870658890 79357254043...
result:
ok 5000 lines
Test #17:
score: 5
Accepted
time: 467ms
memory: 200092kb
input:
5000 1000000000 5000 2513000 70283 123233 147800 2407113 6750 548577 2496501 1589521 382060 1078641 28843 12885 979911 249118 399277 335551 1496141 1161882 94180 1562518 1846018 2023612 688097 1505606 37597 1714464 2071436 2225125 2437519 1190287 1307370 1559871 443072 285850 1245177 429584 1750366 ...
output:
416853386301 245456106087 329277735132 507750960639 544942162618 258694401397 376595479438 395068151898 515513005035 523563370330 378130973019 272463853221 335748583419 223192323740 328497513286 436111548238 380723617773 389134126388 418340678864 415228727699 338316467895 344020792244 444955157605 5...
result:
ok 5000 lines
Test #18:
score: 5
Accepted
time: 1ms
memory: 3876kb
input:
1 2 5 1000000000 1 1 1 2 2 1 2 2 1 1
output:
0 1000000000 1000000000 0 0
result:
ok 5 lines
Test #19:
score: 5
Accepted
time: 1ms
memory: 3868kb
input:
2 1 5 2 1 1 2 1000000000000 1 1 1 2 2 2 1 1 2 1
output:
0 1000000000000 0 0 1000000000000
result:
ok 5 lines
Subtask #3:
score: 11
Accepted
Test #20:
score: 11
Accepted
time: 820ms
memory: 53548kb
input:
200000 20 200000 679416469 548913625 468159997 137709609 883140368 682558021 473174374 400192350 124143873 825920417 372498686 851213321 822264481 78195915 5427143 453304163 233551905 810910186 810046144 52603791 282167184 385032797 81387991 747194790 917579656 585184539 12659388 249218417 158295502...
output:
920563165 270738856 355012553 363898450 515535908 734168762 81197110 448355845 204186827 966151314 377621564 856252543 311456222 368700872 197258906 567302636 172379629 579171621 1043838058 244996663 621435809 278057792 727463012 573783312 395879848 500677226 891900111 1031612062 771021332 691010101...
result:
ok 200000 lines
Test #21:
score: 11
Accepted
time: 964ms
memory: 60384kb
input:
199998 20 199928 841581743 193826897 19260647 316900759 938030012 734551083 200340391 232139411 654311599 1143318 596086442 603556286 904977745 575551276 670573487 214312499 155571640 318139630 664877075 921888211 314261245 840096855 656620366 784431866 158438090 761901044 794827280 603867695 489777...
output:
623283525 8593864781 7874704109 155914357 3646556950 3740880356 3717912008 12901066587 1524759519 4985719750 2248493864 5114948482 3925676469 579421045 1507306567 2095047126 606785057 146334438 4045519468 8910005611 4581660381 4073333567 3935919804 676004871 2344714675 5021627074 5038533943 15002805...
result:
ok 199928 lines
Test #22:
score: 11
Accepted
time: 835ms
memory: 59784kb
input:
200000 20 200000 986369289 907363922 363774806 860858089 709715562 958810333 925993952 387795500 17150414 148015078 97834597 563293239 667378418 806659943 610215443 524417320 750481911 623874575 259982271 991286339 284729472 528334897 723997495 992805109 87608435 211268145 108070673 872622387 564643...
output:
10054223674 507380699 3217502558 539269 6315538 1928038308 1387049352 9511170763 5162637476 42235828 121118538 4623727820 10063019655 3205838882 4165257188 7261364 8095368917 8506365 5447619 2143078432 7359894792 10046658768 5435463 9232067090 6457897508 9629262 6399644 10022553858 6118703 8574986 1...
result:
ok 200000 lines
Test #23:
score: 11
Accepted
time: 792ms
memory: 53332kb
input:
200000 20 200000 747319812 390314311 314857121 211725609 263470750 979001169 50249481 658501549 959367948 893597081 177095123 795316289 460892240 678153548 117315462 524637159 259809686 647733605 266923024 115001443 857165610 939992604 661082449 538356122 31381162 71199751 506277142 981277756 241363...
output:
13662467103 15058589930 16458374764 15068421502 15811563571 13609092499 11356368656 16879299235 11336754159 13516222673 12846976402 18034454674 13386369283 17622328679 18631538755 15324696769 16685528530 14449065100 9460517704 13186912844 13733806309 18274703051 15926306728 14858932320 16642420472 1...
result:
ok 200000 lines
Test #24:
score: 11
Accepted
time: 1038ms
memory: 53536kb
input:
200000 20 200000 583112253 665093743 182048276 129269058 978415657 935953723 213813205 484649825 261214425 779189226 703649598 549454855 77715802 293926531 52713413 268118203 466091215 231039312 656528084 638468205 591205307 677293897 835642445 551021744 925782487 807259560 868830834 350378234 29765...
output:
316570302401 913144581593 913146543686 816894767104 544003812147 913148786078 468597633695 913144020995 913144301294 913147945181 183683477907 0 617634383371 666551848769 913147945181 5219486966 433656750247 524020417620 738877896143 913144301294 663163982315 913146543686 463256538270 913144861892 9...
result:
ok 200000 lines
Test #25:
score: 11
Accepted
time: 909ms
memory: 56272kb
input:
199962 20 199931 203506003 500751161 109978444 459010003 360964084 934576878 62980626 287820619 391197904 676602559 355742604 562232069 46776374 245111830 792609360 310542062 980352907 366602017 761654096 990177701 115948816 787238197 996548404 415779854 365866565 515988075 727704701 717436079 63512...
output:
798529011 60397088 1873438365 2138547241 1144282606 4083769129 4025496730 2344294194 200221409 1327038796 156436273 2085005208 76583374 1449673130 1074781339 257136048 3879420993 1472989996 25734720 1192283175 3633170363 1661044557 1096662244 257544665 540683798 2288140683 601119764 3096222006 21406...
result:
ok 199931 lines
Test #26:
score: 11
Accepted
time: 1ms
memory: 3872kb
input:
1 2 5 1000000000 1 1 1 2 2 1 2 2 1 1
output:
0 1000000000 1000000000 0 0
result:
ok 5 lines
Test #27:
score: 11
Accepted
time: 0ms
memory: 4036kb
input:
2 1 5 2 1 1 2 1000000000000 1 1 1 2 2 2 1 1 2 1
output:
0 1000000000000 0 0 1000000000000
result:
ok 5 lines
Subtask #4:
score: 12
Accepted
Test #28:
score: 12
Accepted
time: 943ms
memory: 149304kb
input:
200000 1000000000 200000 28270302 472359923 262785485 923929785 393684160 761485431 72038469 116384740 426631758 437934930 610834083 455314140 734276543 903544756 220163018 756113376 732404264 947339315 109784905 625451008 794076307 818852312 758007217 124450858 674924509 311761991 507260538 7032362...
output:
29294995135992468 9003943574137677 39324997066279292 37544709020512848 57388992119827952 54425124319330092 19450449300737912 25838911017710871 2608104102967357 32395369352281774 5765752637876701 65609495812941401 57820177390587134 1971831067795873 19213682025389514 30244870693646792 3672338761985429...
result:
ok 200000 lines
Test #29:
score: 12
Accepted
time: 983ms
memory: 149332kb
input:
199957 1000000000 199978 484184824 891546207 975734696 100539020 831491149 39172314 864159331 720402805 776042647 843662372 935604278 544595844 393931465 659783207 863682602 900000494 79169772 921429466 469390191 891091094 53691506 616777249 622575840 230565013 939987814 175664187 663514526 67841276...
output:
19959327553591648 32010533345091793 15410299665390255 71446530548310580 42757122329520314 44547359192496305 40421459068680865 12617048458606361 68505071787885633 20229193415512477 3959463349380309 52345766780671421 22183426380065088 29440145261757182 3846326653273891 34476543006148377 40819831884710...
result:
ok 199978 lines
Test #30:
score: 12
Accepted
time: 738ms
memory: 155964kb
input:
200000 1000000000 200000 422691889 268096182 223379104 268498792 392869265 1000000000 417073437 318368899 256962522 269513908 419697397 238567965 335189697 385837139 224219570 512586026 262793940 382819306 336110315 334843736 221179169 333772959 246702289 246377232 468460842 481454739 360039636 4372...
output:
224180993880896775 289564129076952626 275865980455069675 157628887637311054 198006388889029310 171540845366364406 335236582279069778 233727831092410768 286541513965424592 374120296090502383 310438489863336356 103195240752822032 189760302415610937 298279318492947402 291103583974138676 194715458020342...
result:
ok 200000 lines
Test #31:
score: 12
Accepted
time: 675ms
memory: 157044kb
input:
200000 1000000000 200000 602692841 601218040 601028255 1000000000 600403832 600232743 1000000000 599827124 599554412 1000000000 599301448 599113416 598989376 598786010 598636538 598553391 598370071 1000000000 598097301 598050441 597961490 1000000000 597806035 1000000000 597567223 597431163 597303663...
output:
209319542988838768 110577432223619722 125560261182969181 113185646498525815 136111861598679143 41978037866824629 96633947494918877 98374850209472659 242090527128147826 294694667971307324 138693418992158068 268811154379707206 69619449407249103 70205711769209505 59220392077886910 77428322381245404 195...
result:
ok 200000 lines
Test #32:
score: 12
Accepted
time: 645ms
memory: 183124kb
input:
199931 1000000000 199922 4013211 29714 1234462 1104572 1387655 273547 2854143 48754 3708907 92381 2416194 746211 782254 120292 5006444 2861799 5079340 2465365 2124023 4872770 133080 4355785 24081 4909586 243019 478235 278274 765568 1623339 518688 1021168 1990694 15052 3907624 3158505 4801536 2792353...
output:
396961167374 239043328316 303627822911 432749619117 361386708539 232557605389 310510144596 367430698623 278512942021 502706642903 232040628241 132457354501 521368949201 242967590974 429550834513 471199557886 266915933583 223731337727 151159169817 156285897711 298457093414 348439300538 252319058294 3...
result:
ok 199922 lines
Test #33:
score: 12
Accepted
time: 641ms
memory: 183840kb
input:
200000 1000000000 200000 5099932 4728906 2664545 3492339 646363 4078 481407 651875 32539 107203 1903484 515880 757323 3210572 10151 4880869 2293417 47189 3005497 2964135 91971 1797360 5095111 1494940 234796 3878867 4688923 399250 4093489 4917976 3217920 1135442 278278 2617067 2494154 4981268 4413226...
output:
491847427429 221565577072 416295244945 372886641436 238900215923 42152037417 220171926078 356278662471 242256776253 477527214604 97990314803 194326826650 543508546303 455921465239 422936284306 62633776772 240775687183 325298847287 546245176672 311618424599 365337654397 471518661673 232566667212 4090...
result:
ok 200000 lines
Test #34:
score: 12
Accepted
time: 1ms
memory: 3764kb
input:
1 2 5 1000000000 1 1 1 2 2 1 2 2 1 1
output:
0 1000000000 1000000000 0 0
result:
ok 5 lines
Test #35:
score: 12
Accepted
time: 0ms
memory: 3812kb
input:
2 1 5 2 1 1 2 1000000000000 1 1 1 2 2 2 1 1 2 1
output:
0 1000000000000 0 0 1000000000000
result:
ok 5 lines
Subtask #5:
score: 9
Accepted
Test #36:
score: 9
Accepted
time: 154ms
memory: 27324kb
input:
199918 1000000000 199903 1496 2382 3896 3664 1177 1627 2821 4200 3074 3783 2069 4403 629 2610 4991 4074 3033 2798 4333 3501 3667 3064 663 2821 2818 458 2950 4020 2665 3578 63 4855 4941 3492 2423 4510 1489 1018 4829 1912 3133 3174 309 287 2909 4102 4296 4526 3170 3683 4960 4863 4738 2927 2405 3600 44...
output:
1352416884531 1380463318391 923920163167 1525224977139 1405019709299 869269749781 715671043328 876194052054 1358007874327 127994985855 1230162209719 1532026808855 611656467332 1023855959729 414792924571 1316679734677 827308370883 1265411315424 821484360433 1051517948640 837509712760 582943943131 457...
result:
ok 199903 lines
Test #37:
score: 9
Accepted
time: 136ms
memory: 27384kb
input:
200000 1000 200000 809770918 700177243 142627650 840666719 799717263 288840787 130614153 965150450 584417569 833256629 453961603 553430999 842122932 156970995 233405993 462368588 449589390 97217337 576814616 526506175 16887352 919946415 588340411 47310125 508028561 746882745 289969878 38349443 85588...
output:
1585694392495 706038536805 586801212025 729763504879 1121912701709 602929530934 1384874490966 932809860298 1786651350814 1173133997984 642188971333 1847564817170 874110129257 1634207197990 1165001912684 860420326934 364758620851 736767366986 901294347345 1499330839732 451636930949 1002710230684 1556...
result:
ok 200000 lines
Test #38:
score: 9
Accepted
time: 172ms
memory: 27316kb
input:
200000 1000000000 200000 399998482 399998882 643012112 481981456 399998451 475990021 399997292 399997409 399996369 399998092 399998185 399998416 399998701 399997027 399996347 1000000000 411997672 399996237 399997188 402404134 399996973 399998072 459327897 399997196 399997360 606704265 399997369 3999...
output:
56425935917250335 348929904541748910 43150321666095229 218746357373815571 108846332361563136 211578526026780722 142755080047590213 244555928973138123 59355666550218703 274305014995294225 171177308635990844 94566903236734112 84270300399685207 317423517245573254 902979060499211 14514565807335715 18696...
result:
ok 200000 lines
Test #39:
score: 9
Accepted
time: 149ms
memory: 30536kb
input:
199989 1000000000 199949 5101893 2534711 252776 33497 4575476 620658 35790 1061631 1362697 834917 2062598 2789238 2540552 2557066 725856 2407848 4266144 1731334 653868 4676650 235573 2010805 1576557 922173 617762 1140093 387911 618359 2084018 2717580 9938 4014950 411349 3801906 341206 665844 2556003...
output:
376419619600 353028349944 783455928283 427146243318 508001272847 231025894377 614377184831 496116219491 384142701402 337878147372 528478063399 414595122323 604998898988 244135680083 319848781263 358386785447 481117281935 464006706964 356458898506 260105342030 610113746365 259007651455 414991108424 2...
result:
ok 199949 lines
Test #40:
score: 9
Accepted
time: 148ms
memory: 30704kb
input:
200000 1000000000 200000 1101540 573488 61066 1014872 39283 626062 84341 591377 109026 505272 1339 74452 729192 49315 521939 959958 249731 940337 56264 1071790 609623 239862 57448 809987 464526 111430 226312 124386 673550 421690 211347 45875 138962 705453 739456 464892 44238 52980 905593 205558 5198...
output:
655436303263 616441802310 638361564730 586321577191 519122088245 660130086237 389806954608 241891011597 423594953230 510963332372 630353140994 627262451077 339051346548 308888235187 550167732447 354951509166 308776095000 597351022439 625625736560 772346222022 549689478477 667370706484 319926160326 2...
result:
ok 200000 lines
Test #41:
score: 9
Accepted
time: 1ms
memory: 3808kb
input:
1 2 5 1000000000 1 1 1 2 2 1 2 2 1 1
output:
0 1000000000 1000000000 0 0
result:
ok 5 lines
Test #42:
score: 9
Accepted
time: 1ms
memory: 4044kb
input:
2 1 5 2 1 1 2 1000000000000 1 1 1 2 2 2 1 1 2 1
output:
0 1000000000000 0 0 1000000000000
result:
ok 5 lines
Subtask #6:
score: 0
Time Limit Exceeded
Test #43:
score: 0
Time Limit Exceeded
input:
200000 1000000000 200000 81882094 47220813 43282454 17633207 52769165 4830673 31396360 64793163 9174729 36727563 71268262 24662923 40146030 1430053 62926106 30042905 1330107 81817720 98841078 87766129 51155045 23216268 79896310 66625868 87854925 42976560 86542933 28336449 34932261 19698851 584453 90...
output:
result:
Subtask #7:
score: 0
Time Limit Exceeded
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Test #63:
score: 0
Time Limit Exceeded
input:
49968 1000000000 49902 4944156 4815511 9240823 7764082 994590 2019985 2016609 9208180 4884222 2671715 5813918 8082427 5690017 4750252 6475214 2447878 7680249 8636430 6031922 1028528 2689700 1920015 8635882 5610090 9361349 7547902 5838245 7362790 240533 4193002 8850309 9498339 6763561 8096700 8938068...
output:
result:
Subtask #8:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
100%
Accepted
Dependency #4:
100%
Accepted
Dependency #5:
100%
Accepted
Dependency #6:
0%