QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#526461#6304. RectanglezhouhuanyiWA 17ms48800kbC++145.8kb2024-08-21 16:25:202024-08-21 16:25:20

Judging History

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

  • [2024-08-21 16:25:20]
  • 评测
  • 测评结果:WA
  • 用时:17ms
  • 内存:48800kb
  • [2024-08-21 16:25:20]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<set>
#define N 400000
#define mod 998244353
using namespace std;
const int inf=(int)(1e9);
const int invfac[4]={1,1,499122177,166374059};
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;
}
struct reads
{
	int num,data;
	bool operator < (const reads &t)const
	{
		return data!=t.data?data<t.data:num<t.num;
	}
};
vector<reads>p[N+1];
int Ts,n,tong[N+1],length,tong2[N+1],length2,dp[4][N+1],maxn[N+1],l1[N+1],r1[N+1],l2[N+1],r2[N+1],sl[N+1],sr[N+1],ans;
set<reads>s[N+1];
set<reads>sw;
set<reads>sw2;
struct seg
{
	struct node
	{
		int l,r,maxn,res;
	};
	node tree[(N<<2)+1];
	int wmaxn;
	void build(int k,int l,int r)
	{
		tree[k].l=l,tree[k].r=r,tree[k].maxn=1,tree[k].res=0;
		if (l==r) return;
		int mid=(l+r)>>1;
		build(k<<1,l,mid),build(k<<1|1,mid+1,r);
		return;
	}
	long long calc(int k,int d)
	{
		if (tree[k].l==tree[k].r) return 1ll*tong2[max(d,tree[k].maxn)-1]*(tong2[tree[k].l]-tong2[tree[k].l-1])%mod;
		else
		{
			if (tree[k<<1].maxn>=d) return MD(calc(k<<1,d)+MD2(tree[k].res-tree[k<<1].res));
			else return MD(1ll*tong2[d-1]*(tong2[tree[k<<1].r]-tong2[tree[k<<1].l-1])%mod+calc(k<<1|1,d));
		}
	}
	void push_up(int k)
	{
		tree[k].maxn=max(tree[k<<1].maxn,tree[k<<1|1].maxn),tree[k].res=MD(tree[k<<1].res+calc(k<<1|1,tree[k<<1].maxn));
		return;
	}
	void change(int k,int x,int d)
	{
		if (tree[k].l==tree[k].r)
		{
			tree[k].maxn=d;
			return;
		}
		int mid=(tree[k].l+tree[k].r)>>1;
		if (x<=mid) change(k<<1,x,d);
		else change(k<<1|1,x,d);
		push_up(k);
		return;
	}
	int get_maxn(int k,int l,int r)
	{
		if (tree[k].l==l&&tree[k].r==r) return tree[k].maxn;
		int mid=(tree[k].l+tree[k].r)>>1;
		if (r<=mid) return get_maxn(k<<1,l,r);
		else if (l>=mid+1) return get_maxn(k<<1|1,l,r);
		else return max(get_maxn(k<<1,l,mid),get_maxn(k<<1|1,mid+1,r));
	}
	int solve(int k,int d)
	{
		if (tree[k].l==tree[k].r) return tree[k].maxn<=d?tree[k].l:tree[k].l-1;
		if (tree[k<<1].maxn<=d) return solve(k<<1|1,d);
		else return solve(k<<1,d);
	}
	int query(int k,int l,int r)
	{
		if (tree[k].l==l&&tree[k].r==r)
		{
			int d=calc(k,wmaxn);
			wmaxn=max(wmaxn,tree[k].maxn);
			return d;
		}
		int mid=(tree[k].l+tree[k].r)>>1;
		if (r<=mid) return query(k<<1,l,r);
		else if (l>=mid+1) return query(k<<1|1,l,r);
		else return MD(query(k<<1,l,mid)+query(k<<1|1,mid+1,r));
	}
};
seg T;
void change(int x)
{
	if (s[x].empty()) T.change(1,x,1);
	else
	{
		auto it=s[x].end();
		it--,T.change(1,x,(*it).data);
	}
	return;
}
void solve()
{
	int l,r,tl,tr,ps,wmaxn=0;
	length=length2=0,sw.clear(),sw2.clear();
	for (int i=1;i<=n;++i)
	{
		if (l1[i]!=1) tong[++length]=l1[i]-1;
		tong[++length]=r1[i];
		if (l2[i]!=1) tong2[++length2]=l2[i]-1;
		tong2[++length2]=r2[i];
	}
	tong[++length]=inf,sort(tong+1,tong+length+1),length=unique(tong+1,tong+length+1)-tong-1;
	tong2[++length2]=inf,sort(tong2+1,tong2+length2+1),length2=unique(tong2+1,tong2+length2+1)-tong2-1;
	for (int i=0;i<=length;++i) dp[0][i]=1;
	for (int i=1;i<=length;++i) maxn[i]=0,p[i].clear(),s[i].clear();
	for (int i=1;i<=n;++i)
	{
		l=lower_bound(tong,tong+length+1,l1[i]-1)-tong+1,r=lower_bound(tong,tong+length+1,r1[i])-tong;
		sl[i]=lower_bound(tong2,tong2+length2+1,l2[i]-1)-tong2+1,sr[i]=lower_bound(tong2,tong2+length2+1,r2[i])-tong2;
		wmaxn=max(wmaxn,l);
		if (r+1<=length) maxn[r+1]=max(maxn[r+1],l);
		p[1].push_back((reads){i,1}),p[l].push_back((reads){i,-1});
		if (r+1<=length) p[r+1].push_back((reads){i,1});
	}
	for (int i=2;i<=length;++i) maxn[i]=max(maxn[i],maxn[i-1]);
	for (int i=1;i<=3;++i)
		for (int j=1;j<=length;++j)
		{
			dp[i][j]=dp[i][j-1];
			for (int k=1,rst=tong[j]-tong[j-1];k<=i;++k,rst=1ll*rst*(tong[j]-tong[j-1]-k+1)%mod) Adder(dp[i][j],1ll*MD2(dp[i-k][j-1]-(!maxn[j]?0:dp[i-k][maxn[j]-1]))*rst%mod*invfac[k]%mod);
		}
	Adder(ans,MD2(dp[3][length]-dp[3][wmaxn-1])),T.build(1,1,length2);
	for (int i=1;i<=length;++i)
	{
		for (int j=0;j<p[i].size();++j)
		{
			if (p[i][j].data==1)
			{
				if (sr[p[i][j].num]+1<=length2) s[sr[p[i][j].num]+1].insert((reads){p[i][j].num,sl[p[i][j].num]});
				sw.insert((reads){p[i][j].num,sr[p[i][j].num]}),sw2.insert((reads){p[i][j].num,sl[p[i][j].num]});
			}
			else
			{
				if (sr[p[i][j].num]+1<=length2) s[sr[p[i][j].num]+1].erase((reads){p[i][j].num,sl[p[i][j].num]});
				sw.erase((reads){p[i][j].num,sr[p[i][j].num]}),sw2.erase((reads){p[i][j].num,sl[p[i][j].num]});
			}
			if (sr[p[i][j].num]+1<=length2) change(sr[p[i][j].num]+1);
		}
		if (sw.empty()) Adder(ans,1ll*(tong[i]-tong[i-1])*inf%mod*(inf-1)%mod*invfac[2]%mod);
		else
		{
			tr=(*sw.begin()).data;
			auto it=sw2.end();
			it--,tl=(*it).data;
			if (tl<=tr)
			{
				Adder(ans,1ll*(tong[i]-tong[i-1])*MD(1ll*(tong2[tr]-tong2[tl-1])*(inf-tong2[tr]+tong2[tl-1])%mod+1ll*(tong2[tr]-tong2[tl-1])*(tong2[tr]-tong2[tl-1]-1)%mod*invfac[2]%mod)%mod);
				swap(tl,tr);
				tr--,tl++;
				if (tl==length2+1||!tr) continue;
			}
			if (T.get_maxn(1,1,tl)<=tr)
			{
				ps=T.solve(1,tr),T.wmaxn=max(1,T.get_maxn(1,1,tl));
				Adder(ans,1ll*(tong[i]-tong[i-1])*MD2(1ll*tong2[tr]*(tong2[ps]-tong2[tl-1])%mod-T.query(1,tl,ps))%mod);
			}
		}
	}
	return;
}
int main()
{
	Ts=read();
	while (Ts--)
	{
		n=read(),ans=0;
		for (int i=1;i<=n;++i) l1[i]=read(),l2[i]=read(),r1[i]=read(),r2[i]=read();
		solve();
		for (int i=1;i<=n;++i) swap(l1[i],l2[i]),swap(r1[i],r2[i]);
		solve(),printf("%d\n",ans);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 48800kb

input:

3
1
1 1 1000000000 1000000000
3
1 1 2 2
3 3 4 4
5 5 6 6
5
581574116 47617804 999010750 826131769
223840663 366320907 613364068 926991396
267630832 51913575 488301124 223957497
217461197 492085159 999485867 913732845
28144453 603781668 912516656 993160442

output:

230616300
64
977066618

result:

ok 3 number(s): "230616300 64 977066618"

Test #2:

score: -100
Wrong Answer
time: 17ms
memory: 48656kb

input:

1000
10
5 7 6 10
4 3 6 9
1 6 3 7
1 1 7 10
1 2 7 7
5 2 8 3
2 1 5 7
1 1 10 6
1 7 2 8
4 7 5 9
10
6 6 8 10
4 4 9 9
2 4 6 5
5 3 10 10
1 3 4 4
2 2 3 6
7 5 8 6
2 7 8 8
5 7 10 10
2 4 7 8
10
3 6 6 10
1 2 7 4
7 5 10 9
4 5 8 9
2 7 5 9
2 2 9 7
3 3 8 4
1 1 8 6
5 4 10 6
3 9 7 10
10
3 1 8 9
1 3 8 10
4 1 7 4
2 4 5 ...

output:

28090346
21067815
91293528
63203269
14045217
24579047
49158123
56180656
10533942
83
28090372
101827338
512901428
38624242
10533932
42135595
7022614
7022661
7022622
31601641
21067817
35112979
7022628
7022682
17556485
42135554
59692019
28090452
14045202
73737099
42135505
31601703
49158091
28090434
108...

result:

wrong answer 41st numbers differ - expected: '7022642', found: '7022641'