题解 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之后 ...
随机推荐
- Java8时间转换
===java8中时间的各种转换(LocalDateTime)=== 1.将LocalDateTime转为自定义的时间格式的字符串 public static String getDateTimeAs ...
- winform实现图片的滑动效果
使用winform实现图片的滑动效果(类似网站首页图片滑动切换效果),结果实现了,但是效果其实不是很理想.也许有更好的方法. Timer timerSlide = null; //当前 ...
- fastDFS的入门程序
导入jar包 <dependency> <groupId>cn.bestwu</groupId> <artifactId>fastdfs-client- ...
- python day7: time,datetime,sys,pickle,json模块
目录 python day 7 1. time模块 2. datetime模块 2.1 date类 2.2 time类 2.3 datetime类 2.4 timedelta类 2.5 tzinfo时 ...
- C++线程同步与互斥总结
互斥:当多个线程访问同一个全局变量,或者同一个资源(比如打印机)的时候,需要进行线程间的互斥操作来保证访问的安全性. 临界区.互斥体.事件和信号量都可以实现线程互斥.但如果仅仅需要实现互斥功能,推荐前 ...
- Linux之项目的部署
前期准备 python3解释器 uwsgi wsgi(web服务网关接口,就是一个实现了python web应用的协议) virtualenvwrapper 路飞的代码 vue的代码 nginx (一 ...
- python之变量的数据类型(3)dict 及解构简单介绍
一.变量的数据类型(3) 1. dict 字典dict 用{}来表示 键值对数据 {key:value} 唯一性 键 都必须是可哈希的 不可变的数据类型就可以当做字典中的键 值 没有任何限制 2.增删 ...
- [ipsec][crypto] ike/ipsec与tls的认证机制比较
前言 接上篇:[ipsec][crypto] 有点不同的数字证书到底是什么 本篇内容主要是上一篇内容的延伸.抽象的从概念上理解了证书是什么之后,我们接下来 从实践的角度出发,以IKEv2和TLS两个协 ...
- Linux命令——du
参考:10 Useful du (Disk Usage) Commands to Find Disk Usage of Files and Directories 前言 du(Disk Usage), ...
- prometheus 告警规则
GitHub网址1 https://github.com/samber/awesome-prometheus-alerts 网址2 https://awesome-prometheus-alerts. ...