题解 CF1097F 【Alex and a TV Show】
妙妙题……
这道题这要求%2的个数,肯定有什么性质
于是我们想到了用\(bitset\)来处理
由于三操作有\(gcd\),于是我们又想到用反演来解决
我们回忆一下反演的柿子
设\(f(x)\)为x出现了多少次,\(F(x)\)为x的倍数出现了多少次
\]
跟据反演,我们有:
\]
我们要求的数即为\(f(v)\)
由于\(\mu\)的取值只有\(-1, 0, 1\),在膜二意义下只有\(0, 1\)
我们用\(a[x][y]\)表示\(x\)集合内的y即y的倍数出现了多少次(\(F(y)\)),再用\(u[x][y]\)表示\(\mu(\frac{y}{x})\),我们要求的\(f(v) = a[x]\&u[v]\)
再来重新考虑所有操作:
对于1操作,预处理出每一个v的所有约数的\(bitset\),赋值即可
对于2操作,直接用\(a[x]=a[y]^a[z]\)即可
对于3操作,\(a[x] = a[y]\&a[z]\)
对于4操作,用上述方法求出\(bitset\)后的\(1\)的数量
\(Code:\)
#include<bits/stdc++.h>
using namespace std;
#define il inline
#define re register
il int read() {
re int x = 0, f = 1; re char c = getchar();
while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar();}
while(c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
return x * f;
}
#define rep(i, s, t) for(re int i = s; i <= t; ++ i)
#define maxn 7001
#define maxm 100005
int n, m, prim[maxn], vis[maxn], mu[maxn], cnt;
bitset<maxn>G[maxn], a[maxm], u[maxn];
int main() {
n = read(), m = read(), mu[1] = 1;
rep(i, 2, 7000) {
if(!vis[i]) prim[++ cnt] = i, mu[i] = -1;
for(re int j = 1; j <= cnt && prim[j] * i <= 7000; ++ j) {
vis[i * prim[j]] = 1;
if(i % prim[j] == 0) break;
mu[i * prim[j]] = -mu[i];
}
}
rep(i, 1, 7000) {
for(re int j = i; j <= 7000; j += i) G[j][i] = 1, u[i][j] = mu[j / i] != 0;
}
while(m --) {
int opt = read(), x = read();
if(opt == 1) a[x] = G[read()];
if(opt == 2) a[x] = a[read()] ^ a[read()];
if(opt == 3) a[x] = a[read()] & a[read()];
if(opt == 4) printf("%d", (u[read()] & a[x]).count() & 1);
}
return 0;
}
题解 CF1097F 【Alex and a TV Show】的更多相关文章
- CF1097F Alex and a TV Show
题目地址:CF1097F Alex and a TV Show bitset+莫比乌斯反演(个人第一道莫比乌斯反演题) 由于只关心出现次数的奇偶性,显然用bitset最合适 但我们并不直接在bitse ...
- CF1097F Alex and a TV Show 莫比乌斯反演、bitset
传送门 发现自己对mobius反演的理解比较浅显-- 首先我们只需要维护每一个数的出现次数\(\mod 2\)的值,那么实际上我们只需要使用\(bitset\)进行维护,每一次加入一个数将其对应次数异 ...
- 【CF1097F】Alex and a TV Show(bitset)
[CF1097F]Alex and a TV Show(bitset) 题面 洛谷 CF 题解 首先模\(2\)意义下用\(bitset\)很明显了. 那么问题在于怎么处理那个\(gcd\)操作. 然 ...
- 【CF1097F】Alex and a TV Show
[CF1097F]Alex and a TV Show 题面 洛谷 题解 我们对于某个集合中的每个\(i\),令\(f(i)\)表示\(i\)作为约数出现次数的奇偶性. 因为只要因为奇偶性只有\(0, ...
- 【Codeforces 1097F】Alex and a TV Show(bitset & 莫比乌斯反演)
Description 你需要维护 \(n\) 个可重集,并执行 \(m\) 次操作: 1 x v:\(X\leftarrow \{v\}\): 2 x y z:\(X\leftarrow Y \cu ...
- CodeForces - 1097F:Alex and a TV Show (bitset & 莫比乌斯容斥)
Alex decided to try his luck in TV shows. He once went to the quiz named "What's That Word?!&qu ...
- Codeforces Round #569 (Div. 2) 题解A - Alex and a Rhombus+B - Nick and Array+C - Valeriy and Dequ+D - Tolik and His Uncle
A. Alex and a Rhombus time limit per test1 second memory limit per test256 megabytes inputstandard i ...
- Codeforces 1097 Alex and a TV Show
传送门 除了操作 \(3\) 都可以 \(bitset\) 现在要维护 \[C_i=\sum_{gcd(j,k)=i}A_jB_k\] 类比 \(FWT\),只要求出 \(A'_i=\sum_{i|d ...
- Codeforces 1097F Alex and a TV Show (莫比乌斯反演)
题意:有n个可重集合,有四种操作: 1:把一个集合设置为单个元素v. 2:两个集合求并集. 3:两个集合中的元素两两求gcd,然后这些gcd形成一个集合. 4:问某个可重复集合的元素v的个数取模2之后 ...
随机推荐
- kubernetes第八章--NFS PersistentVolume
- Swift之xib模块化设计
一.解决问题 Xib/Storybarod可以方便.可视化的设置约束,在开发中也越来越重要.由于Xib不能组件化,使得封装.重用都变得不可行.本文将介绍一种解决方案,来实现Xib组件化. 二.模型块原 ...
- 7.nth-of-type | nth-child?【CSS】
举例说明: <ul> <p>111</p> <span>222</span> <li>1</li> <li& ...
- iPhone的xib与iPad的xib相互转换
1. xib转换 iPhone版本APP开发完成后需要再开发iPad版本的APP,需要把iPhone版本的xib文件添加到iPad项目中去,但是Xcode中iPhone和iPad使用的xib格式不能完 ...
- Mysql8.0.17安装(windows10)
1.因为系统重装 又双叒叕开始了装mysql数据库 下载安装包 https://dev.mysql.com/downloads/mysql/ 2.解压到你想安装的地方 3.解压完是没有图红色框中的文 ...
- MySQL Backup--Xtrabackup远程备份和限速备份
使用xbstream 备份到远程服务器 ##xbstream 备份到远程服务器 innobackupex \ --defaults-file="/export/servers/mysql/e ...
- Python——结束语句
条件语句: break 结束语句,表示达到某个目的后,将结束当前循环语句,break以下的代码都不执行.例如: for i in range(10): print("--------&quo ...
- curl-手册
Manual -- curl usage explained Related: Man Page FAQ LATEST VERSION You always find news about wha ...
- 如何使用Arduino和SIM900A GPRS / GSM模块将数据发送到Web服务器
今天我们在这里介绍一个非常有趣的项目,我们将使用Arduino开发板和GPRS将数据发送到SparkFun服务器.这是一个基于IoT的项目,我们将使用GSM模块SIM900A将一些数据发送到互联网上的 ...
- openGL起飞篇
我的技术路线:glfw+glad(有了glfw,什么glew,freeglut都不要了) GLFW:直接下载,然后新建vs项目,在<VC++>的<包含目录>添加include路 ...