QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#100838#5827. 异或图vincy20 2ms3448kbC++141.7kb2023-04-28 12:09:382023-04-28 12:09:40

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-28 12:09:40]
  • 评测
  • 测评结果:20
  • 用时:2ms
  • 内存:3448kb
  • [2023-04-28 12:09:38]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define PR pair<int,int>
#define fi first
#define se second
using namespace std;
const long long N=1e3+5,M=1e5+5,md=998244353,F=1e9;
long long n,m,C,a[N],u[N],v[N],f[N],siz[N],cnt,num[M],b[N],g[M],ans,h[3],H[3];
inline ll read()
{
   ll x=0,f=1;
   char ch=getchar();
   while(!isdigit(ch)) { if(ch=='-') f=-1; ch=getchar(); }
   while(isdigit(ch)) x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
   return x*f;
}
ll solve(int n)
{
	ll ans=0;
	for (int i=62;i>=0;i--)
	{
		int sum=0; h[0]=h[1]=0; h[2]=1;
		for (int j=1;j<=n;j++)
		{
			ll A=(1ll<<i),B=b[j]&((1ll<<i)-1);
			if ((b[j]>>i)&1) 
			{
				H[0]=(h[0]*A+h[1]*B)%md;
				H[1]=(h[0]*B+h[1]*A)%md;
				H[2]=h[2]*B%md;
				H[sum]=(H[sum]+h[2])%md;
				tie(h[0],h[1],h[2])=tie(H[0],H[1],H[2]);
				sum^=1;
			} else
			{
				h[0]=h[0]*B%md; h[1]=h[1]*B%md; h[2]=h[2]*B%md;
			}
		} ans=(ans+h[(C>>i)&1])%md;
		if (sum!=((C>>i)&1)) break;
	} 
	return ans;
}
int gf(int x) { return f[x]==x?x:f[x]=gf(f[x]); }
void merge(int x,int y) { f[x]=y; siz[y]+=siz[x]; } 
int main()
{
	cin>>n>>m>>C;
	for (int i=1;i<=n;i++) a[i]=read(),a[i]++;
	for (int i=0;i<m;i++) u[i]=read(),v[i]=read();
	for (int S=0;S<(1<<m);S++)
	{
		for (int i=1;i<=n;i++) f[i]=i,siz[i]=1; cnt=0; num[S]=num[S>>1]+(S&1); g[S]=1;
		for (int i=0;i<m;i++)
		{
			if (S&(1ll<<i)) 
			{
				int x=gf(u[i]),y=gf(v[i]);
				if (x!=y) { if (a[x]<a[y]) merge(y,x); else merge(x,y); }
//				printf("%d %d\n",gf(u[i]),gf(v[i]));
			}
		}
		for (int i=1;i<=n;i++) 
			if (f[i]==i) { if (siz[i]%2) b[++cnt]=a[i]; else g[S]=g[S]*a[i]%md; } 
		(g[S]*=solve(cnt))%=md;
		if (num[S]&1) (ans-=g[S])%=md; else (ans+=g[S])%=md;
	}
	cout<<ans;
	return 0;
}

详细

Subtask #1:

score: 20
Accepted

Test #1:

score: 20
Accepted
time: 2ms
memory: 3348kb

input:

4 6 2
7 11 14 0
1 2
1 3
2 3
2 4
4 1
4 3

output:

44

result:

ok 1 number(s): "44"

Test #2:

score: 0
Accepted
time: 2ms
memory: 3324kb

input:

4 4 6
12 14 14 5
4 2
1 4
3 2
1 2

output:

798

result:

ok 1 number(s): "798"

Test #3:

score: 0
Accepted
time: 1ms
memory: 3328kb

input:

3 3 2
10 4 11
2 1
3 2
1 3

output:

33

result:

ok 1 number(s): "33"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3312kb

input:

4 0 4
9 8 5 2

output:

148

result:

ok 1 number(s): "148"

Test #5:

score: 0
Accepted
time: 2ms
memory: 3328kb

input:

5 6 14
12 15 13 13 12
3 1
2 4
2 5
2 1
5 3
4 5

output:

21337

result:

ok 1 number(s): "21337"

Test #6:

score: 0
Accepted
time: 2ms
memory: 3324kb

input:

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

output:

42

result:

ok 1 number(s): "42"

Test #7:

score: 0
Accepted
time: 2ms
memory: 3348kb

input:

4 4 3
13 7 8 12
4 1
3 1
2 4
4 3

output:

552

result:

ok 1 number(s): "552"

Test #8:

score: 0
Accepted
time: 2ms
memory: 3340kb

input:

4 2 12
1 12 4 11
2 1
3 1

output:

70

result:

ok 1 number(s): "70"

Test #9:

score: 0
Accepted
time: 2ms
memory: 3344kb

input:

5 5 6
10 7 8 2 13
1 5
1 3
2 1
4 3
5 3

output:

1231

result:

ok 1 number(s): "1231"

Test #10:

score: 0
Accepted
time: 2ms
memory: 3448kb

input:

5 7 9
6 7 13 15 12
1 3
5 3
5 2
4 5
4 3
4 1
3 2

output:

6223

result:

ok 1 number(s): "6223"

Test #11:

score: 0
Accepted
time: 2ms
memory: 3436kb

input:

3 0 3
15 7 12

output:

104

result:

ok 1 number(s): "104"

Test #12:

score: 0
Accepted
time: 2ms
memory: 3332kb

input:

3 2 9
10 6 5
1 2
1 3

output:

17

result:

ok 1 number(s): "17"

Test #13:

score: 0
Accepted
time: 2ms
memory: 3304kb

input:

5 5 11
7 9 15 9 9
5 4
5 1
5 2
1 3
3 4

output:

5224

result:

ok 1 number(s): "5224"

Test #14:

score: 0
Accepted
time: 1ms
memory: 3320kb

input:

5 0 12
9 8 14 11 2

output:

3006

result:

ok 1 number(s): "3006"

Test #15:

score: 0
Accepted
time: 0ms
memory: 3336kb

input:

3 1 1
6 10 4
3 1

output:

30

result:

ok 1 number(s): "30"

Subtask #2:

score: 0
Memory Limit Exceeded

Dependency #1:

100%
Accepted

Test #16:

score: 0
Memory Limit Exceeded

input:

9 27 705410105529944560
929827299070190972 733413770730537329 473007347105710981 190062421504120247 918561152768663129 196040702922254016 981530663192980241 203295856357272834 337150461958783092
2 8
7 9
8 9
2 3
9 2
2 7
9 5
9 4
4 8
1 7
6 3
6 1
4 1
6 5
2 4
2 1
9 3
9 6
7 3
7 5
5 2
4 5
2 6
3 1
3 8
4 3
8 6

output:


result:


Subtask #3:

score: 0
Wrong Answer

Test #47:

score: 0
Wrong Answer
time: 2ms
memory: 3312kb

input:

14 0 731833687287532167
157552918690640051 900457311668526045 111217720157614956 84140984111060473 814012186135880499 784848789620248379 958953377683017264 105083874298571687 104921429970878846 44983041675142735 871013110538758030 686733907990421995 98063590462078176 495161493555059993

output:

504530635

result:

wrong answer 1st numbers differ - expected: '231790380', found: '504530635'

Subtask #4:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%