# UOJ310. 【UNR #2】黎明前的巧克力 [FWT]

UOJ

## 思路

$$1+2x^{a}$$FWT一下，发现结果就只有-13。为什么？根据FWT的理论，$$a_i$$会对$$FWT(a)_j$$产生$$a_i\times (-1)^{\text{bitcnt}[i\&j]}$$的贡献。

（这个解方程咋想到的啊qwq）

## 代码

#include<bits/stdc++.h>
clock_t t=clock();
namespace my_std{
using namespace std;
#define pii pair<int,int>
#define fir first
#define sec second
#define MP make_pair
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
#define drep(i,x,y) for (int i=(x);i>=(y);i--)
#define templ template<typename T>
#define sz 1100000
#define mod 998244353ll
typedef long long ll;
typedef double db;
templ inline T rnd(T l,T r) {return uniform_int_distribution<T>(l,r)(rng);}
templ inline bool chkmax(T &x,T y){return x<y?x=y,1:0;}
templ inline bool chkmin(T &x,T y){return x>y?x=y,1:0;}
{
t=0;char f=0,ch=getchar();double d=0.1;
while(ch>'9'||ch<'0') f|=(ch=='-'),ch=getchar();
while(ch<='9'&&ch>='0') t=t*10+ch-48,ch=getchar();
if(ch=='.'){ch=getchar();while(ch<='9'&&ch>='0') t+=d*(ch^48),d*=0.1,ch=getchar();}
t=(f?-t:t);
}
char __sr[1<<21],__z[20];int __C=-1,__zz=0;
inline void Ot(){fwrite(__sr,1,__C+1,stdout),__C=-1;}
inline void print(register int x)
{
if(__C>1<<20)Ot();if(x<0)__sr[++__C]='-',x=-x;
while(__z[++__zz]=x%10+48,x/=10);
while(__sr[++__C]=__z[__zz],--__zz);__sr[++__C]='\n';
}
void file()
{
#ifdef NTFOrz
freopen("a.in","r",stdin);
#endif
}
inline void chktime()
{
#ifndef ONLINE_JUDGE
cout<<(clock()-t)/1000.0<<'\n';
#endif
}
#ifdef mod
ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x%mod) if (y&1) ret=ret*x%mod;return ret;}
ll inv(ll x){return ksm(x,mod-2);}
#else
ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x) if (y&1) ret=ret*x;return ret;}
#endif
//  inline ll mul(ll a,ll b){ll d=(ll)(a*(double)b/mod+0.5);ll ret=a*b-d*mod;if (ret<0) ret+=mod;return ret;}
}
using namespace my_std;

int n;
int a[sz];

int f[sz];
ll g[sz];
void FWT(int *a,int n)
{
int N=1<<n,x,y;
rep(i,0,n-1)
for (int mid=1<<i,j=0;j<N;j+=mid<<1)
rep(k,0,mid-1)
x=a[j+k],y=a[j+k+mid],a[j+k]=x+y,a[j+k+mid]=x-y;
}
ll I=inv(2);
void iFWT(ll *a,int n)
{
int N=1<<n;ll x,y;
rep(i,0,n-1)
for (int mid=1<<i,j=0;j<N;j+=mid<<1)
rep(k,0,mid-1)
x=a[j+k],y=a[j+k+mid],a[j+k]=(x+y)*I%mod,a[j+k+mid]=(x-y+mod)*I%mod;
}

int main()
{
file();
FWT(f,20);
int x;
rep(i,0,(1<<20)-1) x=(3*n-f[i])/4,g[i]=ksm(mod-1,x)*ksm(3,n-x)%mod;
iFWT(g,20);
printf("%lld\n",(g[0]-1+mod)%mod);
return 0;
}

UOJ310. 【UNR #2】黎明前的巧克力 [FWT]

(0)
(0)