# [UOJ UNR#2 黎明前的巧克力]

#include<iostream>
#include<cstring>
#include<cstdio>
#define MN 1048576
#define mod 998244353
using namespace std;
{
int x=0;char ch=getchar();
while(ch<'0'||ch>'9') ch=getchar();
while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
return x;
}
const int Inv2=(mod+1)/2;
int s[MN+5],S[MN+5],n,f[22][MN+5],F[22][MN+5],num[MN+5],sum;

inline int pow(int x,int k)
{
for(sum=1;k;k>>=1,x=1LL*x*x%mod)
if(k&1) sum=1LL*sum*x%mod;
return sum;
}

void FWT(int l,int r)
{
if(l==r) return;
int mid=l+r>>1;FWT(l,mid);FWT(mid+1,r);
for(int i=0;i<=mid-l;++i)
{
int x=s[l+i],y=s[mid+1+i];
s[l+i]=1LL*(x+y)*Inv2%mod;
s[mid+1+i]=1LL*(x-y+mod)*Inv2%mod;
}
}

void Solve(int l,int r,int dep)
{
if(l==r){f[dep][l]=num[l];return;}
int mid=l+r>>1;Solve(l,mid,dep+1);Solve(mid+1,r,dep+1);
for(int i=0;i<=mid-l;++i)
{
f[dep][l+i]=f[dep+1][l+i]+f[dep+1][mid+1+i];
F[dep][l+i]=F[dep+1][l+i]+F[dep+1][mid+1+i];
f[dep][mid+1+i]=f[dep+1][l+i]+F[dep+1][mid+1+i];
F[dep][mid+1+i]=F[dep+1][l+i]+f[dep+1][mid+1+i];
}
}

int main()
{
Solve(0,MN-1,1);
for(int i=0;i<MN;++i)
{
s[i]=pow(3,f[1][i]);
if(F[1][i]&1) s[i]=(mod-s[i])%mod;
}
FWT(0,MN-1);
printf("%d\n",(s[0]-1+mod)%mod);
return 0;
}

posted @ 2017-09-02 22:53  FallDream  阅读(191)  评论(0编辑  收藏  举报