分析

大佬说看样例就像和卷积有关。

把题目化简成a*x=b,这是个xor的FWT。

FWT的讲解请看:https://www.cnblogs.com/cjyyb/p/9065615.html

那么要求的是x,所以我们得逆着来,则对b进行IFWT,对a FWT,然后c=b/a,于是x=FWT(c).

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#include <set>
#include <bitset>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define random(a, b) rand()*rand()%(b-a+1)+a
#define pi acos(-1.0)
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const int inf = 0x3f3f3f3f;
const int maxn = 3e5+;
const int maxm = 1e5+;
const int mod = 1e9+;
ll qpow(ll a,ll b){
ll res=;
while(b){
if(b&) res=res*a%mod;
b>>=;
a=a*a%mod;
}
return res;
}
ll inv = ;
void IFWT(int a[],int n){
for(int d=;d<n;d<<=)
for(int m=d<<,i=;i<n;i+=m)
for(int j=;j<d;j++){
int x = a[i+j],y=a[i+j+d];
a[i+j]=(x+y)%mod*inv%mod;
a[i+j+d]=(x-y+mod)%mod*inv%mod;
}
} void FWT(int a[],int n){
for(int d=;d<n;d<<=)
for(int m=d<<,i=;i<n;i+=m)
for(int j=;j<d;j++){
int x = a[i+j],y=a[i+j+d];
a[i+j]=(x+y)%mod;
a[i+j+d]=(x-y+mod)%mod;
}
}
int a[maxn],b[maxn];
int main(){
#ifdef LOCAL
freopen("in.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
int n;
scanf("%d",&n);
for(int i=;i<n;i++) scanf("%d",&a[i]);
for(int i=;i<n;i++) scanf("%d",&b[i]);
FWT(a,n);
IFWT(b,n);
for(int i=;i<n;i++) a[i]=b[i]*qpow(a[i],mod-)%mod;
FWT(a,n);
for(int i=;i<n;i++) cout<<a[i]<<endl;
return ;
}

2018牛客网暑期ACM多校训练营(第九场)A -Circulant Matrix(FWT)的更多相关文章

  1. 牛客网暑期ACM多校训练营 第九场

    HPrefix Sum study from : https://blog.csdn.net/mitsuha_/article/details/81774727 k较小.分离x和k. 另外的可能:求a ...

  2. 2018牛客网暑期ACM多校训练营(第二场)I- car ( 思维)

    2018牛客网暑期ACM多校训练营(第二场)I- car 链接:https://ac.nowcoder.com/acm/contest/140/I来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 ...

  3. 2018牛客网暑期ACM多校训练营(第一场)D图同构,J

    链接:https://www.nowcoder.com/acm/contest/139/D来源:牛客网 同构图:假设G=(V,E)和G1=(V1,E1)是两个图,如果存在一个双射m:V→V1,使得对所 ...

  4. 2018 牛客网暑期ACM多校训练营(第一场) E Removal (DP)

    Removal 链接:https://ac.nowcoder.com/acm/contest/139/E来源:牛客网 题目描述 Bobo has a sequence of integers s1, ...

  5. 2018牛客网暑期ACM多校训练营(第十场)A Rikka with Lowbit (树状数组)

    链接:https://ac.nowcoder.com/acm/contest/148/A 来源:牛客网 Rikka with Lowbit 时间限制:C/C++ 5秒,其他语言10秒 空间限制:C/C ...

  6. 2018牛客网暑期ACM多校训练营(第十场)J Rikka with Nickname(二分,字符串)

    链接:https://ac.nowcoder.com/acm/contest/148/J?&headNav=acm 来源:牛客网 Rikka with Nickname 时间限制:C/C++ ...

  7. 2018牛客网暑期ACM多校训练营(第二场)J Farm(树状数组)

    题意 n*m的农场有若干种不同种类作物,如果作物接受了不同种类的肥料就会枯萎.现在进行t次施肥,每次对一个矩形区域施某种类的肥料.问最后枯萎的作物是多少. 分析 作者:xseventh链接:https ...

  8. 2018牛客网暑期ACM多校训练营(第一场)B Symmetric Matrix(思维+数列递推)

    题意 给出一个矩阵,矩阵每行的和必须为2,且是一个主对称矩阵.问你大小为n的这样的合法矩阵有多少个. 分析 作者:美食不可负064链接:https://www.nowcoder.com/discuss ...

  9. 2018牛客网暑期ACM多校训练营(第三场) A - PACM Team - [四维01背包][四约束01背包]

    题目链接:https://www.nowcoder.com/acm/contest/141/A 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524288K ...

  10. 2018牛客网暑期ACM多校训练营(第五场) F - take - [数学期望][树状数组]

    题目链接:https://www.nowcoder.com/acm/contest/143/F 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524288K ...

随机推荐

  1. 【XSY1544】fixed 数学 强连通图计数

    题目描述 ​ 给你一个\(n\times n\)的方阵\(A\).定义方阵\(A\)的不动点\((i,j)\)为:\(\forall p,q\geq 0,(A^p)_{i,j}=(A^q)_{i,j} ...

  2. CODEFORCES掉RATING记 #3

    比赛:Codeforces Round #426 (Div. 2) 时间:2017.7.30晚 开场先看AB A:给你两个方向,和旋转次数(每次旋转90度),问你旋转方向是什么 B:给你一个字符串,问 ...

  3. Fiddler中显示IP方法

    如何在fiddler查看到请求的IP地址?就像下面这样 打开fiddler, 快捷键Ctrl+R  或者  菜单->Rules->Customize Rules…,然后在CustomRul ...

  4. windows 服务器同步互联网时间

    @echo off ::netsh ipsec static set policy name=7road assign=n net time /setsntp:pool.ntp.org net sto ...

  5. rt-thread中线程内置定时器的作用 ---

    @2019-01-15 [小记] 常见到在内核组件的接口函数中,配置和启动一个定时器后,启动线程调度 我猜想是超时时间到达后恢复调用接口函数的线程以执行线程调度语句后的代码

  6. Star sky CodeForces - 835C

    用一个三维数组cnt[x][y][k]表示从(1, 1)到(x, y)亮度为k的个数,然后查询的时候就是对于每一个亮度,计算出这个亮度t秒后的亮度和当前这个亮度的个数,答案就是他们的乘积, 然后遍历每 ...

  7. [HNOI2010]物品调度

    题目描述 现在找工作不容易,Lostmonkey费了好大劲才得到fsk公司基层流水线操作员的职位.流水线上有n个位置,从0到n-1依次编号,一开始0号位置空,其它的位置i上有编号为i的盒子.Lostm ...

  8. 单片机的编程语言和开发环境 LET′S TRY“嵌入式编程”: 3 of 6

    单片机的编程语言和开发环境 LET′S TRY“嵌入式编程”: 3 of 6 本连载讲解作为嵌入式系统开发技术人员所必需具备的基础知识.这些基础知识是硬件和软件技术人员都应该掌握的共通技术知识. 在“ ...

  9. spring5 reactive

    示例代码:https://github.com/srpraneeth/spring5-reactive 说明文档: https://coyee.com/article/12086-spring-5-r ...

  10. 【洛谷P3917】异或序列

    题目大意:给定一个长度为 N 的序列,每个位置有一个权值,求 \[\sum\limits_{1\le i\le j\le n}(a_i\oplus a_{i+1}...\oplus a_j)\] 的值 ...