题目传送门

题目大意

给出\(n,s_{1,2,...,n}\),定义一个五元组\((a,b,c,d,e)\)合法当且仅当:

  1. \[1\le a,b,c,d,e\le n
    \]
  2. \[(s_a\vee s_b)\wedge s_c \wedge (s_d\oplus s_e)=2^i,i\in \mathbb{Z}
    \]
  3. \[s_a\wedge s_b=0
    \]

求出对于所有合法的五元组\((a,b,c,d,e)\):

\[\sum f(s_a\vee s_b)f(s_c)f(s_d\oplus s_e)
\]

其中\(f(i)\)表示第\(i\)位斐波拉契数列。

思路

其实这个题应该算\(\text {FST}\)的入门级题目,也不是很难。

首先,我们定义\(v(a,b,c,d,e)=(s_a\vee s_b)\wedge s_c \wedge (s_d\oplus s_e)\)。于是我们可以把式子写成这样一个形式:

\[\sum_{i} \sum_{v(a,b,c,d,e)=2^i} [s_a\wedge s_b=0]f(s_a\vee s_b)f(s_c)f(s_d\oplus s_e)
\]
\[=\sum_{p} \sum_{i\wedge j\wedge k=2^p} f(i)f(j)f(k)(\sum_{s_a\vee s_b=i,s_a\wedge s_b=0}1)(\sum_{s_a\oplus s_b=k}1)
\]

然后我们就发现第一个括号里面的可以用子集卷积求到,后面那个可以用异或卷积求到,总的又可以用并卷积求到。于是我们就可以在\(\Theta(w\log ^2w)\)的时间内求到了。其中\(w\)是值域。

\(\text {Code}\)

#include <bits/stdc++.h>
using namespace std; #define Int register int
#define inv2 500000004
#define mod 1000000007
#define MAXN 1000005 template <typename T> inline void read (T &t){t = 0;char c = getchar();int f = 1;while (c < '0' || c > '9'){if (c == '-') f = -f;c = getchar();}while (c >= '0' && c <= '9'){t = (t << 3) + (t << 1) + c - '0';c = getchar();} t *= f;}
template <typename T,typename ... Args> inline void read (T &t,Args&... args){read (t);read (args...);}
template <typename T> inline void write (T x){if (x < 0){x = -x;putchar ('-');}if (x > 9) write (x / 10);putchar (x % 10 + '0');} int lim = 1; void mul (int &a,int b){a = 1ll * a * b % mod;}
void del (int &a,int b){a = a >= b ? a - b : a + mod - b;}
void add (int &a,int b){a = a + b >= mod ? a + b - mod : a + b;} void ORFWT (int *A,int type){
for (Int i = 1;i < lim;i <<= 1)
for (Int j = 0;j < lim;j += i << 1)
for (Int k = 0;k < i;++ k)
if (type == 1) add (A[i + j + k],A[j + k]);
else del (A[i + j + k],A[j + k]);
} void ANDFWT (int *A,int type){
for (Int i = 1;i < lim;i <<= 1)
for (Int j = 0;j < lim;j += i << 1)
for (Int k = 0;k < i;++ k)
if (type == 1) add (A[j + k],A[i + j + k]);
else del (A[j + k],A[i + j + k]);
} void XORFWT (int *A,int type){
for (Int i = 1;i < lim;i <<= 1)
for (Int j = 0;j < lim;j += i << 1)
for (Int k = 0;k < i;++ k){
int x = A[j + k],y = A[i + j + k];
if (type == 1) A[j + k] = (x + y) % mod,A[i + j + k] = (x + mod - y) % mod;
else A[j + k] = 1ll * (x + y) * inv2 % mod,A[i + j + k] = 1ll * (x + mod - y) * inv2 % mod;
}
} int n,s,fib[1 << 17],cnt[1 << 17],A[1 << 17],S[1 << 17],f[18][1 << 17],h[1 << 17],sum[1 << 17]; signed main(){
read (n);
fib[0] = 0,fib[1] = cnt[1] = 1;int maxn = 0;
for (Int i = 2;i < (1 << 17);++ i) fib[i] = (fib[i - 1] + fib[i - 2]) % mod,cnt[i] = cnt[i >> 1] + (i & 1);
for (Int i = 1,s;i <= n;++ i) read (s),maxn = max (maxn,s),add (f[cnt[s]][s],1),add (h[s],1),add (sum[s],fib[s]);
int logn = 0;while (lim <= maxn) lim <<= 1,logn ++;
for (Int i = 0;i <= logn;++ i) ORFWT (f[i],1);
for (Int i = 0;i <= logn;++ i){
for (Int j = 0;j < lim;++ j) S[j] = 0;
for (Int j = 0;j <= i;++ j)
for (Int k = 0;k < lim;++ k)
add (S[k],1ll * f[j][k] * f[i - j][k] % mod);
ORFWT (S,-1);
for (Int j = 0;j < lim;++ j) if (cnt[j] == i) add (A[j],S[j]);
}
XORFWT (h,1);
for (Int i = 0;i < lim;++ i) mul (h[i],h[i]);
XORFWT (h,-1);
for (Int i = 0;i < lim;++ i) mul (A[i],fib[i]),mul (h[i],fib[i]);
ANDFWT (A,1),ANDFWT (h,1),ANDFWT (sum,1);
for (Int i = 0;i < lim;++ i) mul (A[i],h[i]),mul (A[i],sum[i]);
ANDFWT (A,-1);
int ans = 0;for (Int i = 1;i < lim;i <<= 1) add (ans,A[i]);
write (ans),putchar ('\n');
return 0;
}

题解 CF914G Sum the Fibonacci的更多相关文章

  1. CF914G Sum the Fibonacci(FWT,FST)

    CF914G Sum the Fibonacci(FWT,FST) Luogu 题解时间 一堆FWT和FST缝合而来的丑陋产物. 对 $ cnt[s_{a}] $ 和 $ cnt[s_{b}] $ 求 ...

  2. CF914G Sum the Fibonacci (快速沃尔什变换FWT + 子集卷积)

    题面 题解 这是一道FWT和子集卷积的应用题. 我们先设 cnt[x] 表示 Si = x 的 i 的数量,那么 这里的Nab[x]指满足条件的 Sa|Sb=x.Sa&Sb=0 的(a,b)二 ...

  3. CF914G Sum the Fibonacci FWT、子集卷积

    传送门 一道良心的练习FWT和子集卷积的板子-- 具体来说就是先把所有满足\(s_a \& s_b = 0\)的\(s_a \mid s_b\)的值用子集卷积算出来,将所有\(s_a \opl ...

  4. CF914G Sum the Fibonacci

    解:发现我们对a和b做一个集合卷积,对d和e做一个^FWT,然后把这三个全部对位乘上斐波那契数,然后做&FWT就行了. #include <bits/stdc++.h> , MO ...

  5. 【CF914G】Sum the Fibonacci 快速??变换模板

    [CF914G]Sum the Fibonacci 题解:给你一个长度为n的数组s.定义五元组(a,b,c,d,e)是合法的当且仅当: 1. $1\le a,b,c,d,e\le n$2. $(s_a ...

  6. Codecraft-18 and Codeforces Round #458 (Div. 1 + Div. 2, combined)G. Sum the Fibonacci

    题意:给一个数组s,求\(f(s_a | s_b) * f(s_c) * f(s_d \oplus s_e)\),f是斐波那契数列,而且要满足\(s_a\&s_b==0\),\((s_a | ...

  7. 【codeforces914G】Sum the Fibonacci FWT+FST(快速子集变换)

    题目描述 给出一个长度为 $n$ 的序列 $\{s\}$ ,对于所有满足以下条件的五元组 $(a,b,c,d,e)$ : $1\le a,b,c,d,e\le n$ : $(s_a|s_b)\& ...

  8. LeetCode题解——Two Sum

    题目地址:https://oj.leetcode.com/problems/two-sum/ Two Sum Given an array of integers, find two numbers ...

  9. LeetCode题解之Sum Root to Leaf Numbers

    1.题目描述 2.问题分析 记录所有路径上的值,然后转换为int求和. 3.代码 vector<string> s; int sumNumbers(TreeNode* root) { tr ...

随机推荐

  1. 理解Java中对象基础Object类

    一.Object简述 源码注释:Object类是所有类层级关系的Root节点,作为所有类的超类,包括数组也实现了该类的方法,注意这里说的很明确,指类层面. 所以在Java中有一句常说的话,一切皆对象, ...

  2. vue2+vite初体验

    前言 自从 vite 发布之后,社区赞誉无数,而我也一直心水 vite 的轻量快速的热重载的特性,特别是公司的项目巨大,已经严重拖慢了热重载的速度了,每次热重载都要等上一小会,所以急需寻找一个解决方案 ...

  3. JS_DOM操作之常用事件

    1 - onload 事件:加载完成后立即执行 <!DOCTYPE html> <html lang="en"> <head> <meta ...

  4. Python习题集(十二)

    每天一习题,提升Python不是问题!!有更简洁的写法请评论告知我! https://www.cnblogs.com/poloyy/category/1676599.html 题目 请写一个函数fin ...

  5. 《Go语言圣经》阅读笔记:第三章基础数据类型

    第三章 基础数据类型 Go语言将数据类型分为四类: 基础类型 数字 整数 浮点数 复数 字符串 布尔 复合类型 数据 结构体 引用类型 指针 切片 字典 函数 通道 接口类型 在此章节中先介绍基础类型 ...

  6. vscode安装go插件失败

    解决办法:使用golang代理,在环境变量中添加两个新变量: 详情参考vscode中为golang开发环境配置代理goproxy 之后便有一部分可以安装成功

  7. shell 脚本 根据PID过滤查看进程所有信息

    #!/bin/bash read -p "输入要查询的PID: " P #筛选第二列等于输入的PID号 n=`ps aux | awk '$2~/^'$P'$/ {print $1 ...

  8. python模块--glob, fnmatch

    包/方法 返回值 参数 说明 glob     Unix shell样式的路径扩展 .glob() list 匹配满足规则的所有路径(默认以 . 开头的文件不会匹配到, 可以用 .* 来匹配) pat ...

  9. unity2021游戏引擎安装激活并汉化

    今天重新搭建了下unity的开发环境,也踩了不少坑,还有就是看了一些unity3d的教程,越看越不可思议,unity居然能做这么多好玩的东西,像枪战类,模拟类,角色扮演,动作冒险都很震撼. 但是震撼归 ...

  10. java版gRPC实战之七:基于eureka的注册发现

    欢迎访问我的GitHub https://github.com/zq2599/blog_demos 内容:所有原创文章分类汇总及配套源码,涉及Java.Docker.Kubernetes.DevOPS ...