QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#211755#7520. Monster GeneratorzhouhuanyiWA 0ms3928kbC++142.9kb2023-10-12 20:57:282023-10-12 20:57:29

Judging History

你现在查看的是测评时间为 2023-10-12 20:57:29 的历史记录

  • [2023-11-04 18:37:25]
  • 管理员手动重测本题所有提交记录
  • 测评结果:WA
  • 用时:0ms
  • 内存:3784kb
  • [2023-11-04 17:11:37]
  • 管理员手动重测本题所有提交记录
  • 测评结果:0
  • 用时:0ms
  • 内存:3600kb
  • [2023-10-12 20:57:29]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:3928kb
  • [2023-10-12 20:57:28]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#define N 200
using namespace std;
const long long inf=(long long)(1e18);
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;
	int num;
	bool operator < (const reads &t)const
	{
		if (sgn(rb-ra)!=sgn(t.rb-t.ra)) return sgn(rb-ra)!=sgn(t.rb-t.ra)?sgn(rb-ra)>sgn(t.rb-t.ra):num<t.num;
		else if (rb-ra>=0) return ra!=t.ra?ra<t.ra:num<t.num;
		else return rb!=t.rb?rb>t.rb:num<t.num;
	}
};
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 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);
}
void calc(long long x)
{
	for (int i=1;i<=n;++i) st[i].ra=st[i].a+(__int128)(st[i].ta)*x,st[i].rb=st[i].b+(__int128)(st[i].tb)*x;
	sort(st+1,st+n+1);
	return;
}
bool check(long long x)
{
	for (int i=1;i<=n;++i) st[i].ra=st[i].a+(__int128)(st[i].ta)*x,st[i].rb=st[i].b+(__int128)(st[i].tb)*x;
	for (int i=1;i<=n-1;++i)
		if (st[i+1]<st[i])
			return 0;
	return 1;
}
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) 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--;
		dque[++top]=tongs[i];
	}
	for (int i=1;i<=top;++i)
	{
		sl=l,sr=r;
		if (i>=2&&dque[i].x!=dque[i-1].x) sl=max(sl,(dque[i-1].y-dque[i].y+dque[i].x-dque[i-1].x-1)/(dque[i].x-dque[i-1].x)+1);
		if (i+1<=top)
		{
			if (dque[i].x==dque[i+1].x) sr=l-1;
			else sr=min(sr,(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()
{
	long long t,lst;
	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(),st[i].num=i;
	sort(st+1,st+n+1),t=0;
	while (t<=m)
	{
		lst=t,calc(t);
		for (int i=log(inf)/log(2);i>=0;--i)
			if (lst+(1ll<<i)<=m&&check(lst+(1ll<<i)))
				lst+=(1ll<<i);
		solve(t,lst),t=lst+1;
	}
	printf("%llu\n",ans);
	return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3928kb

input:

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

output:

106

result:

wrong answer 1st lines differ - expected: '113', found: '106'