QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#305794#6190. Graph Problemvme50WA 1ms9716kbC++172.5kb2024-01-16 00:22:152024-01-16 00:22:15

Judging History

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

  • [2024-01-16 00:22:15]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:9716kb
  • [2024-01-16 00:22:15]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define gc() (P1==P2 && (P2=(P1=bufI)+fread(bufI,1,LIM,stdin),P1==P2)?EOF:*P1++)
#define pc(x) (((P3==bufO+LIM)?(fwrite(bufO,1,P3-bufO,stdout),P3=bufO):P3),*P3++=(x))
const int N=505,LIM=1e7+5,MOD=998244353;
mt19937 rand1(0);int n,m,c,ans,o[N],a[N][N],a1[N][N],z[N][N],z1[N][N];
int stO[55];char bufI[LIM],bufO[LIM],*P1=bufI,*P2=bufI,*P3=bufO;
int rd()
{
	int res=0;bool fl=0;char c=0;while(!isdigit(c)) fl|=c=='-',c=gc();
	while(isdigit(c)) res=res*10+(c-48),c=gc();return fl?-res:res;
}
void wr(int x)
{
	if(!x) {pc('0');return;}if(x<0) pc('-'),x=-x;
	stO[0]=0;while(x) stO[++stO[0]]=x%10,x/=10;
	for(int i=stO[0];i;--i) pc(stO[i]+48);
}
void flush() {fwrite(bufO,1,P3-bufO,stdout);P3=bufO;}
int rdm(int l,int r) {return uniform_int_distribution<int>(l,r)(rand1);}
void W(int &x,int y) {x+=y;if(x>=MOD) x-=MOD;}
void W(int &x,ll y) {x=(x+y)%MOD;}
int add(int x,int y) {x+=y;return x<MOD?x:x-MOD;}
int qPow(int x,int y)
{int res=1;for(;y;y/=2,x=1ll*x*x%MOD) if(y&1) res=1ll*res*x%MOD;return res;}
void inv(int n)
{
	for(int i=1;i<=n;++i) fill(z1[i]+1,z1[i]+n+1,0),z1[i][i]=1;
	for(int i=1,t,t1;i<=n;++i)
	{
		if(!z[i][i]) for(int j=i+1;j<=n;++j) if(z[j][i])
		{
			for(int k=i;k<=n;++k) swap(z[i][k],z[j][k]);
			for(int k=1;k<=n;++k) swap(z1[i][k],z1[j][k]);break;
		}t1=qPow(z[i][i],MOD-2);
		for(int k=i;k<=n;++k) z[i][k]=1ll*z[i][k]*t1%MOD;
		for(int k=1;k<=n;++k) z1[i][k]=1ll*z1[i][k]*t1%MOD;
		for(int j=i+1;j<=n;++j)
		{
			t=MOD-z[j][i];for(int k=i;k<=n;++k) W(z[j][k],1ll*z[i][k]*t);
			for(int k=1;k<=n;++k) W(z1[j][k],1ll*z1[i][k]*t);
		}
	}
	for(int i=n;i;--i) for(int j=i+1;j<=n;++j)
	{for(int k=1;k<=n;++k) W(z1[i][k],1ll*z1[j][k]*(MOD-z[i][j]));z[i][j]=0;}
}
int slv(int u,int v)
{
	int t=add(-a1[u][v],MOD);
	for(int i=1;i<=o[0];++i) for(int j=1;j<=o[0];++j)
		W(t,1ll*a1[u][o[i]]*z1[o[i]][o[j]]%MOD*a1[o[j]][v]);return t>0;
}
int main()
{
	n=rd();m=rd();for(int i=1;i<=n;++i) a[i][i]=1;
	for(int i=1,u,v;i<=m;++i) u=rd(),v=rd(),a[u][v]=rdm(1,MOD-1);c=rd();
	for(int i=1;i<=n;++i) copy(a[i]+1,a[i]+n+1,z[i]+1);inv(n);
	for(int i=1;i<=n;++i) copy(z1[i]+1,z1[i]+n+1,a1[i]+1);
	while(c--)
	{
		o[0]=rd();for(int i=1;i<=o[0];++i) o[i]=(rd()+ans-1)%n+1;
		for(int i=1;i<=o[0];++i) for(int j=1;j<=o[0];++j)
			z[i][j]=a1[o[i]][o[j]];inv(o[0]);int x=rd();
		while(x--)
		{
			int u,v,t;u=(rd()+ans-1)%n+1;v=(rd()+ans-1)%n+1;
			t=slv(u,v);ans+=t;pc(t+48);
		}pc('\n');
	}flush();return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 7848kb

input:

5 4
1 2
2 3
3 4
4 5
2
1 4
2 1 5 1 3
3 5 3 4
1 1 2

output:

01
1

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 9716kb

input:

100 4870
1 4
1 9
2 1
2 6
2 8
4 5
4 10
5 2
5 3
5 7
6 2
6 4
6 8
7 1
7 2
7 8
7 10
8 1
8 2
8 3
8 4
8 5
8 6
8 7
8 9
8 13
8 16
8 17
9 1
9 2
9 3
9 4
9 5
9 6
9 7
9 8
9 18
10 1
10 2
10 3
10 4
10 5
10 6
10 7
10 11
10 15
11 1
11 2
11 3
11 4
11 5
11 6
11 7
11 8
11 9
11 10
11 12
11 18
11 20
12 1
12 2
12 3
12 4
1...

output:

1011000010
1010110101
0001010000
0000101001
1000010000
0111001101
0011001101
1100010010
0111111111
0000111111
0011110111
0111111111
1011110011
0101111101
1001110110
1111111111
1111001111
1110111111
0110111011
1111101101
1011001111
1111110001
1011111011
1111111101
1111001101
1011010011
1110111111
110...

result:

wrong answer 9th lines differ - expected: '0001100010', found: '0111111111'