QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#83500#5442. Referee Without RedxiaoyaowudiCompile Error//C++143.3kb2023-03-02 10:56:162023-03-02 10:56:17

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-02 10:56:17]
  • 评测
  • [2023-03-02 10:56:16]
  • 提交

answer

#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
constexpr int N(3e6+10),p(998244353);
int n,m,v[N],r,c;
int h(int x,int y){return (x-1)*m+y;}
int o(int x,int y){return (x-1)*c+y;}
int lcm(int x,int y){return x/std::__gcd(x,y)*y;}
void calc(int *a,int *b,int *c,int &k,int n)
{
	int cnt(0);static bool vis[N];std::memset(vis+1,0,sizeof(bool)*n);
	for(int i(1);i<=n;++i) if(!vis[i])
	{
		++k;b[k]=cnt+1;int u(i);
		do
		{
			if((u%2)==1) u=(u+1)/2;
			else u=u/2+(n+1)/2;
			a[++cnt]=u;
			vis[u]=true;
		}while(u!=i);
		c[k]=cnt;
	}
}
template<typename T> void clr(T *k,int num){std::memset(k+1,0,sizeof(T)*num);}
bool vvc[N],vvr[N],rid[N],cid[N];
bool dfsc(int _c);
bool dfsr(int _r){bool ret(true);vvr[_r]=true;
for(int i(1);i<=c;++i) if(rid[o(_r,i)]){if(!cid[o(_r,i)]) ret=false;else if(!vvc[i]){auto res=dfsc(i);if(!res) ret=false;}}return ret;}
bool dfsc(int _c){bool ret(true);vvc[_c]=true;
for(int i(1);i<=r;++i) if(cid[o(i,_c)]){if(!rid[o(i,_c)]) ret=false;else if(!vvr[i]){auto res=dfsr(i);if(!res) ret=false;}}return ret;}
int calc(int *a,int n)
{
	static int f[N];
	for(int i(2);i<=n;++i)
	{
		int j(f[i-1]);
		while(j && a[j+1]!=a[i]) j=f[j];
		if(a[j+1]==a[i]) ++j;
		f[i]=j;
	}
	int k(f[n]);
	while(n%(n-k)) k=f[k];
	return n-k;
}
int main()
{
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	int T;std::cin>>T;static int inv[N],fac[N];inv[1]=fac[0]=fac[1]=1;
	for(int i(2);i<N;++i) inv[i]=1ll*inv[p%i]*(p-p/i)%p,fac[i]=1ll*fac[i-1]*i%p;
	while(T--)
	{
		std::cin>>n>>m;
		for(int i(1);i<=n;++i) for(int j(1);j<=m;++j) std::cin>>v[h(i,j)];
		static int ci[N],cs[N],ce[N],ri[N],rs[N],re[N],vq[N],qid,vc[N];
		static bool hvc[N],hvr[N];
		r=c=0;
		calc(ci,cs,ce,c,m);calc(ri,rs,re,r,n);
		clr(rid,r*c);clr(cid,r*c);clr(hvc,c);clr(hvr,r);clr(vvc,c);clr(vvr,r);
		int ans(1);
		for(int i(1);i<=r;++i) if(re[i]-rs[i])
		{
			for(int j(1);j<=c;++j) if(ce[j]-cs[j])
			{
				++qid;bool cap(true);
				for(int x(rs[i]);x<=re[i];++x)
				{
					for(int y(cs[j]);y<=ce[j];++y)
					{
						int cur(v[h(ri[x],ci[y])]);
						if(vq[cur]==qid)
						{
							ans=1ll*ans*inv[++vc[cur]]%p;
							cap=false;
						}
						else
						{
							vq[cur]=qid;
							vc[cur]=1;
						}
					}
				}
				ans=1ll*ans*fac[(re[i]-rs[i]+1)*(ce[j]-cs[j]+1)]%p
				if(cap)
				{
					ans=1ll*ans*inv[2]%p;
					if((ce[i]-cs[i])&1)
					{
						rid[o(i,j)]=true;
						hvr[i]=true;
					}
					if((re[j]-rs[j])&1)
					{
						cid[o(i,j)]=true;
						hvc[j]=true;
					}
				}
			}
		}
		for(int i(1);i<=r;++i) if(hvr[i]){ans=2ll*ans%p;if(!vvr[i]){bool ret(dfsr(i));if(ret) ans=1ll*ans*inv[2]%p;}}
		for(int i(1);i<=c;++i) if(hvc[i]){ans=2ll*ans%p;if(!vvc[i]){bool ret(dfsc(i));if(ret) ans=1ll*ans*inv[2]%p;}}
		for(int i(1);i<=r;++i) if(re[i]==rs[i]){int t(1);for(int j(1);j<=c;++j) if(ce[j]-cs[j])
		{
			static int tmp[N];int ct(0);for(int k(cs[j]);k<=ce[j];++k) tmp[++ct]=v[h(ri[rs[i]],ci[k])];
			t=lcm(t,calc(tmp,ct));
		}ans=1ll*ans*t%p;}
		for(int i(1);i<=c;++i) if(ce[i]==cs[i]){int t(1);for(int j(1);j<=r;++j) if(re[j]-rs[j])
		{
			static int tmp[N];int ct(0);for(int k(rs[j]);k<=re[j];++k) tmp[++ct]=v[h(ri[k],ci[cs[i]])];
			t=lcm(t,calc(tmp,ct));
		}ans=1ll*ans*t%p;}
		std::cout<<ans<<"\n";
	}
	return 0;
}

Details

answer.code: In function ‘int main()’:
answer.code:85:83: error: expected ‘;’ before ‘if’
   85 |                                 ans=1ll*ans*fac[(re[i]-rs[i]+1)*(ce[j]-cs[j]+1)]%p
      |                                                                                   ^
      |                                                                                   ;
   86 |                                 if(cap)
      |                                 ~~