QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#192315#7520. Monster Generatorucup-team266#RE 0ms3608kbC++142.4kb2023-09-30 14:13:432023-11-04 18:36:01

Judging History

你现在查看的是最新测评结果

  • [2023-11-04 18:36:01]
  • 管理员手动重测本题所有提交记录
  • 测评结果:RE
  • 用时:0ms
  • 内存:3608kb
  • [2023-11-04 17:09:10]
  • 管理员手动重测本题所有提交记录
  • 测评结果:0
  • 用时:0ms
  • 内存:3736kb
  • [2023-09-30 14:13:44]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:3968kb
  • [2023-09-30 14:13:43]
  • 提交

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 x){if(x>0&&x<=m)qc[++cn]=x;x++;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 (o[y].b-o[x].b)*(o[y].k-o[z].k)>=(o[z].b-o[y].b)*(o[x].k-o[y].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<=m;i++)qc[++cn]=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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3608kb

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: -100
Runtime Error

input:

3 100000000
3 1 5 2
4 2 1 3
1 9 100 1

output:


result: