QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#738827 | #7646. 优惠购物 | SkyMaths | 10 | 481ms | 107480kb | C++14 | 6.1kb | 2024-11-12 20:02:48 | 2024-11-12 20:02:49 |
Judging History
answer
// #pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define rep(i,l,r) for (int i(l), i##end(r); i <= i##end; ++i)
#define per(i,r,l) for (int i(r), i##end(l); i >= i##end; --i)
#define ll long long
#define fi first
#define se second
#define eb emplace_back
#define File(filename) freopen(filename".in", "r", stdin), freopen(filename".out", "w", stdout)
#define clr(arr) memset(arr, 0, sizeof(arr))
using namespace std;
template <typename Tx> inline void read(Tx &x) {x = 0; bool f = 0; char ch = getchar(); while (ch < '0' || ch > '9') f ^= ch == '-', ch = getchar(); while (ch <= '9' && ch >= '0') x = x * 10 + ch - '0', ch = getchar(); if (f) x = -x;}
template <typename Tx, typename ...Ty> inline void read(Tx &x, Ty &...y) {read(x); read(y...);}
template <typename Tx> inline void O_write(Tx x) {if (x > 9) O_write(x / 10); putchar('0' + x % 10);}
template <typename Tx> inline void write(Tx x, char ch = '\n') {O_write(x < 0 ? (putchar('-'), -x) : x); putchar(ch);}
template <typename T> inline void cmax(T &x, T y) {if (x < y) x = y;}
template <typename T> inline void cmin(T &x, T y) {if (x > y) x = y;}
namespace Main {
const int N = 1e6 + 9;
int n, m, c;
ll a[N], b[N], x[N], s[N], d[N];
const ll inf = 0x3f3f3f3f3f3f3f3f;
struct SegmentTree {
#define lc (p << 1)
#define rc (p << 1 | 1)
ll tag[N * 4], mn[N * 4];
#define pushup(p) mn[p] = min(mn[lc], mn[rc])
void add_tag(int p, ll v) {
tag[p] += v, mn[p] += v;
}
void pushdown(int p) {
if (tag[p]) {
add_tag(lc, tag[p]);
add_tag(rc, tag[p]);
tag[p] = 0;
}
}
void build(int p = 1, int l = 0, int r = n) {
tag[p] = 0;
if (l == r) {
mn[p] = s[l];
return ;
}
int mid = (l + r) >> 1;
build(lc, l, mid), build(rc, mid + 1, r);
pushup(p);
}
void modify(int ql, int qr, ll v, int p = 1, int l = 0, int r = n) {
if (qr < l || r < ql) return;
if (ql <= l && r <= qr) return add_tag(p, v);
pushdown(p);
int mid = (l + r) >> 1;
modify(ql, qr, v, lc, l, mid), modify(ql, qr, v, rc, mid + 1, r);
pushup(p);
}
ll querymin(int ql, int qr, int p = 1, int l = 0, int r = n) {
if (ql <= l && r <= qr) return mn[p];
pushdown(p);
int mid = (l + r) >> 1;
if (qr <= mid) return querymin(ql, qr, lc, l, mid);
if (mid < ql) return querymin(ql, qr, rc, mid + 1, r);
return min(querymin(ql, qr, lc, l, mid), querymin(ql, qr, rc, mid + 1, r));
}
} sgt;
// rep (_, 1, n) {
// ll p = 0;
// ll z = -1;
// rep (i, 1, n) {
// ll t = min(b[i] - x[i], s[i - 1]);
// rep (j, i, n) cmin(t, s[j] - 1);
// if (t >= z) p = i, z = t;
// }
// if (z <= 0) break;
// x[p] += z;
// s[p - 1] -= z;
// rep (i, p, n) s[i] -= (z + 1);
// }
ll qry(int i) {
ll t = min(sgt.querymin(i - 1, i - 1), sgt.querymin(i, n) - 1);
return t;
}
void put(int p, ll z) {
if (z <= 0) return ;
x[p] += z;
sgt.modify(p - 1, p - 1, -z);
sgt.modify(p, n, -(z + 1));
}
priority_queue <int> pq;
inline void skymaths() {
read(n, m, c);
rep (i, 1, n) read(a[i]);
rep (i, 1, n) read(b[i]);
s[0] = m;
rep (i, 1, n) {
s[i] = s[i - 1] + a[i] / c;
}
// s'[i] = s[i] - x[i + 1]
{
ll mn = inf; rep (i, 0, n) d[i] = 0;
per (i, n, 1) {
ll t = min(b[i], a[i] % c);
cmin(mn, s[i - 1]); cmin(t, mn);
// rep (j, i - 1, n) cmin(t, s[j]);
x[i] += t;
d[i - 1] -= t;
mn -= t;
// rep (j, i - 1, n) s[j] -= t;
}
rep (i, 1, n) d[i] += d[i - 1];
rep (i, 0, n) s[i] += d[i];
}
{
ll mn = inf; rep (i, 0, n) d[i] = 0;
per (i, n, 1) {
ll t = min((b[i] - x[i]) / c, s[i - 1] / c);
cmin(mn, s[i]); cmin(t, mn / (c + 1));
// rep (j, i, n) cmin(t, s[j] / (c + 1));
x[i] += t * c;
s[i - 1] -= t * c;
mn -= t * (c + 1);
d[i] -= t * (c + 1);
// rep (j, i, n) s[j] -= t * (c + 1);
}
rep (i, 1, n) d[i] += d[i - 1];
rep (i, 0, n) s[i] += d[i];
}
// rep (_, 1, n) {
// ll p = 0;
// ll z = -1;
// rep (i, 1, n) {
// ll t = min(b[i] - x[i], s[i - 1]);
// rep (j, i, n) cmin(t, s[j] - 1);
// if (t >= z) p = i, z = t;
// }
// if (z <= 0) break;
// x[p] += z;
// s[p - 1] -= z;
// rep (i, p, n) s[i] -= (z + 1);
// }
sgt.build();
static pair <ll, int> pr[N];
static ll nw[N];
rep (i, 1, n) pr[i] = make_pair(b[i] - x[i], i);
sort(pr + 1, pr + n + 1, greater<pair <ll, int> >());
rep (i, 1, n) nw[i] = pr[i].first;
int cnt = unique(nw + 1, nw + n + 1) - nw - 1, r = 1;
nw[cnt + 1] = -1;
while (!pq.empty()) pq.pop();
rep (_, 1, cnt + 1) {
ll w = nw[_];
while (!pq.empty()) {
// no limit
int i = pq.top();
ll z = qry(i);
// qry only care s limit not b[i] - x[i]!!!
if (z >= w) {
put(i, z);
pq.pop();
} else break;
}
while (r <= n && pr[r].fi >= w) pq.push(pr[r++].se);
while (!pq.empty()) {
int i = pq.top();
ll z = qry(i);
// qry only care s limit not b[i] - x[i]!!!
if (z >= w) {
put(i, z);
pq.pop();
} else break;
}
}
ll ans(0);
rep (i, 1, n) ans += a[i] - x[i];
rep (i, 1, n) x[i] = 0;
write(ans);
}
signed main() {
//freopen("a.in", "r", stdin);
int T = 1;
read(T);
rep (Tid, 1, T) {
skymaths();
}
return 0;
} } signed main() { Main::main(); return 0;}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 5
Accepted
time: 0ms
memory: 19904kb
input:
5 10 9 8 10 5 1 2 10 9 2 9 8 8 5 3 1 1 7 2 2 1 3 0 10 1 5 3 2 6 10 5 10 1 4 8 1 1 2 5 6 2 3 1 3 6 1 10 6 10 5 4 9 5 4 10 8 5 2 4 2 4 2 5 1 1 7 5 0 0 10 5 10 6 2 7 4 3 8 10 5 5 4 1 0 6 3 3 5 4 5 0 0 10 6 12 6 8 7 3 1 4 10 2 9 10 0 3 1 3 1 3 1 0 4 7
output:
51 42 49 48 54
result:
ok 5 lines
Test #2:
score: 0
Wrong Answer
time: 2ms
memory: 20028kb
input:
5 10 8 16 2 4 3 3 10 1 8 7 1 10 2 1 1 2 9 0 2 2 1 0 10 6 5 1 8 7 1 5 1 2 5 5 2 1 6 0 0 4 1 0 0 0 0 10 9 9 10 5 3 1 2 1 9 3 1 10 3 0 2 0 2 1 8 2 1 9 10 4 8 1 4 7 9 2 4 7 9 4 6 1 3 2 4 1 0 4 0 4 2 10 10 7 5 1 6 4 7 5 10 6 2 7 2 0 3 4 5 4 7 4 2 1
output:
41 28 34 47 41
result:
wrong answer 2nd lines differ - expected: '29', found: '28'
Subtask #2:
score: 10
Accepted
Test #4:
score: 10
Accepted
time: 473ms
memory: 107480kb
input:
1 1000000 75424149 4 15519624 393474467 66570532 20552964 884794646 633920424 885627436 891022137 207531470 263467015 853563838 909020263 225156643 843397191 555130236 28501962 70380880 400094075 351542363 118716292 772000502 495729611 777038576 845271464 346378405 179347308 90713310 683636539 92786...
output:
400011543086868
result:
ok single line: '400011543086868'
Test #5:
score: 10
Accepted
time: 481ms
memory: 106140kb
input:
1 1000000 290027657 13 304913277 796843021 516017645 319050677 454050563 311934679 136029540 790505371 382952680 125583971 728245481 902515808 812248168 868676972 790078499 415156440 464267202 582710403 940789661 787826252 967007727 383461878 355142003 38823668 153257857 934717389 686901242 36112867...
output:
464602224908438
result:
ok single line: '464602224908438'
Test #6:
score: 10
Accepted
time: 344ms
memory: 20320kb
input:
100 10000 555225459 12 283175257 921770254 7299205 304241949 267180864 651891533 164511492 581458656 706908893 739975249 933584512 596665557 469159082 990911824 978336498 995722553 404329338 864926421 108033148 939393219 883683355 155563579 13934792 536244919 137715285 306298646 959297422 220012187 ...
output:
4588217379181 4629253346598 4052616322788 4685633463207 4611498546635 3286925309424 4700753892257 4389905037385 4633607365103 4688195153421 4178811594145 4752054242985 4664825925836 4665776689820 3962158296116 4640134664463 3364786516333 4529228891211 4651138496620 4597397577514 3343211719775 377293...
result:
ok 100 lines
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Skipped
Dependency #4:
0%
Subtask #6:
score: 0
Wrong Answer
Test #24:
score: 0
Wrong Answer
time: 0ms
memory: 20032kb
input:
600 10 21 2 1434256 1792820 8964100 10756920 6454152 717128 9681228 7529844 7171280 10398356 1075692 1075692 1434256 10039792 358564 717128 717128 5737024 3227076 1792820 10 5 4 5500368 6875460 4125274 687544 5500368 4469049 4125276 2750183 9969416 5156593 4469049 3781503 687546 0 1718865 343773 0 2...
output:
46075460 39791714 28465970 34054190 17576490 15588718 52668466 55963386 98157466 99455211 58990996 4396101 59994584 40467365 117326435 26464778 51419646 94269994 55661369 38720301 50486106 40921356 30237996 20727720 79192499 83723022 64525482 18910772 84890678 56421714 49832625 100159936 1360310 118...
result:
wrong answer 1st lines differ - expected: '46254742', found: '46075460'
Subtask #7:
score: 0
Skipped
Dependency #6:
0%
Subtask #8:
score: 0
Skipped
Dependency #6:
0%
Subtask #9:
score: 0
Skipped
Dependency #2:
100%
Accepted
Dependency #5:
0%