题解 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之后 ...
随机推荐
- [LOJ2002] [SDOI2017] 序列计数
题目链接 LOJ:https://loj.ac/problem/2002 洛谷:https://www.luogu.org/problemnew/show/P3702 Solution 考虑补集转换, ...
- IntelliJ IDEA 2019 激活码 | 全产品 | 跨平台 | Goland | PhpStorm | Rider | CentOS | Windows
>>> 下载地址: https://kenkao.pipipan.com/fs/14896800-375468824 >>> 下载地址2: https://pan. ...
- 单实例dg软件从10.2.0.4版本安装至10.2.0.5.12
DG环境搭建需求,因此安装与主库相同的软件版本 1.主库软件版本10.2.0.5.12 2dg环境提供的是全新的10.2.0.4.0 3.安装步骤,安装10.2.0.5 静默安装 psu安装10.2. ...
- 【洛谷 SP8093】 JZPGYZ - Sevenk Love Oimaster(后缀自动机)
题目链接 广义sam.. #include <cstdio> #include <cstring> #include <algorithm> using names ...
- SocketException: Write failed (OS Error: Broken pipe, errno = 32
https://github.com/flutter/flutter/issues/16491
- thinkPHP5.0 使用PHPExcel导出Excel文件
首先下载PHPExcel类.网上很多,自行下载. 我下载的跟composer下载的不太一样.我下载的是 下载存放目录.jpg 而composer下载的是: composer下载.jpg 本篇使 ...
- go语言实现分布式id生成器
本文:https://chai2010.cn/advanced-go-programming-book/ch6-cloud/ch6-01-dist-id.html 分布式id生成器 有时我们需要能够生 ...
- 服务网关ZuulFilter过滤器--如何解决跨域请求中的OPTIONS请求
进行跨域请求的时候,并且请求头中有额外参数,比如token,客户端会先发送一个OPTIONS请求 来探测后续需要发起的跨域POST请求是否安全可接受 所以这个请求就不需要拦截,下面是处理方式 @Ove ...
- 【hbase】hbase-2.2.1配置独立的zookeeper的安装与测试
下载hbase-2.2.1-bin.tar.gz并执行安装命令: [hadoop@hadoop01 ~]$ tar -zxvf hbase--bin.tar.gz 查看安装目录: [hadoop@ha ...
- Mac 下 安装Python3
因为Mac系统自带Python2.7 所以我们开发要重新装Python3 直接运行下面就好 luohaotiandeMacBook-Pro:~ luohaotian$ which python /us ...