QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#432598#4887. Fast BridgeszhouhuanyiWA 1ms5756kbC++143.1kb2024-06-07 13:13:252024-06-07 13:13:26

Judging History

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

  • [2024-06-07 13:13:26]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5756kb
  • [2024-06-07 13:13:25]
  • 提交

answer



#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#define N 501
#define mod 1000000007
using namespace std;
const int inf=(int)(1e9);
int read()
{
	char c=0;
	int sum=0;
	while (c<'0'||c>'9') c=getchar();
	while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
	return sum;
}
void Adder(int &x,int d)
{
	x=x+d>=mod?x+d-mod:x+d;
	return;
}
void Adder2(int &x,int d)
{
	x=x+d<0?x+d+mod:x+d;
	return;
}
int MD(int x)
{
	return x>=mod?x-mod:x;
}
int MD2(int x)
{
	return x<0?x+mod:x;
}
int S(int x)
{
	return ((1ll*x*(x+1))>>1)%mod;
}
int S2(int x)
{
	return ((__int128)(x)*(x+1)*((x<<1)+1)/6)%mod;
}
struct reads
{
	int x1,y1,x2,y2;
	bool operator < (const reads &t)const
	{
		return x2<t.x2;
	}
};
reads st[N+1],st2[N+1];
int n,m,leng,leng2,ans,tong[N+1],length,tong2[N+1],length2,delta[N+1][N+1][N+1],dis[N+1][N+1];
vector<int>p[N+1];
void solve()
{
	int res,rst;
	length=length2=0;
	for (int i=1;i<=leng;++i) tong[++length]=st[i].x1,tong2[++length2]=st[i].y1;
	sort(tong+1,tong+length+1),length=unique(tong+1,tong+length+1)-tong-1;
	sort(tong2+1,tong2+length2+1),length2=unique(tong2+1,tong2+length2+1)-tong2-1;
	sort(st+1,st+leng+1);
	for (int i=1;i<=length;++i)
		for (int j=1;j<=length2;++j)
			for (int k=1;k<=leng;++k)
				delta[i][j][k]=-inf;
	for (int i=1;i<=leng;++i)
		for (int j=i;j<=leng;++j)
			dis[i][j]=i==j?0:-inf;
	for (int i=leng;i>=1;--i)
		for (int j=i+1;j<=leng;++j)
			if (st[i].x2<=st[j].x1&&st[i].y2<=st[j].y1)
				for (int k=j;k<=leng;++k)
					dis[i][k]=max(dis[i][k],dis[j][k]+1);
	for (int i=1;i<=leng;++i)
		for (int j=i;j<=leng;++j)
			delta[lower_bound(tong+1,tong+length+1,st[i].x1)-tong][lower_bound(tong2+1,tong2+length2+1,st[i].y1)-tong2][j]=max(delta[lower_bound(tong+1,tong+length+1,st[i].x1)-tong][lower_bound(tong2+1,tong2+length2+1,st[i].y1)-tong2][j],dis[i][j]);
	for (int i=length;i>=1;--i)
		for (int j=length2;j>=1;--j)
			for (int k=1;k<=leng;++k)
			{
				if (i+1<=length) delta[i][j][k]=max(delta[i][j][k],delta[i+1][j][k]);
				if (j+1<=length2) delta[i][j][k]=max(delta[i][j][k],delta[i][j+1][k]);
			}
	for (int i=1;i<=length;++i)
		for (int j=1;j<=length2;++j)
		{
			rst=0;
			for (int k=0;k<=leng-1;++k) p[k].clear();
			for (int k=1;k<=leng;++k)
				if (tong[i]<=st[k].x1&&tong2[j]<=st[k].y1&&delta[i][j][k]!=-inf)
					p[delta[i][j][k]].push_back(k);
			for (int k=0;k<=leng-1;++k)
			{
				res=n+1;
				for (int t=0;t<p[k].size();++t)
					if (st[p[k][t]].y2<res)
						Adder(rst,1ll*(res-st[p[k][t]].y2)*(n-st[p[k][t]].x2+1)%mod),res=st[p[k][t]].y2;
			}
			Adder2(ans,-2ll*rst*(tong[i]-tong[i-1])%mod*(tong2[j]-tong2[j-1])%mod);
		}
	return;
}
int main()
{
	int x1,y1,x2,y2;
	n=read(),m=read(),ans=2ll*n%mod*n%mod*MD2(S2(n)-S(n))%mod;
	for (int i=1;i<=m;++i)
	{
		x1=read(),y1=read(),x2=read(),y2=read();
		if (y1<y2) st[++leng]=(reads){x1,y1,x2,y2};
		else st2[++leng2]=(reads){x1,n-y1+1,x2,n-y2+1};
	}
	solve();
	for (int i=1;i<=max(leng,leng2);++i) swap(st[i],st2[i]);
	swap(leng,leng2);
	solve(),printf("%d\n",ans);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 5756kb

input:

2 2
1 1 2 2
1 2 2 1

output:

12

result:

wrong answer expected '6', found '12'