QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#88395 | #5827. 异或图 | myee | 30 | 17ms | 70584kb | C++11 | 7.0kb | 2023-03-16 09:47:41 | 2023-03-16 09:47:43 |
Judging History
answer
// 传统计数强省的 998244353 震撼
// 异或卷积呐。
// 集合幂级数呐。
/*
Bell Number:
1
1
2
5
15
52
203
877
4140
21147
115975
678570
4213597
27644437
190899322
1382958545
*/
// 每种等值联通块划分方案的容斥系数为其各部分子图的各联通选法带符号权值积之和之积。
// 先对每个图算出有其带符号权值积之和,容易发现为 1 当且仅当无边。
// 然后枚举最小点所在联通块,容斥掉不连通的情况,得到各个块的各联通选法带符号权值积之和。
// 然后把每个联通块转换成异或卷积形式,显然和联通块中最小值一致,或不对异或值做贡献。
// 可以在联通块最小值处标记该联通块,不对异或值做贡献的可以单独做子集合并 dp。
// 对联通块值为最小值的异或卷积信息如何合并?
// 因为 [0,r) 类型的异或卷积虽支持快速乘法,但不支持快速加法,我们考虑怎么办。
// 容易发现没得办。
// 因此我们写一个 Bell 数级别爆搜即可。
// 判掉 m=0,大概能拿 80pts 左右。
// 哦好像可以做到 O(3^n) 之类的,那没事了(
// 其实就是,把每个联通块最小元素也记入状态,算出方案数。
// 然后把这些最小元素选若干来暴力合并出全集即可。
#include <bits/stdc++.h>
typedef unsigned uint;
typedef unsigned long long ullt;typedef long long llt;
typedef bool bol;typedef char chr;typedef void voi;
typedef double dbl;
template<typename T>bol _min(T&a,T b){return b<a?(a=b,true):false;}
template<typename T>bol _max(T&a,T b){return a<b?(a=b,true):false;}
const ullt Mod=998244353;
struct modint
{
ullt v;
modint():v(0){}
modint(ullt v):v(v%Mod){}
ullt&operator()(){return v;}
friend modint operator+(modint a,modint b){return a()+b();}
friend modint operator-(modint a,modint b){return a()+Mod-b();}
friend modint operator*(modint a,modint b){return a()*b();}
modint operator-(){return Mod-v;}
modint _power(ullt index){
modint ans(1),base(*this);
while(index){
if(index&1)ans*=base;
base*=base,index>>=1;
}
return ans;
}
friend modint operator^(modint a,ullt b){return a._power(b);}
modint inv(){return _power(Mod-2);}
modint&operator+=(modint b){return*this=*this+b;}
modint&operator-=(modint b){return*this=*this-b;}
modint&operator*=(modint b){return*this=*this*b;}
voi read(){scanf("%llu",&v);}
voi print(){printf("%llu",v);}
voi println(){print(),putchar('\n');}
};
using modvec=std::vector<modint>;
using vec=std::vector<std::pair<bol,modint> >;
const ullt Lim=1llu<<60;
const uint Bit=60;
ullt Len[Bit+5];
vec get(ullt r){
vec Ans(Bit+1);
for(uint i=0;i<Bit;i++)if(r>=Len[i])Ans[i]={0,1},r-=Len[i];else Ans[i]={1,0};
Ans[Bit]={0,r?1:0};
return Ans;
}
vec mul(vec A,vec B){
modvec UserA(Bit+1),UserB(Bit+1);
for(uint i=0;i<=Bit;i++)UserA[i]=A[i].second*Len[i],UserB[i]=B[i].second*Len[i];
for(uint i=Bit;i;i--)UserA[i-1]+=UserA[i],UserB[i-1]+=UserB[i];
vec Ans(Bit+1);
modint v;
for(uint i=0;i<Bit;i++){
Ans[i]={A[i].first==B[i].first,A[i].second*UserB[i+1]+B[i].second*UserA[i+1]+v};
v+=A[i].second*B[i].second*Len[i];
}
Ans[Bit]={0,A[Bit].second*B[Bit].second+v};
return Ans;
}
modint query(vec A,ullt p){
for(uint i=0;i<Bit;i++)if((p>=Len[i])==A[i].first)return A[i].second;else if(p>=Len[i])p-=Len[i];
return A[Bit].second;
}
ullt A[25],c;
uint E[25];
uint Log2[1u<<15|1],Pop2[1u<<15|1];
modint Dp[1u<<15|1],Dp2[1u<<15|1];
inline uint lowbit(uint v){return v&-v;}
modint T[15][16][1u<<15|1],User[1u<<15|1];
modint Q[16][1u<<15|1];
modint G[1u<<15|1],W[1u<<15|1];
int main()
{
#ifdef MYEE
freopen("QAQ.in","r",stdin);
freopen("QAQ.out","w",stdout);
#else
#endif
Len[Bit]=1;for(uint i=0;i<Bit;i++)Len[i]=Lim>>(i+1);
uint n,m;scanf("%u%u%llu",&n,&m,&c);
{
static uint P[25];for(uint i=0;i<n;i++)scanf("%llu",A+i),P[i]=i,A[i]++;
std::sort(P,P+n,[&](uint a,uint b){return A[a]<A[b];}),std::sort(A,A+n);
std::vector<uint>User(n);
for(uint i=0;i<n;i++)User[P[i]]=i;
for(uint i=0;i<n;i++)P[i]=User[i];
for(uint i=0,u,v;i<m;i++)scanf("%u%u",&u,&v),u=P[u-1],v=P[v-1],E[u]|=1u<<v,E[v]|=1u<<u;
// for(uint i=0;i<n;i++)
// printf("%u%c",P[i]+1," \n"[i==n-1]);
// for(uint i=0;i<n;i++)for(uint j=i+1;j<n;j++)
// if(E[i]>>j&1)printf("%u %u\n",i+1,j+1);
// for(uint i=0;i<n;i++)
// printf("%llu\n",A[i]);
}
if(!m){
vec a=get(1);
for(uint i=0;i<n;i++)a=mul(a,get(A[i]));
query(a,c).println();
return 0;
}
for(uint i=0;i<=n;i++)Log2[1u<<i]=i;
for(uint i=0;i<(1u<<n);i++){
bol ok=1;for(uint j=0;j<n;j++)if(i>>j&1)ok&=!(i&E[j]);
if(ok&&i)Dp[i]=1;
Dp2[i]=Dp[i];
for(uint j=(i-1)&i;j;j=(j-1)&i)if(lowbit(j)==lowbit(i))Dp2[i]-=Dp2[j]*Dp[i^j];
Pop2[i]=Pop2[i>>1]+(i&1);
if(Pop2[i]&1)T[Log2[lowbit(i)]][Pop2[i]-1][i^lowbit(i)]=Dp2[i];
else User[i]=Dp2[i]*A[Log2[lowbit(i)]];
}
// for(uint i=0;i<(1u<<n);i++)Dp[i].print(),putchar(" \n"[i==(1u<<n)-1]);
// for(uint i=0;i<(1u<<n);i++)Dp2[i].print(),putchar(" \n"[i==(1u<<n)-1]);
for(uint i=0;i<n;i++)for(uint j=0;j<n;j++)
for(uint k=0;k<n;k++)for(uint l=0;l<(1u<<n);l++)if(l>>k&1)
T[i][j][l]+=T[i][j][l^(1u<<k)];
modint ans;
for(uint i=0;i<(1u<<n);i++){
vec a=get(1);
for(uint j=0;j<n;j++)if(i>>j&1)a=mul(a,get(A[j]));
G[i]=query(a,c);
}
W[0]=1;
for(uint i=1;i<(1u<<n);i++)for(uint j=i;j;j=(j-1)&i)
if(lowbit(i)==lowbit(j))W[i]+=W[i^j]*User[j];
// for(uint i=0;i<(1u<<n);i++)User[i].print(),putchar(" \n"[i==(1u<<n)-1]);
// for(uint i=0;i<(1u<<n);i++)W[i].print(),putchar(" \n"[i==(1u<<n)-1]);
for(uint i=0;i<(1u<<n);i++){
uint t=(1u<<n)-i-1;
uint cnt=Pop2[t];
for(uint j=t;~j;j=j-1){
Q[0][j&=t]=1;for(uint k=1;k<=cnt;k++)Q[k][j]=0;
for(uint p=0;p<n;p++)if((i>>p&1)&&!(j&((1u<<(p+1))-1)))for(uint k=cnt;~k;k--){
Q[k][j]*=T[p][0][j];for(uint q=1;q<=k;q++)Q[k][j]+=T[p][q][j]*Q[k-q][j];
}
}
for(uint k=0;k<=cnt;k++)for(uint a=0;a<n;a++)if(t>>a&1)
for(uint j=t;j;j=(j-1)&t)if(j>>a&1)
Q[k][j]-=Q[k][j^(1u<<a)];
modint wil;
for(uint j=t;~j;j=j-1)j&=t,wil+=W[j^t]*Q[Pop2[j]][j];
// if(wil()){
// printf("%u\n",i);
// wil.println();
// for(uint j=0;j<(1u<<n);j++)if((j&t)==j)
// Q[Pop2[j]][j].print(),putchar(" \n"[j==t]);
// }
// wil*=G[i];
// G[i].print(),putchar(' '),
// wil.println();
// (wil*G[i]).println();
ans+=wil*G[i];
}
ans.println();
return 0;
}
// g++ graph.cpp -o graph -std=c++11 -DMYEE -Wall
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 20
Accepted
Test #1:
score: 20
Accepted
time: 16ms
memory: 70584kb
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: 15ms
memory: 70364kb
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: 7ms
memory: 70564kb
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: 11ms
memory: 70428kb
input:
4 0 4 9 8 5 2
output:
148
result:
ok 1 number(s): "148"
Test #5:
score: 0
Accepted
time: 14ms
memory: 70368kb
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: 8ms
memory: 70420kb
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: 11ms
memory: 70352kb
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: 11ms
memory: 70432kb
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: 14ms
memory: 70412kb
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: 8ms
memory: 70360kb
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: 17ms
memory: 70428kb
input:
3 0 3 15 7 12
output:
104
result:
ok 1 number(s): "104"
Test #12:
score: 0
Accepted
time: 13ms
memory: 70584kb
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: 13ms
memory: 70520kb
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: 3ms
memory: 70416kb
input:
5 0 12 9 8 14 11 2
output:
3006
result:
ok 1 number(s): "3006"
Test #15:
score: 0
Accepted
time: 4ms
memory: 70532kb
input:
3 1 1 6 10 4 3 1
output:
30
result:
ok 1 number(s): "30"
Subtask #2:
score: 0
Wrong Answer
Dependency #1:
100%
Accepted
Test #16:
score: 0
Wrong Answer
time: 11ms
memory: 70372kb
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:
213452849
result:
wrong answer 1st numbers differ - expected: '5392583', found: '213452849'
Subtask #3:
score: 10
Accepted
Test #47:
score: 10
Accepted
time: 15ms
memory: 70348kb
input:
14 0 731833687287532167 157552918690640051 900457311668526045 111217720157614956 84140984111060473 814012186135880499 784848789620248379 958953377683017264 105083874298571687 104921429970878846 44983041675142735 871013110538758030 686733907990421995 98063590462078176 495161493555059993
output:
231790380
result:
ok 1 number(s): "231790380"
Test #48:
score: 0
Accepted
time: 11ms
memory: 70516kb
input:
11 0 101435837408688522 638776638580507479 933944392115323974 19098604312360490 142362319980029593 419910251764515410 275591812677260089 770239593400917018 928344484461634421 67340905784404712 378109786925249078 110881245457449811
output:
242383534
result:
ok 1 number(s): "242383534"
Test #49:
score: 0
Accepted
time: 11ms
memory: 70484kb
input:
9 0 100988561775675251 622570387572403506 684352103903274038 784649864569409753 270298495621205212 56183537059869110 346856482529145989 86639702870530669 607198038565138736 14747634008501988
output:
20893166
result:
ok 1 number(s): "20893166"
Test #50:
score: 0
Accepted
time: 3ms
memory: 70340kb
input:
10 0 839910859917247463 611237879350518457 292219463776059962 548211857317940894 822255554598388425 335628456629874391 774414280870858683 882480367082748768 654587410087321403 74330774886125511 22894883233341926
output:
61697734
result:
ok 1 number(s): "61697734"
Subtask #4:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%