QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#738911 | #9569. Subway | Deltax | WA | 20ms | 220096kb | C++14 | 4.5kb | 2024-11-12 20:14:06 | 2024-11-12 20:14:06 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
#define fi first
#define se second
#define mkp make_pair
#define pb push_back
typedef pair <int, int> pii;
inline int read() {
int x = 0, f = 0;
char c = getchar();
while (!isdigit(c)) {if (c == '-') f = 1; c = getchar();}
while (isdigit(c)) x = (x << 1) + (x << 3) + (c & 15), c = getchar();
return f? -x : x;
}
const int MAXN = 2e5;
struct DS {
priority_queue <pii> q2, d2;
priority_queue <pii, vector<pii>, greater<pii>> q1, d1;
inline int size() {return q1.size() - d1.size();}
pii max() {
while (d2.size() && q2.top() == d2.top()) q2.pop(), d2.pop();
if (q2.size())
return q2.top();
return mkp(-1, -1);
}
pii min() {
while (d1.size() && q1.top() == d1.top()) q1.pop(), d1.pop();
if (q1.size())
return q1.top();
return mkp(-1, -1);
}
void ins(pii x) {q1.push(x); q2.push(x);}
void del(pii x) {d1.push(x); d2.push(x);}
}ds[MAXN + 10];
typedef long long LL;
typedef pair<LL, LL> pll;
const int MAXS = MAXN*60;
const LL inf = 2e18;
struct SEG {
pll tag[MAXS]; //fi k, se b
int lc[MAXS], rc[MAXS], tot;
inline LL calc(pll v, LL x) {
if (v == mkp(0ll, 0ll)) return inf;
// cerr << v.fi << " " << v.se << " " << x << endl;
return v.fi * x + v.se;
}
void upd2(int l, int r, pll v, int &s) {
if (!s) s = ++tot;
if (tag[s] == mkp(0ll, 0ll)) {
tag[s] = v;
return;
}
int mid = l + r >> 1;
LL v1 = calc(v, mid);
LL v2 = calc(tag[s], mid);
if (v1 < v2) swap(v1, v2), swap(tag[s], v);
if (l == r) return;
if (calc(v, l) < calc(tag[s], l)) upd2(l, mid, v, lc[s]);
else upd2(mid + 1, r, v, rc[s]);
}
void upd1(int l, int r, int L, int R, pll v, int &s) {
if (!s) s = ++tot;
if (L > r || R < l) return;
if (L <= l && r <= R) {
upd2(l, r, v, s);
return;
}
int mid = l + r >> 1;
upd1(l, mid, L, R, v, lc[s]);
upd1(mid + 1, r, L, R, v, rc[s]);
return;
}
LL query(int l, int r, int x, int s) {
if (!s) return inf;
if (l == r) return calc(tag[s], x);
int mid = l + r >> 1; LL v = calc(tag[s], x);
if (x <= mid) return min(query(l, mid, x, lc[s]), v);
return min(query(mid + 1, r, x, rc[s]), v);
}
}seg;
pii pos[MAXN + 10];
//vector <pii> G[MAXN + 10];
int a[MAXN + 10], b[MAXN + 10];
LL dp[MAXN + 10];
typedef pair <LL, int> pli;
priority_queue <pli, vector<pli>, greater<pli>> q;
int rt[MAXN + 10];
const int MAXW = 1e6;
LL query(int x, int p) {
return seg.query(1, MAXW, x, rt[p]);
}
inline void chkmin(int x, LL v) {
if (dp[x] > v)
dp[x] = v, q.push(mkp(v, x));
}
bool vis[MAXN + 10];
int w[MAXN + 10];
//vector <pair<int, LL>> G[MAXN + 10];
void dij() {
while (!q.empty()) {
int x = q.top().se; q.pop();
if (vis[x]) continue;
vis[x] = 1;
int p = pos[x].fi;
LL k = ::b[pos[x].se], m = dp[x];
ds[p].del(mkp(a[pos[x].se], x));
seg.upd1(1, MAXW, 1, MAXW, mkp(k, m), rt[p]);
if (ds[p].size()) {
// DS tmp = ds[p];
// while (ds[p].size()) {
pii p1 = ds[p].min();
pii p2 = ds[p].max();
LL v1 = query(p1.fi, p);
LL v2 = query(p2.fi, p);
chkmin(p1.se, v1);
chkmin(p2.se, v2);
ds[p].del(p1);
// }
// ds[p] = tmp;
}
if (w[x]) {
if (x + 1 == 6) {
// cerr << "s" << endl;
}
chkmin(x + 1, dp[x] + w[x]);
}
/*
for (auto i : G[x]) {
int v = i.fi; LL w = i.se;
chkmin(v, dp[x] + w);
}*/
}
}
//vector <int> vec[MAXN + 10];
signed main() {
//freopen ("std.in", "r", stdin);
//freopen ("std.out", "w", stdout);
int n, k;
n = read(), k = read();
for (int i = 1; i <= k; ++i) a[i] = read();
for (int i = 1; i <= k; ++i) b[i] = read();
int tot = 0;
for (int i = 1; i <= k; ++i) {
int p = read();
for (int j = 1; j <= p; ++j) {
int x = read();
pos[tot + j].fi = x;
pos[tot + j].se = i;
ds[x].ins(mkp(a[i], tot + j));
// vec[x].pb(tot + j);
if (j < p) {
w[tot + j] = read();
//G[tot + j].pb(mkp(tot + j + 1, w));
}
}
tot += p;
}
//cerr << tot << endl;
/*
for (int i = 1; i <= n; ++i)
for (auto u : vec[i])
for (auto k : vec[i])
G[u].pb(mkp(k, 1ll * b[pos[u].se] * a[pos[k].se]));
*/
for (int i = 1; i <= tot; ++i) {
if (pos[i].fi == 1) q.push(mkp(0ll, i));
else dp[i] = inf;
}
dij();
static LL ans[MAXN + 10];
for (int i = 1; i <= n; ++i) ans[i] = inf;
for (int i = 1; i <= tot; ++i) {
// cout << dp[i] << " ";
ans[pos[i].fi] = min(ans[pos[i].fi], dp[i]);
}
//cout << endl;
for (int i = 2; i <= n; ++i)
printf("%lld ", ans[i]);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 3ms
memory: 219944kb
input:
6 3 1 5 1 5 5 1 3 1 2 2 3 3 3 5 1 2 1 4 3 3 4 5 4 6
output:
2 5 21 14 18
result:
ok 5 number(s): "2 5 21 14 18"
Test #2:
score: 0
Accepted
time: 4ms
memory: 218696kb
input:
6 3 1 5 1 5 5 1 5 1 2 2 100 3 100 6 1 4 5 1 100 2 4 3 100 5 1 4 2 3 1 5
output:
2 31 43 37 136
result:
ok 5 number(s): "2 31 43 37 136"
Test #3:
score: 0
Accepted
time: 11ms
memory: 218888kb
input:
5 9 278281 70119 511791 834898 25300 63487 609134 236836 394497 835557 287345 579404 879128 636344 306393 569430 152565 47119 2 3 823004250 4 2 1 25427550 3 2 1 15849621 3 2 1 701911826 5 3 5 679672631 3 907176714 2 2 1 817370554 2 2 3 697987914 2 2 4 873900795 2 2 1 814305954 5
output:
817370554 15849621 80811085745 701911826
result:
ok 4 number(s): "817370554 15849621 80811085745 701911826"
Test #4:
score: 0
Accepted
time: 8ms
memory: 218524kb
input:
5 10 436148 103565 528276 212202 680282 92724 609031 560815 80390 406327 546832 581372 731920 348686 791433 98906 112247 118131 361076 724950 4 1 213029090 4 415633732 5 581145231 3 2 4 306227294 2 2 1 713116112 4 2 3 99672714 5 2 3 975143846 1 5 4 249118026 5 689334413 1 597093740 2 553624319 3 3 4...
output:
597093740 765908995 213029090 628662822
result:
ok 4 number(s): "597093740 765908995 213029090 628662822"
Test #5:
score: 0
Accepted
time: 15ms
memory: 218484kb
input:
3 5 696710 837216 390019 431068 960618 589388 829806 692481 154511 282620 2 1 711629163 3 2 1 781784306 3 2 1 686636041 3 2 3 794790206 2 2 1 844212542 2
output:
844212542 686636041
result:
ok 2 number(s): "844212542 686636041"
Test #6:
score: 0
Accepted
time: 8ms
memory: 219056kb
input:
3 8 344877 101098 328614 735002 476606 635558 573861 261083 964379 333960 25186 276560 258996 683650 765559 582374 2 3 838262394 1 2 2 863940316 3 2 2 476918371 3 3 3 320092619 1 400754003 2 3 3 150885055 2 90507792 1 2 3 190275693 2 2 2 600234969 3 2 2 679446528 3
output:
400754003 29224357199
result:
ok 2 number(s): "400754003 29224357199"
Test #7:
score: 0
Accepted
time: 3ms
memory: 219452kb
input:
50 52 895514 29433 851800 887860 340384 95967 506578 666268 850660 602220 717255 242039 34055 752012 248567 170469 505996 823344 143369 390858 112988 892365 15368 617804 351619 557340 788960 990487 283825 272924 24678 130649 341049 980236 558990 254726 682005 963825 953074 603477 706464 340694 23541...
output:
632126151 479346918 492618840 3695787776 22624579200 174047740 416387993526 21429733469 15831777447 203893499 522142321620 977566721 279122223 30345963113 804573598 73397618725 6389037892 224856032596 416404080694 75356833904 69909552850 4504114918 13173874327 1104455938 275720760247 136977429637 22...
result:
ok 49 numbers
Test #8:
score: 0
Accepted
time: 4ms
memory: 218768kb
input:
50 186 909405 536090 349598 989013 812836 176449 79855 101754 179492 328610 751840 298905 429840 327083 222463 770826 222448 679356 524717 759894 186015 464746 390432 205629 893518 619709 777762 985329 612480 308146 507216 337177 463052 10105 150939 411855 75743 831031 391242 914978 198839 259846 36...
output:
279207921 30546650 3955157971 366881738 678883775 822326137 828131153 510756214 2799968412 2039093375 2727811374 2032421076 1966318841 894245748 2686792493 218322703 721713806 962052764 2586140415 201519887 722596289 49603757 329009601 562632121 73396118 399363911 1252345566 631600417 106456928 5055...
result:
ok 49 numbers
Test #9:
score: 0
Accepted
time: 11ms
memory: 220096kb
input:
50 746 109522 187240 733057 796323 66411 270785 937748 93610 470338 557856 166396 453860 431444 832088 13928 85925 15012 650718 328138 113957 812853 420621 146202 494017 985809 97315 96915 329400 118469 310530 501365 375790 461794 395440 784193 383084 825278 651991 584960 198686 644465 936326 856317...
output:
108689636 452441994 85834082 194842954 1581446 78212329 192476904 317795566 17889600 204753389 160234611 32867254 60240077 5211225 59666696 182239665 3783349 260084869 211347631 275823469 278103417 62390636 110457213 390191494 14670321 1101923 516180268 190362002 66561551 565544855 21826762 21720545...
result:
ok 49 numbers
Test #10:
score: -100
Wrong Answer
time: 20ms
memory: 219172kb
input:
100 241 564812 561763 140723 436240 394309 44156 384984 144017 947539 422591 408747 362914 763371 162274 318323 676445 200578 532099 333815 768706 880020 140834 689221 544561 536480 764898 626990 221618 173930 13451 775752 248365 66936 533899 658027 131826 28438 795120 203253 433075 523346 599087 67...
output:
267913444 25339157310 8314344093 5464367180 1286326436 90461126 8907606133 16347606802 14711829080 8971431750 170752878 397694350 1037375748 18879356054 1501065529 2069064987 9584178341 17014391217 903970115 490753396 1632578522 10191345537 36790983230 2195645069 11593917652 18457433523 759764904 72...
result:
wrong answer 23rd numbers differ - expected: '26994814823', found: '36790983230'