[模板]FWT
写起来和fft很像,这里放个板子.
代码:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<ctime>
#include<queue>
#include<map>
#include<algorithm>
#include<cstring>
using namespace std;
#define duke(i,a,n) for(register int i = a;i <= n;i++)
#define lv(i,a,n) for(register int i = a;i >= n;i--)
#define clean(a) memset(a,0,sizeof(a))
const int INF = << ;
typedef long long ll;
typedef double db;
template <class T>
void read(T &x)
{
char c;
bool op = ;
while(c = getchar(), c < '' || c > '')
if(c == '-') op = ;
x = c - '';
while(c = getchar(), c >= '' && c <= '')
x = x * + c - '';
if(op) x = -x;
}
template <class T>
void write(T x)
{
if(x < ) putchar('-'), x = -x;
if(x >= ) write(x / );
putchar('' + x % );
}
#define N 1 << 21 | 3
const int mod = ;
int lim,base;
int a[N],b[N],c[N];
inline int mlt(int x,int y)
{
return x * 1ll * y % mod;
}
inline int mo(int x,int y)
{
if(x + y >= mod) return x + y - mod;
if(x + y < ) return x + y + mod;
return x + y;
}
inline int d2(int x)
{
return (x & ) ? (x + mod) >> : x >> ;
}
void fwt(int *a,int d,int op)
{
for(int i = ;i < lim;i <<= )
{
for(int k = ;k < lim;k += (i << ))
{
for(int l = ;l < i;l++)
{
if(op == )
a[k + l + i] = mo(a[k + l + i],d * a[k + l]);
else if(op == )
a[k + l] = mo(a[k + l],d * a[k + l + i]);
else
{
int nx = a[k + l],ny = a[k + l + i];
a[k + l] = mo(nx,ny),a[k + l + i] = mo(nx,-ny);
if(d == -)
a[k + l] = d2(a[k + l]),a[k + l + i] = d2(a[k + l + i]);
}
}
}
}
}
int main()
{
read(base);
lim = << base;
duke(i,,lim - ) read(a[i]);
duke(i,,lim - ) read(b[i]);
for(int op = ;op <= ;op ++)
{
fwt(a,,op);
fwt(b,,op);
for(int i = ;i < lim;i++)
{
c[i] = mlt(a[i],b[i]);
}
fwt(a,-,op);
fwt(b,-,op);
fwt(c,-,op);
duke(i,,lim - )
{
printf("%d ",c[i]);
}
puts("");
}
return ;
}
[模板]FWT的更多相关文章
- P4717 【模板】快速沃尔什变换
思路 FWT的模板 FWT解决这样的卷积 \[ C_k=\sum_{i\otimes j=k} A_iB_j \] \(\otimes\)可能是and,or,xor等位运算 几个式子 FWTand: ...
- FWT模板(洛谷P4717 【模板】快速沃尔什变换)(FWT)
洛谷题目传送门 只是一个经过了蛇皮压行的模板... 总结?%%%yyb%%% #include<bits/stdc++.h> #define LL long long #define RG ...
- 【洛谷4717】【模板】快速沃尔什变换(FWT模板)
点此看题面 大致题意: 有两个长度为\(2^n\)的数组\(A,B\),且\(C_i=\sum_{j⊕k==i}A_jB_k\)分别求出当\(⊕\)为\(or,and,xor\)时的\(C\)数组. ...
- 【模板/经典题型】FWT
FWT在三种位运算下都满足FWT(a×b)=FWT(a)*FWT(b) 其中or卷积和and卷积还可以通过FMT实现(本质上就是个高维前缀和) #include<bits/stdc++.h> ...
- Luogu4717 【模板】快速沃尔什变换(FWT)
https://www.cnblogs.com/RabbitHu/p/9182047.html 完全没有学证明的欲望因为这个实在太好写了而且FFT就算学过也忘得差不多了只会写板子 #include&l ...
- 快速沃尔什变换(FWT)学习笔记 + 洛谷P4717 [模板]
FWT求解的是一类问题:\( a[i] = \sum\limits_{j\bigoplus k=i}^{} b[j]*c[k] \) 其中,\( \bigoplus \) 可以是 or,and,xor ...
- NTT FWT(xor or and) 模板
void nnt(int a[],int len,int on) { ;i<len;i++) if(i<r[i]) swap(a[i],a[r[i]]); ;i<len;i<& ...
- FWT模板
代码来自51nod1570 #include<cstdio> #include<cstring> #include<algorithm> #define MN 50 ...
- 洛谷.4717.[模板]快速沃尔什变换(FWT)
题目链接 https://www.mina.moe/archives/7598 //285ms 3.53MB #include <cstdio> #include <cctype&g ...
随机推荐
- crm01 Django-admin管理工具
admin组件使用 Django 提供了基于 web 的管理工具. Django 自动管理工具是 django.contrib 的一部分.你可以在项目的 settings.py 中的 INSTALLE ...
- 100 道 Linux 笔试题,能拿 80 分就算大神!
本套笔试题共100题,每题1分,共100分.(参考答案在文章末尾) 1. cron 后台常驻程序 (daemon) 用于: A. 负责文件在网络中的共享 B. 管理打印子系统C. 跟踪管理系统信息和错 ...
- 使用lombok注解@Getter @Setter方法代码编译成功,但是没有生成get,set方法
现象描述: 在对应类对象中,添加lombok的@Getter或@Setter注解,编译没有问题,但是在使用类对象时,没有出现对应的get或set方法. 配置且编译ok,但是没有对应的get或set方法 ...
- Leetcode724:寻找数组的中心索引(java、python3)
寻找数组的中心索引 给定一个整数类型的数组 nums,请编写一个能够返回数组"中心索引"的方法. 我们是这样定义数组中心索引的:数组中心索引的左侧所有元素相加的和等于右侧所有元素相 ...
- moongoTemplate使用
添加依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifact ...
- 『 Luogu P3205 』 HNOI2010 合唱队
解题思路 设置两个二维数组 $f$ 和 $g$,含义如下. $f[l][r]$ 表示在期望得到的队形中 $l\rightarrow r$ 这段区间初始队形排列的方案数,并且最后一个加入进去的是第 $l ...
- 洛谷 2449 [SDOI2005]矩形
[题解] 因为这道题中n比较小,n^2效率是可以接受的. 枚举两个矩形,如果它们有重叠部分,就用并查集合并一下即可. #include<cstdio> #include<algori ...
- springcloud(九):熔断器Hystrix和Feign的应用案例
因为 feign 中已经支持了 Hystrix ,所以在 Feign 中使用 Hystrix 时,不需要导包,也不需要在入口类上面增加额外的注解: Feign 虽然支持了 Hystrix ,但是默认 ...
- 【Codeforces 1118D1】Coffee and Coursework (Easy version)
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 从小到大枚举天数. 然后贪心地,从大到小分配a[i]到各个天当中. a[n]分配到第1天,a[n-1]分配到第2天,...然后a[n-x]又分 ...
- CODEVS1022 覆盖 (二分图染色+匈牙利算法)
先对整幅图进行二分图染色,再跑一遍匈牙利算法. /* CODEVS1022 */ #include <cstdio> #include <cstring> #include & ...