QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#192416 | #7520. Monster Generator | ucup-team266# | WA | 102ms | 4076kb | C++14 | 2.4kb | 2023-09-30 14:29:15 | 2023-11-04 18:36:03 |
Judging History
你现在查看的是最新测评结果
- [2023-11-04 16:34:13]
- hack成功,自动添加数据
- (//qoj.ac/hack/422)
- [2023-11-04 16:28:16]
- hack成功,自动添加数据
- (//qoj.ac/hack/420)
- [2023-09-30 14:29:15]
- 提交
answer
#include<bits/stdc++.h>
#define ll long long
#define ie __int128
#define ull unsigned long long
using namespace std;
ull ans;
int n,cn;ll m,a[110],ak[110],b[110],bk[110],qc[101000];
ie sq(ie x,ie y){
if(y<0)x=-x,y=-y;
if(y==0||x<=0)return -1;
return (x+y-1)/y;
}
ie xq(ie x,ie y){
if(y<0)x=-x,y=-y;
if(y==0||x<=0)return -1;
return x/y;
}
void zph(ll y){
for(int e=-2;e<=2;e++){
ll x=y+e;
if(x>0&&x<=m)qc[++cn]=x;
}
}
struct tb{ie x,y;int id;}e[110];
int typ(ie a){
if(a>0)return 1;
if(a==0)return 0;
return -1;
}
bool cmp(tb a,tb b){
int ka=typ(a.y-a.x),kb=typ(b.y-b.x);
if(ka!=kb)return ka>kb;
if(ka<=0)return a.y>b.y;
return a.x<b.x;
}
struct xd{ie k,b;}o[110];
bool cmp2(xd x,xd y){if(x.k!=y.k)return x.k>y.k;return x.b<y.b;}
int sta[110],top;
bool chk(int x,int y,int z){
return ((long double)(o[y].b-o[x].b))/(o[x].k-o[y].k)>=((long double)(o[z].b-o[y].b))/(o[y].k-o[z].k);
}
ull S(ie l,ie r){
return (ull)((l+r)*(r-l+1)/2);
}
ull calc(ull l,ull r,ull b,ull k){
ull og=(r-l+1)*b;
og+=S(l,r)*k;
return og;
}
int main(){
scanf("%d%lld",&n,&m);
qc[++cn]=m+1,qc[++cn]=0;
for(int i=1;i<=n;i++)scanf("%lld%lld%lld%lld",&a[i],&ak[i],&b[i],&bk[i]);
for(int i=1;i<=n;i++)if(ak[i]!=bk[i])
zph(sq(b[i]-a[i],ak[i]-bk[i]));
for(int i=1;i<=n;i++)for(int j=i+1;j<=n;j++){
if(ak[i]!=ak[j])zph(sq(a[j]-a[i],ak[i]-ak[j]));
if(bk[i]!=bk[j])zph(sq(b[j]-b[i],bk[i]-bk[j]));
}
sort(qc+1,qc+cn+1),cn=unique(qc+1,qc+cn+1)-qc-1;
ull ans=0;
for(int ii=1;ii<cn;ii++){
ie X=qc[ii];
for(int i=1;i<=n;i++)e[i]=(tb){X*ak[i]+a[i],X*bk[i]+b[i],i};
sort(e+1,e+n+1,cmp);
ie qb=0,qk=0;
o[0]=(xd){qk,qb};
for(int io=1;io<=n;io++){
int i=e[io].id;
qb-=a[i],qk-=ak[i];
o[i]=(xd){qk,qb};
//ins (qb,qk)
qb+=b[i],qk+=bk[i];
}
if(qc[ii]==qc[ii+1]-1){
ie mi=0;
for(int i=0;i<=n;i++)mi=min(mi,o[i].b+o[i].k*X);
ans+=mi;
continue;
}
sort(o,o+n+1,cmp2);
top=0;
for(int i=0;i<=n;i++){
if(top&&o[i].k==o[sta[top]].k)continue;
while(top>1&&chk(sta[top-1],sta[top],i))top--;
sta[++top]=i;
}
for(int i=1;i<=top;i++){
ie tl=qc[ii],tr=qc[ii+1]-1;
if(i>1)tl=max(tl,sq(o[sta[i-1]].b-o[sta[i]].b,o[sta[i]].k-o[sta[i-1]].k));
if(i<top)tr=min(tr,xq(o[sta[i]].b-o[sta[i+1]].b,o[sta[i+1]].k-o[sta[i]].k));
if(tl<=tr)ans+=calc(tl,tr,o[sta[i]].b,o[sta[i]].k);
}
}
cout<<-ans;
return 0;
}
//a>b c>d
//x-a-b-c>=0
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3668kb
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: 3960kb
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: 3680kb
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: 0ms
memory: 3976kb
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: 0ms
memory: 3680kb
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: 0ms
memory: 3700kb
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: 0
Accepted
time: 1ms
memory: 3752kb
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:
2159229278647499039
result:
ok single line: '2159229278647499039'
Test #8:
score: 0
Accepted
time: 2ms
memory: 4076kb
input:
100 1000000000000000000 926447257775795 188 535928580576730 524 773621914798781 805 607314524993852 999 433706296251306 467 260773017334982 276 627420175261216 730 936517336182015 391 944793592281860 143 916701567834795 374 985020926183290 391 155471328385744 343 158052135419112 152 37256868527793 4...
output:
845915142005167939
result:
ok single line: '845915142005167939'
Test #9:
score: 0
Accepted
time: 0ms
memory: 3676kb
input:
5 10000000 82420 1 83004 12 90974 1 5052 16 74853 1 50459 3 40080 1 8547 14 73449 1 29852 11
output:
50401135100561
result:
ok single line: '50401135100561'
Test #10:
score: -100
Wrong Answer
time: 102ms
memory: 3916kb
input:
100 1000000000000000000 9993245793650 4 9241831921583 115 6604842581175 13 7477954917260 107 7956734211252 3 351959292590 21 8744829275263 11 1121812966924 88 4383873864556 10 7802901884633 87 2999374450961 5 7728117026444 119 2606040601922 2 9450726899416 95 463533606932 4 456141627827 113 51628088...
output:
1462629487049893562
result:
wrong answer 1st lines differ - expected: '1462626783113250968', found: '1462629487049893562'