QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#439579 | #7520. Monster Generator | yyandy | WA | 6ms | 3884kb | C++14 | 3.5kb | 2024-06-12 12:28:38 | 2024-06-12 12:28:38 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 i128;
const int N=505;
i128 ga[N],gb[N],a[N],b[N],da[N],db[N],tA[N],tB[N],T[N],ttA[N],ttB[N];
int stk[N],n,p[N];
ll m;
inline bool check(int x,int y){
return ga[x]+max((i128)0,ga[y]-gb[x])<ga[y]+max((i128)0,ga[x]-gb[y]);
}
inline bool cmp(int x,int y){
i128 xa=-ga[x]+gb[x],xb=-ga[y]+gb[y];
if(xa>=0&&xb<0)return 1;
if(xa<0&&xb>=0)return 0;
return check(x,y);
}
inline i128 slope(int x,int y){
// y< x time
if(tA[y]<=tA[x])return -2e18;
else if(tB[x]==tB[y])return 2e18;
return (tA[y]-tA[x]-1)/(tB[x]-tB[y])+1;
}
inline bool ncmp(int x,int y){
return tB[x]>tB[y];
}
inline i128 bcheck(i128 x,i128 y){
bool flag=x<0;
ll L=1,R=1e18+1e5,mn=2e18;
while(L<=R){
ll mid=L+R>>1;
if((x+mid*y<0)!=flag)
mn=min(mn,mid),R=mid-1;
else L=mid+1;
}
return mn;
}
inline ll ccheck(ll L,ll R,int x,int y){
ll mn=R+5;
ga[x]=L*da[x]+a[x];
gb[x]=L*db[x]+b[x];
ga[y]=L*da[y]+a[y];
gb[y]=L*db[y]+b[y];
bool flag=check(x,y);
while(L<=R){
ll mid=L+R>>1;
ga[x]=mid*da[x]+a[x];
gb[x]=mid*db[x]+b[x];
ga[y]=mid*da[y]+a[y];
gb[y]=mid*db[y]+b[y];
if(check(x,y)!=flag){
mn=min(mn,mid);
R=mid-1;
}else{
L=mid+1;
}
}
return mn;
}
int main(){
// freopen("yuanshen.in","r",stdin);
// freopen("yuanshen.out","w",stdout);
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin>>n>>m;
for(int i=1;i<=n;++i){
ll A,DA,B,DB;cin>>A>>DA>>B>>DB;
a[i]=A;da[i]=DA;b[i]=B;db[i]=DB;
}
vector<ll> pl;
pl.push_back(0),pl.push_back(m+1);
for(int i=1;i<=n;++i){
ll mn=bcheck(b[i]-a[i],db[i]-da[i]);
if(mn<=m)pl.push_back(mn);
}
for(int i=1;i<=n;++i){
for(int j=i+1;j<=n;++j){
int x=i,y=j;
// 分段函数,分为三段, $[0,L] (L,R] (R,m]$ 首先搞出这个 L,R 然后在段内二分
ll resA=bcheck(a[y]-b[x],da[y]-db[x]);// 满足
ll resB=bcheck(a[x]-b[y],da[x]-db[y]);
if(resA>=0&&resA<=m)pl.push_back(resA),pl.push_back(resA+1);
if(resB>=0&&resB<=m)pl.push_back(resB),pl.push_back(resB+1);
ll tmpA=ccheck(0,min(resA,resB)-1,x,y);
if(tmpA<=min({m,resA-1,resB-1}))pl.push_back(tmpA),pl.push_back(tmpA+1);
ll tmpB=ccheck(min(resA,resB),max(resA,resB)-1,x,y);
if(tmpB<=min(m,max(resA,resB)-1)&&tmpB>=min(resA,resB))pl.push_back(tmpB),pl.push_back(tmpB+1);
ll tmpC=ccheck(max(resA,resB),m,x,y);
if(tmpC>=max(resA,resB)&&tmpC<=m)pl.push_back(tmpC),pl.push_back(tmpC+1);
}
}
sort(pl.begin(),pl.end());
pl.erase(unique(pl.begin(),pl.end()),pl.end());
ull ans=0;
int sz=pl.size();
for(int i=0;i+1<sz;++i){
ll t=pl[i],nxt=pl[i+1];p[0]=0;
for(int i=1;i<=n;++i)p[i]=i,ga[i]=a[i]+t*da[i],gb[i]=b[i]+t*db[i];
sort(p+1,p+n+1,cmp);tA[0]=tB[0]=0;
for(int i=1;i<=n;++i)
tA[i]=tA[i-1]+b[p[i-1]]-a[p[i]],
tB[i]=tB[i-1]+db[p[i-1]]-da[p[i]];
for(int i=0;i<=n;++i)
p[i]=i;
sort(p,p+n+1,ncmp);
for(int i=0;i<=n;++i)
ttA[i]=tA[p[i]],
ttB[i]=tB[p[i]];
for(int i=0;i<=n;++i)
tA[i]=ttA[i],
tB[i]=ttB[i];
int tp=0;stk[++tp]=0;
for(int i=1;i<=n;++i){//
while(tp&&(tA[i]<=tA[stk[tp]]||(tp>1&&slope(stk[tp-1],stk[tp])>slope(stk[tp],i))))tp--;
stk[++tp]=i;
}
T[0]=t;
for(int i=1;i<tp;++i){
T[i]=max(T[i-1],(i128)slope(stk[i],stk[i+1]));
T[i]=min(T[i],(i128)nxt);
}T[tp]=nxt;
for(int i=1;i<=tp;++i)
if(T[i]>T[i-1]){
ans-=tA[stk[i]]*(T[i]-T[i-1]);
ull g=(i128)(T[i]+T[i-1]-1)*(T[i]-T[i-1])/2;
ans-=tB[stk[i]]*g;
}
}
cout<<ans<<'\n';
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3644kb
input:
3 5 3 1 5 2 4 2 1 3 1 9 100 1
output:
113
result:
ok single line: '113'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
3 100000000 3 1 5 2 4 2 1 3 1 9 100 1
output:
35000000549999998
result:
ok single line: '35000000549999998'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3668kb
input:
10 1000000000000000000 776874380544333 197 471391764744275 33 159838820333814 107 677112662750393 41 962335658276824 48 255593531071176 11 127404116579775 209 268525254990127 34 647620110614714 76 897947476313307 13 146196843402516 221 772928712898807 39 637929916804442 2 716937021892338 15 64200226...
output:
17883317185357051350
result:
ok single line: '17883317185357051350'
Test #4:
score: 0
Accepted
time: 1ms
memory: 3884kb
input:
10 1000000000000 519946 5 967590 4 367668 9 772494 6 635694 5 932710 1 260259 2 627580 1 84994 3 52124 6 447095 4 705749 6 427312 2 977458 7 540121 1 292993 5 556831 6 321679 4 567919 4 609512 4
output:
1542003553318518337
result:
ok single line: '1542003553318518337'
Test #5:
score: 0
Accepted
time: 1ms
memory: 3876kb
input:
10 1000000000000000000 972703917532605 2 524956306619424 679 644953227221677 4 562488807303931 696 726248880302017 2 678581164692315 811 63290732871341 4 2359762326353 451 355584232678496 3 295959529542702 895 982076563374348 4 315626935294595 161 202583559712801 1 987516708328993 170 26590404960673...
output:
4582284981606185217
result:
ok single line: '4582284981606185217'
Test #6:
score: 0
Accepted
time: 1ms
memory: 3884kb
input:
10 1000000000000000000 915236950983 25 924829121702 314 142125786492 33 125091250839 71 702305171043 11 468800042449 438 449646370235 9 56198959092 472 246955215365 12 950417123809 62 646952653060 4 858914642874 441 693754630072 34 490226765023 91 273330383457 25 749838451697 371 635897703553 24 847...
output:
18304932886689493500
result:
ok single line: '18304932886689493500'
Test #7:
score: -100
Wrong Answer
time: 6ms
memory: 3588kb
input:
100 1000000000000000000 839671173511709 107 620743247548148 134 338569457755976 9 455191878916920 157 56529874788057 33 993208347666256 99 553193266380324 120 589361808163439 126 866467572275902 19 13931460152331 210 630774124991101 56 253227140072409 133 970610042608501 106 332792633317838 252 8813...
output:
13953072760591532882
result:
wrong answer 1st lines differ - expected: '2159229278647499039', found: '13953072760591532882'