QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#797515 | #7646. 优惠购物 | fairyqq28 | 10 | 221ms | 91008kb | C++14 | 2.8kb | 2024-12-03 09:53:32 | 2024-12-03 09:53:32 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#define rep(i, a, b) for(int i = (a); i <= (b); i++)
#define per(i, a, b) for(int i = (a); i >= (b); i--)
#define ls (u<<1)
#define rs (u<<1|1)
#define mid ((l+r)>>1)
using namespace std;
typedef long long ll;
const int N = 1000010;
class TREE{
struct node{
ll mn, lzy;
void tag(ll x) {mn += x, lzy += x;}
};
node t[N<<2];
void up(int u) {t[u].mn = min(t[ls].mn, t[rs].mn);}
void down(int u){
if(!t[u].lzy) return;
t[ls].tag(t[u].lzy), t[rs].tag(t[u].lzy), t[u].lzy = 0;
}
public:
void build(int u, int l, int r, ll *a){
t[u].lzy = 0;
if(l == r) t[u].mn = a[l];
else build(ls, l, mid, a), build(rs, mid + 1, r, a), up(u);
}
void update(int u, int l, int r, int x, int y, ll val){
if(x <= l && r <= y) return t[u].tag(val);
down(u);
if(x <= mid) update(ls, l, mid, x, y, val);
if(y > mid) update(rs, mid + 1, r, x, y, val);
up(u);
}
ll query(int u, int l, int r, int x, int y){
if(x <= l && r <= y) return t[u].mn;
down(u);
if(y <= mid) return query(ls, l, mid, x, y);
if(x > mid) return query(rs, mid + 1, r, x, y);
return min(query(ls, l, mid, x, y), query(rs, mid + 1, r, x, y));
}
};
TREE tr;
int n;
ll m, c, a[N], b[N], ans, s[N], x[N];
void solve1(){
s[1] = m;
rep(i, 1, n){
ll t = min({s[i], a[i] % c, b[i]});
ans -= t, x[i] += t;
s[i+1] = s[i] - t + (a[i] - t) / c;
}
}
void solve2(){
ll mn = s[n+1];
per(i, n, 1){
ll t = min({(b[i] - x[i]) / c, (s[i] - x[i]) / c, mn / (c+1)});
x[i] += t * c, ans -= t * c;
mn = min(mn - t * (c+1), s[i] - x[i]);
}
// printf("solve2: %lld\n", mn);
s[1] = m;
rep(i, 1, n) s[i+1] = s[i] - x[i] + (a[i] - x[i]) / c;
}
priority_queue<int> q;
void solve3(){
static int id[N];
static ll tmp[N], rk[N];
rep(i, 1, n+1) tmp[i] = s[i] - x[i];
tr.build(1, 1, n+1, tmp);
rep(i, 1, n) id[i] = i, rk[i] = min(c-1, b[i] - x[i]);
id[n+1] = n+1, rk[n+1] = 0;
sort(id+1, id+n+1, [&](int x, int y) {return rk[x] > rk[y];});
for(int l = 1, r = 0; l <= n; l = r + 1){
while(r < n && rk[id[r+1]] == rk[id[l]]) q.push(id[++r]);
while(!q.empty()){
int x = q.top();
ll t = min(tr.query(1, 1, n+1, x, x), tr.query(1, 1, n+1, x+1, n+1) - 1);
if(t <= rk[id[r+1]]) break;
t = min(t, c-1);
ans -= t; q.pop();
tr.update(1, 1, n+1, x, x, -t);
tr.update(1, 1, n+1, x+1, n+1, -t-1);
}
}
}
void solve(){
while(!q.empty()) q.pop();
ans = 0;
rep(i, 1, n) x[i] = 0;
scanf("%d%lld%lld", &n, &m, &c);
rep(i, 1, n) scanf("%lld", &a[i]), ans += a[i];
rep(i, 1, n) scanf("%lld", &b[i]);
solve1();
solve2();
solve3();
printf("%lld\n", ans);
}
int main(){
int T; scanf("%d", &T); while(T--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 5
Accepted
time: 0ms
memory: 16216kb
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: 0ms
memory: 16212kb
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: 166ms
memory: 91008kb
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: 168ms
memory: 90896kb
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: 221ms
memory: 19016kb
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: 4ms
memory: 16236kb
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:
46254741 42284053 28465970 36815341 18797079 16608538 59809952 55963386 98157466 99455211 58990996 4474137 59994584 40677039 117326435 26562073 51644185 94269994 59007133 38720301 55628209 40921356 30237996 20727720 83424156 84045025 66629573 18910772 84890678 72094409 49832625 110722254 1360310 120...
result:
wrong answer 1st lines differ - expected: '46254742', found: '46254741'
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%