码迷,mamicode.com
首页 > 其他好文 > 详细

快速沃尔什变换模板

时间:2020-02-07 00:55:06      阅读:49      评论:0      收藏:0      [点我收藏+]

标签:class   xor   快速   else   int   变换   code   +=   inline   


inline void FWT_or(ll *f, ll x = 1) {
    for (int p = 2, k = 1;p <= n; p <<= 1, k <<= 1) 
        for (int i = 0;i < n; i += p) 
            for (int j = 0;j < k; j++) 
                if (~x) f[i+j+k] = (f[i+j+k] + f[i+j]) % P;
                else f[i+j+k] = (f[i+j+k] - f[i+j] + P) % P;
}

inline void FWT_and(ll *f, ll x = 1) {
    for (int p = 2, k = 1;p <= n; p <<= 1, k <<= 1) 
        for (int i = 0;i < n; i += p) 
            for (int j = 0;j < k; j++) 
                if (~x) f[i+j] = (f[i+j+k] + f[i+j]) % P;
                else f[i+j] = (f[i+j] - f[i+j+k] + P) % P;
}

inline void FWT_xor(ll *f, ll opt = 1) {
    for (int p = 2, k = 1;p <= n; p <<= 1, k <<= 1) 
        for (int i = 0;i < n; i += p) 
            for (int j = 0;j < k; j++) {
                ll x = f[i+j], y = f[i+j+k];
                f[i+j] = (x + y) % P;
                f[i+j+k] = (x + P - y) % P;
                if (opt==-1) f[i+j] = f[i+j] * inv2 % P, f[i+j+k] = f[i+j+k] * inv2 % P;
            }
}


快速沃尔什变换模板

标签:class   xor   快速   else   int   变换   code   +=   inline   

原文地址:https://www.cnblogs.com/Hs-black/p/12271681.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!