結果

問題 No.2633 Subsequence Combination Score
ユーザー 👑 potato167
提出日時 2024-02-11 13:34:46
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 435 ms / 2,000 ms
コード長 1,316 bytes
コンパイル時間 4,836 ms
コンパイル使用メモリ 269,988 KB
最終ジャッジ日時 2025-02-19 05:02:55
ジャッジサーバーID
(参考情報)
judge1 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
using namespace std;
using std::cout;
using std::cin;
using std::endl;
using ll=long long;
const int mod=998244353;
#define rep(i,a,b) for (int i=(int)(a);i<(int)(b);i++)
#include<atcoder/all>
using namespace atcoder;


void solve();
// oddloop
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int t=1;
    //cin>>t;
    rep(i,0,t) solve();
}

void solve(){
    using mint=modint998244353;
    int L=(1<<18);
    int N;
    cin>>N;
    vector<int> A(L);
    rep(i,0,N){
        int a;
        cin>>a;
        A[a]++;
    }
    vector<mint> dp(L);
    vector<mint> fact(L,1),fact_inv(L,1);
    rep(i,1,L) fact[i]=fact[i-1]*i;
    fact_inv[L-1]=fact[L-1].inv();
    for(int i=L-1;i>0;i--) fact_inv[i-1]=fact_inv[i]*i;
    mint ans=0;
    auto f=[&](auto self,int l,int r) -> void {
        if(l+1==r){
            dp[l]+=fact_inv[l];
            dp[l]*=(mint(2).pow(A[l])-1);
            ans+=dp[l]*fact[l];
            return;
        }
        int m=(l+r)/2;
        self(self,l,m);
        vector<mint> p(m-l),q(r-l);
        rep(i,l,m) p[i-l]=dp[i];
        rep(i,0,r-l) q[i]=fact_inv[i];
        p=convolution(p,q);
        rep(i,m,r) dp[i]+=p[i-l];
        self(self,m,r);
    };
    f(f,0,L);
    cout<<ans.val()<<"\n";
}
0