QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#88392#5827. 异或图myee10 21ms70424kbC++116.7kb2023-03-16 09:40:382023-03-16 09:40:42

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-16 09:40:42]
  • 评测
  • 测评结果:10
  • 用时:21ms
  • 内存:70424kb
  • [2023-03-16 09:40:38]
  • 提交

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);
        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;
    }
    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-i;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

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 20
Accepted
time: 19ms
memory: 70368kb

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: -20
Wrong Answer
time: 21ms
memory: 70344kb

input:

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

output:

804

result:

wrong answer 1st numbers differ - expected: '798', found: '804'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 10
Accepted

Test #47:

score: 10
Accepted
time: 18ms
memory: 70416kb

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: 1ms
memory: 70420kb

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: 7ms
memory: 70424kb

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: 8ms
memory: 70372kb

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:

0%