QOJ.ac

QOJ

IDSubmission IDProblemHackerOwnerResultSubmit timeJudge time
#674#211784#7520. Monster GeneratorWorld_CreaterzhouhuanyiFailed.2024-06-12 08:25:242024-06-12 08:25:25

Details

Extra Test:

Invalid Input

input:

100 1000000000000000000
167963268582359628 12 796572804448927207 75
581295299967900485 16 441570086795465955 107
396883827275098029 4 422670291827223908 50
574446525560801542 9 506737033475892749 48
488307419582407544 11 789356033256612425 49
202476734336674519 2 776078335945682250 90
73045336927024...

output:


result:

FAIL Integer parameter [name=a[i]] equals to 167963268582359628, violates the range [1, 10^15] (stdin, line 2)

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#211784#7520. Monster GeneratorzhouhuanyiAC ✓13ms3896kbC++143.6kb2023-10-12 21:14:582023-11-04 18:37:26

answer

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cassert>
#define N 200
using namespace std;
long long read()
{
	char c=0;
	long long sum=0;
	while (c<'0'||c>'9') c=getchar();
	while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
	return sum;
}
int sgn(__int128 x)
{
	if (x>0) return 1;
	else if (x==0) return 0;
	else return -1;
}
struct reads
{
	long long a,ta,b,tb;
	__int128 ra,rb;
	bool operator < (const reads &t)const
	{
		if (sgn(rb-ra)!=sgn(t.rb-t.ra)) return sgn(rb-ra)>sgn(t.rb-t.ra);
		else if (rb-ra>=0) return ra<t.ra;
		else return rb>t.rb;
	}
};
reads st[N+1];
struct points
{
	long long x,y;
	bool operator < (const points &t)const
	{
		return x!=t.x?x<t.x:y<t.y;
	}
};
points tongs[N+1],dque[N+1];
points operator + (points a,points b)
{
	return (points){a.x+b.x,a.y+b.y};
}
points operator - (points a,points b)
{
	return (points){a.x-b.x,a.y-b.y};
}
int n,length,lengths,top;
long long tong[5*N*N+1],m;
unsigned long long ans;
__int128 operator * (points a,points b)
{
	return (__int128)(a.x)*b.y-(__int128)(a.y)*b.x;
}
bool check(points a,points b,points c)
{
	return (b-a)*(c-a)>=0;
}
unsigned long long F(long long x)
{
	if (x<0) return 0;
	return (unsigned long long)((__int128)(x)*(x+1)>>1);
}
long long get(long long x,long long y)
{
	return x>0?x/y:-(-x+y-1)/y;
}
void solve(long long l,long long r)
{
	long long res=0,res2=0,sl,sr;
	lengths=top=0;
	for (int i=1;i<=n;++i) st[i].ra=st[i].a+(__int128)(l)*st[i].ta,st[i].rb=st[i].b+(__int128)(l)*st[i].tb;
	sort(st+1,st+n+1);
	for (int i=1;i<=n;++i) tongs[++lengths]=(points){res2+st[i].ta,res+st[i].a},res+=st[i].a-st[i].b,res2+=st[i].ta-st[i].tb;
	sort(tongs+1,tongs+lengths+1);
	for (int i=1;i<=lengths;++i)
	{
		while (top>=2&&check(dque[top-1],dque[top],tongs[i])) top--;
		while (top&&dque[top].x==tongs[i].x) top--;
		dque[++top]=tongs[i];
	}
	for (int i=1;i<=top;++i)
	{
		sl=l,sr=r;
		if (i>=2) sl=max(sl,get(dque[i-1].y-dque[i].y,dque[i].x-dque[i-1].x)+1);
		if (i+1<=top) sr=min(sr,get(dque[i].y-dque[i+1].y,dque[i+1].x-dque[i].x));
		if (sl<=sr) ans+=(unsigned long long)(dque[i].x)*(F(sr)-F(sl-1))+(unsigned long long)(dque[i].y)*(unsigned long long)(sr-sl+1);
	}
	return;
}
int main()
{
	n=read(),m=read();
	for (int i=1;i<=n;++i) st[i].a=read(),st[i].ta=read(),st[i].b=read(),st[i].tb=read();
	sort(st+1,st+n+1);
	for (int i=1;i<=n;++i)
	{
		if (st[i].a<st[i].b&&st[i].ta>st[i].tb&&(st[i].b-st[i].a)%(st[i].ta-st[i].tb)==0) tong[++length]=(st[i].b-st[i].a)/(st[i].ta-st[i].tb);
		if (st[i].a>st[i].b&&st[i].ta<st[i].tb&&(st[i].a-st[i].b)%(st[i].tb-st[i].ta)==0) tong[++length]=(st[i].a-st[i].b)/(st[i].tb-st[i].ta);
		if (st[i].a<=st[i].b&&st[i].ta>st[i].tb) tong[++length]=(st[i].b-st[i].a)/(st[i].ta-st[i].tb)+1;
		if (st[i].a>=st[i].b&&st[i].ta<st[i].tb) tong[++length]=(st[i].a-st[i].b)/(st[i].tb-st[i].ta)+1;
	}
	for (int i=1;i<=n;++i)
		for (int j=1;j<=n;++j)
			if (i!=j)
			{
				if (st[i].a<st[j].a&&st[i].ta>st[j].ta&&(st[j].a-st[i].a)%(st[i].ta-st[j].ta)==0) tong[++length]=(st[j].a-st[i].a)/(st[i].ta-st[j].ta);
				if (st[i].b<st[j].b&&st[i].tb>st[j].tb&&(st[j].b-st[i].b)%(st[i].tb-st[j].tb)==0) tong[++length]=(st[j].b-st[i].b)/(st[i].tb-st[j].tb);
				if (st[i].a<=st[j].a&&st[i].ta>st[j].ta) tong[++length]=(st[j].a-st[i].a)/(st[i].ta-st[j].ta)+1;
				if (st[i].b<=st[j].b&&st[i].tb>st[j].tb) tong[++length]=(st[j].b-st[i].b)/(st[i].tb-st[j].tb)+1;
			}
	sort(tong+1,tong+length+1);
	while (length&&tong[length]>m) length--;
	length=unique(tong+1,tong+length+1)-tong-1,tong[length+1]=m+1;
	for (int i=0;i<=length;++i) solve(tong[i],tong[i+1]-1);
	printf("%llu\n",ans);
	return 0;
}