QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#785267 | #7646. 优惠购物 | miaomiaomiaowu | 15 | 598ms | 84020kb | C++20 | 2.7kb | 2024-11-26 17:21:47 | 2024-11-26 17:21:47 |
Judging History
answer
#include<bits/stdc++.h>
#include<ext/pb_ds/priority_queue.hpp>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MP make_pair
#define pii pair<int,int>
const double PI=acos(-1.0);
template <class Miaowu>
inline void in(Miaowu &x){
char c;x=0;bool f=0;
for(c=getchar();c<'0'||c>'9';c=getchar())f|=c=='-';
for(;c>='0'&&c<='9';c=getchar())x=(x<<1)+(x<<3)+(c^48);
x=f?-x:x;
}
const int N=1e6+5;
int T,n;
ll m,c,a[N],b[N],d[N],use[N],id[N];
struct SGT{
ll mn[N<<2],tag[N<<2];
inline int ls(int u){return u<<1;}
inline int rs(int u){return u<<1|1;}
inline void build(int u,int l,int r){
if(l==r)return mn[u]=d[l-1]-use[l],void();
int mid=l+r>>1;
build(ls(u),l,mid),build(rs(u),mid+1,r);
mn[u]=min(mn[ls(u)],mn[rs(u)]);
}
inline void pd(int u){
if(!tag[u])return;
mn[ls(u)]+=tag[u],tag[ls(u)]+=tag[u];
mn[rs(u)]+=tag[u],tag[rs(u)]+=tag[u];
tag[u]=0;
}
inline void upd(int u,int l,int r,int L,int R,ll x){
if(l>=L&&r<=R)return mn[u]+=x,tag[u]+=x,void();
int mid=l+r>>1;pd(u);
if(mid>=L)upd(ls(u),l,mid,L,R,x);
if(mid<R)upd(rs(u),mid+1,r,L,R,x);
mn[u]=min(mn[ls(u)],mn[rs(u)]);
}
inline ll qry(int u,int l,int r,int L,int R){
if(l>=L&&r<=R)return mn[u];
int mid=l+r>>1;pd(u);ll res=2e18;
if(mid>=L)res=min(res,qry(ls(u),l,mid,L,R));
if(mid<R)res=min(res,qry(rs(u),mid+1,r,L,R));
return res;
}
}sgt;
int main(){
for(cin>>T;T;T--){
in(n),in(m),in(c);d[0]=m;
for(int i=1;i<=n;i++)in(a[i]);
for(int i=1;i<=n;i++)in(b[i]),id[i]=i;
for(int i=1;i<=n+1;i++)d[i]=use[i]=0;
for(int i=1;i<=n;i++)use[i]=min(d[i-1],min(a[i]%c,b[i])),d[i]=d[i-1]+(a[i]-use[i])/c-use[i];
sgt.build(1,1,n+1);
for(int i=n;i>=1;i--){
ll qwq=c*min((min(b[i],d[i-1])-use[i])/c,sgt.qry(1,1,n+1,i+1,n+1)/(c+1));
use[i]+=qwq,sgt.upd(1,1,n+1,i,i,-qwq),sgt.upd(1,1,n+1,i+1,n+1,-qwq/c-qwq);
}
stable_sort(id+1,id+n+1,[](int _1,int _2){return b[_1]-use[_1]>b[_2]-use[_2];});
priority_queue<int>Q;
for(int ii=1,i=id[ii];ii<=n;i=id[++ii]){
Q.push(i);
while(!Q.empty()){
int xx=Q.top();ll qwq=min(sgt.qry(1,1,n+1,xx,xx),sgt.qry(1,1,n+1,xx+1,n+1)-1);
if(qwq<b[i]-use[i])break;
qwq=min(qwq,b[xx]-use[xx]),use[xx]+=qwq;
sgt.upd(1,1,n+1,xx,xx,-qwq),sgt.upd(1,1,n+1,xx+1,n+1,-1-qwq),Q.pop();
}
}
ll ans=0;
for(int i=1;i<=n;i++)ans+=a[i]-use[i];
printf("%lld\n",ans);
}
return 0;
}
详细
Subtask #1:
score: 5
Accepted
Test #1:
score: 5
Accepted
time: 0ms
memory: 14224kb
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: 5
Accepted
time: 0ms
memory: 14324kb
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 29 34 47 41
result:
ok 5 lines
Test #3:
score: 5
Accepted
time: 2ms
memory: 13924kb
input:
5 10 2 18 2 7 3 1 2 2 10 3 10 9 1 7 2 0 1 1 8 2 8 8 10 6 17 10 7 9 6 8 2 9 5 5 4 10 1 5 5 3 0 4 1 2 2 10 5 10 1 6 3 8 7 7 7 9 7 4 0 3 2 4 1 0 5 5 4 2 10 2 7 6 2 9 9 3 8 7 8 10 10 1 0 8 3 2 2 0 2 1 2 10 6 12 7 10 8 1 2 4 7 8 3 7 6 10 1 0 0 4 0 8 1 0
output:
47 59 54 64 51
result:
ok 5 lines
Subtask #2:
score: 0
Wrong Answer
Test #4:
score: 10
Accepted
time: 562ms
memory: 83028kb
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: 0
Wrong Answer
time: 598ms
memory: 84020kb
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:
464602224908439
result:
wrong answer 1st lines differ - expected: '464602224908438', found: '464602224908439'
Subtask #3:
score: 10
Accepted
Dependency #1:
100%
Accepted
Test #7:
score: 10
Accepted
time: 0ms
memory: 13944kb
input:
1 500 225 2 0 0 2 1 2 1 4 0 0 0 0 0 2 1 2 0 0 1 0 0 1 1 2 0 2 2 3 1 0 0 2 2 0 1 1 2 1 3 1 3 2 0 0 1 2 0 2 0 0 1 1 0 1 1 1 0 1 0 2 3 0 0 1 3 1 0 2 2 1 1 4 1 1 2 1 1 0 3 2 0 0 0 1 3 0 1 0 1 2 1 0 0 2 1 1 1 2 3 2 2 2 1 1 2 2 0 0 1 1 0 0 1 0 1 1 0 1 3 1 2 0 2 2 1 1 2 0 1 0 4 2 0 0 0 0 1 4 1 0 1 0 1 0 0 ...
output:
231
result:
ok single line: '231'
Test #8:
score: 10
Accepted
time: 0ms
memory: 13992kb
input:
1 500 253 10 1 2 1 1 0 0 1 3 3 1 0 0 0 0 0 0 0 2 1 0 0 2 1 0 0 0 2 0 0 1 2 1 0 2 2 1 1 2 1 0 2 1 0 0 0 1 0 2 2 0 1 0 0 1 0 0 1 1 1 0 1 1 0 1 2 0 1 0 0 1 1 1 0 0 0 1 2 2 1 1 1 0 3 1 0 0 0 1 0 1 1 4 3 1 0 0 0 1 0 1 3 1 1 1 1 4 1 0 0 0 1 1 1 2 2 0 0 3 0 0 1 0 2 2 1 0 2 0 1 0 2 0 0 1 1 0 2 1 0 1 1 1 0 0...
output:
278
result:
ok single line: '278'
Test #9:
score: 10
Accepted
time: 2ms
memory: 14248kb
input:
100 5 3 11 0 1 3 0 1 0 0 0 0 0 5 3 11 0 0 2 2 1 0 0 0 1 1 5 3 10 2 1 0 1 1 2 1 0 0 1 5 3 11 2 2 0 0 1 0 0 0 0 1 5 2 11 0 0 4 0 1 0 0 3 0 1 5 5 10 2 0 0 0 3 1 0 0 0 1 5 5 11 3 1 1 0 0 3 0 1 0 0 5 2 11 0 1 2 0 2 0 1 2 0 0 5 4 10 2 1 1 1 0 0 1 0 1 0 5 4 10 1 1 1 2 0 1 0 1 2 0 5 2 11 2 0 3 0 0 1 0 3 0 0...
output:
5 3 2 4 3 3 1 3 3 1 3 3 4 1 3 3 1 4 3 4 2 5 3 4 4 2 4 2 2 3 4 4 3 3 2 3 0 2 3 4 4 3 3 2 2 4 5 2 4 4 3 3 4 3 4 2 3 3 3 2 4 4 5 2 4 2 4 2 3 4 4 4 4 2 2 1 2 4 1 3 4 3 3 0 3 5 5 2 4 3 2 3 4 3 3 4 2 3 5 3
result:
ok 100 lines
Test #10:
score: 10
Accepted
time: 0ms
memory: 14248kb
input:
50 10 4 11 2 0 0 2 0 0 1 1 4 0 2 0 0 1 0 0 1 1 2 0 10 9 11 0 1 2 0 1 1 1 2 2 0 0 0 2 0 1 0 1 1 2 0 10 4 11 1 2 1 3 0 0 2 0 1 0 1 0 1 3 0 0 0 0 0 0 10 9 10 1 0 1 1 2 1 0 1 2 1 1 0 0 0 2 0 0 1 0 0 10 7 11 0 3 0 2 3 0 0 2 0 0 0 3 0 0 3 0 0 2 0 0 10 9 10 0 1 0 1 1 1 1 2 1 2 0 0 0 0 1 1 1 0 0 0 10 6 11 0...
output:
6 3 6 6 3 7 7 6 2 7 3 6 8 4 6 5 3 5 8 8 6 5 7 8 8 8 4 8 5 4 3 5 7 5 4 8 5 5 7 6 7 6 7 8 8 4 2 4 7 6
result:
ok 50 lines
Subtask #4:
score: 0
Wrong Answer
Dependency #3:
100%
Accepted
Test #11:
score: 0
Wrong Answer
time: 2ms
memory: 14000kb
input:
60 10 17 2 14 8 11 5 9 14 9 9 8 13 12 3 8 5 9 1 0 4 2 10 10 13 2 11 11 10 15 8 12 7 8 8 10 11 6 3 8 2 4 7 8 1 4 10 7 2 18 6 15 6 11 6 12 8 9 9 15 0 9 0 5 6 0 6 4 3 10 4 3 12 8 16 11 9 5 6 9 10 14 0 0 5 7 8 1 6 2 1 5 10 23 3 10 14 11 7 9 7 7 12 17 6 5 8 1 5 5 7 7 1 4 3 10 27 3 13 7 11 12 11 12 10 9 9...
output:
58 60 80 75 60 55 68 67 62 76 76 71 71 61 74 61 54 62 62 72 64 78 78 64 63 74 73 57 66 67 63 40 40 46 57 58 53 64 65 46 46 30 41 46 61 54 59 48 64 51 55 57 57 73 40 63 56 70 55 38
result:
wrong answer 1st lines differ - expected: '57', found: '58'
Subtask #5:
score: 0
Skipped
Dependency #4:
0%
Subtask #6:
score: 0
Wrong Answer
Test #24:
score: 0
Wrong Answer
time: 2ms
memory: 13968kb
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:
46254742 42284068 28465970 36815342 18797080 16608540 60082784 55963386 98157466 99455211 58990996 4474138 59994584 40677040 117326435 26562075 51644186 94269994 59007134 38720301 55628210 40921356 30237996 20727720 83424160 84045033 66629574 18910773 84890678 72094414 49832625 110722258 1360310 120...
result:
wrong answer 7th lines differ - expected: '59809954', found: '60082784'
Subtask #7:
score: 0
Skipped
Dependency #6:
0%
Subtask #8:
score: 0
Skipped
Dependency #6:
0%
Subtask #9:
score: 0
Skipped
Dependency #2:
0%