[模板]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 ...
随机推荐
- CAD由一个自定义实体事件中的id得到自定义实体对象(com接口VB语言)
由一个自定义实体事件中的id得到自定义实体对象.该函数只能在自定义实体事件中调用. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 2 ...
- 用Docker构建Tomcat镜像
构建tomcat镜像 创建工作目录 [root@elk-node2 tomcat]# mkdir tomcat [root@elk-node2 tomcat]# cd tomcat [root@elk ...
- 【maven】Description Resource Path Location Type An error occurred while filtering resources TESTVIDEO line
在maven中构建项目的时候发现了如下错误: Description Resource Path Location Type An error occurred while filtering res ...
- PrintWriter与ServletOutputStream的区别之文件下载
copy自:https://blog.csdn.net/weixin_37703598/article/details/803870611.out = response.getWriter(); re ...
- 右键快捷打开Git Bash here失败
右键快捷打开Git Bash here失败,提示: Error: Could not fork child process: Resource temporarily unavailable (-1) ...
- 小程序button默认样式透彻理解
微信小程序有一个默认样式,特别是有一个外边框,虽然看起来不别扭,但是自己每次设置border:0:都不生效,写成内联的样式也不生效,后来才知道里面的边框是伪元素的边框,这里的伪元素可以理解为用css动 ...
- ROS lesson 1
ROS ROS官网 ROS 简介 ROS 是 Robot Operation System 的简写,并且 他诞生在2000年后,至今有10余年了,运行在 Linux(Ubuntu) 上 ROS 不是 ...
- python lambda简易使用
基本格式 lambda 变量名:函数表达式 ①直接使用 f=lambda x:x**2 f(3) ②设置函数列表 l=[lambda x:x**2, lambda x:x**3, lambda x:x ...
- python基础面试题30问(附带答案)
1. 闭包 定义:闭包是由函数及其相关的引用环境组合而成的实体(即:闭包=函数+引用环境)(想想Erlang的外层函数传入一个参数a, 内层函数依旧传入一个参数b, 内层函数使用a和b, 最后 ...
- reading/writing files in Python
file types: plaintext files, such as .txt .py Binary files, such as .docx, .pdf, iamges, spreadsheet ...