QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#493859#9141. Array Spreaducup-team3555#WA 1ms7868kbC++141.9kb2024-07-27 12:59:202024-07-27 12:59:21

Judging History

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

  • [2024-09-18 18:58:44]
  • hack成功,自动添加数据
  • (/hack/840)
  • [2024-09-18 18:53:02]
  • hack成功,自动添加数据
  • (/hack/839)
  • [2024-07-29 03:53:23]
  • hack成功,自动添加数据
  • (/hack/753)
  • [2024-07-29 03:51:16]
  • hack成功,自动添加数据
  • (/hack/752)
  • [2024-07-29 03:50:24]
  • hack成功,自动添加数据
  • (/hack/751)
  • [2024-07-29 03:48:52]
  • hack成功,自动添加数据
  • (/hack/750)
  • [2024-07-27 12:59:21]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7868kb
  • [2024-07-27 12:59:20]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const ll N=4003,H=998244353;
int n,m,kl[N],kr[N],f1[N][N],f2[N][N];
vector<int>vl[N],vr[N];
void Max(int &x,int y){if(x<y)x=y;}
void Min(int &x,int y){if(x>y)x=y;}
ll Ksm(ll x,ll y)
{
	ll s=1;
	for(;y;y>>=1,x=x*x%H)if(y&1)s=s*x%H;
	return s;
}
struct BIT
{
	int tr[N];
	void Add1(int x,int y){for(;x;x-=x&-x)Max(tr[x],y);}
	int Ask1(int x){int s=0;for(;x<=n;x+=x&-x)Max(s,tr[x]);return s;}
	void Add2(int x,int y){for(;x;x-=x&-x)Min(tr[x],y);}
	int Ask2(int x){int s=1e9;for(;x<=n;x+=x&-x)Min(s,tr[x]);return s;}
	void Clear1(){memset(tr,0,sizeof(tr));}
	void Clear2(){memset(tr,0x3f,sizeof(tr));}
}T1,T2;
void Sol1(int st)
{
	T1.Clear1();
	for(int i=1;i<=n;i++)f1[i][st]=0;
	for(int i=st-1;i>0;i--)
	{
		Max(f1[i][st],f1[i+1][st]);
		for(int x:vl[i])Max(f1[i][st],T1.Ask1(x)+1);
		T1.Add1(i,f1[i][st]);
	}
}
void Sol2(int st)
{
	T2.Clear2();T2.Add2(st,0);
	for(int i=1;i<=n;i++)f2[st][i]=1e9;
	for(int i=st+1;i<=n;i++)
	{
		Min(f2[st][i],f2[st][i-1]);
		for(int x:vr[i])Min(f2[st][i],T2.Ask2(x)+1);
		T2.Add2(i,f2[st][i]);
	}
}
void Solve()
{
	cin>>m>>m;n=0;map<int,int>mp;
	for(int i=1;i<=m;i++)cin>>kl[i]>>kr[i],kl[i]--,mp[kl[i]]=mp[kr[i]]=0;
	for(auto &p:mp)p.second=++n,vl[n].clear(),vr[n].clear();
	for(int i=1;i<=m;i++)kl[i]=mp[kl[i]],kr[i]=mp[kr[i]],vl[kl[i]].push_back(kr[i]),vr[kr[i]].push_back(kl[i]);
	for(int i=1;i<=n;i++)Sol1(i),Sol2(i);
	for(int i=1;i<=n;i++)
	{
		int mk=0;
		for(int j=1;j<=m;j++)mk+=kl[j]<=i&&i<=kr[j];
		if(mk==m){cout<<1<<endl;return;}
	}
	ll smx=1e9,smn=1;
	for(int i=1;i<=n;i++)for(int j=i+1;j<=n;j++)if(f1[i][j]>0&&f2[i][j]<1e9&&f1[i][j]>f2[i][j])
	{
		ll mx=f1[i][j],mn=f2[i][j];
		if(smx*mn>smn*mx)smx=mx,smn=mn;
	}
	cout<<smx*Ksm(smn,H-2)%H<<endl;
}
int main()
{
	int TT;cin>>TT;
	while(TT--)Solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
3 3
1 3
2 3
1 2
12 6
2 3
5 7
1 9
4 8
1 2
7 11
4 5
3 4
2 3
1 2
4 4
1 1

output:

1
2
2

result:

wrong answer 3rd numbers differ - expected: '499122178', found: '2'