Codeforces 1097 Alex and a TV Show
传送门
除了操作 \(3\) 都可以 \(bitset\)
现在要维护
\]
类比 \(FWT\),只要求出 \(A'_i=\sum_{i|d}A_d\)
就可以直接按位相乘了
求答案就是莫比乌斯反演,\(A_i=\sum_{i|d}\mu(\frac{d}{i})A'_i\)
把每个数字的 \(\mu\) 的 \(bitset\) 预处理出来,乘法就是 \(and\)
最后用 \(count\) 统计答案
# include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn(7005);
int mu[maxn], n, q, pr[maxn], tot;
bitset <maxn> bc[100005], bcm[7005], bcv[7005], ispr;
int main() {
int i, j, op, l, r, v;
mu[1] = 1;
for (i = 2; i <= 7000; ++i) {
if (!ispr[i]) pr[++tot] = i, mu[i] = -1;
for (j = 1; j <= tot && pr[j] * i <= 7000; ++j) {
ispr[pr[j] * i] = 1;
if (i % pr[j]) mu[i * pr[j]] = -mu[i];
else {
mu[i * pr[j]] = 0;
break;
}
}
}
for (i = 1; i <= 7000; ++i)
for (j = i; j <= 7000; j += i) {
bcv[j].set(i);
if (mu[j / i]) bcm[i].set(j);
}
scanf("%d%d", &n, &q);
for (i = 1; i <= q; ++i) {
scanf("%d%d%d", &op, &l, &r);
if (op == 1) bc[l] = bcv[r];
else if (op == 2) scanf("%d", &v), bc[l] = bc[r] ^ bc[v];
else if (op == 3) scanf("%d", &v), bc[l] = bc[r] & bc[v];
else putchar(((bc[l] & bcm[r]).count() & 1) + '0');
}
return 0;
}
Codeforces 1097 Alex and a TV Show的更多相关文章
- Codeforces 1097F Alex and a TV Show (莫比乌斯反演)
题意:有n个可重集合,有四种操作: 1:把一个集合设置为单个元素v. 2:两个集合求并集. 3:两个集合中的元素两两求gcd,然后这些gcd形成一个集合. 4:问某个可重复集合的元素v的个数取模2之后 ...
- Codeforces 1097F. Alex and a TV Show
传送门 由于只要考虑 $\mod 2$ 意义下的答案,所以我们只要维护一堆的 $01$ 容易想到用 $bitset$ 瞎搞...,发现当复杂度 $qv/32$ 是可以过的... 一开始容易想到对每个集 ...
- 【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 ...
- 【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 bitset+莫比乌斯反演(个人第一道莫比乌斯反演题) 由于只关心出现次数的奇偶性,显然用bitset最合适 但我们并不直接在bitse ...
- codeforces 1097 Hello 2019
又回来了.. A - Gennady and a Card Game 好像没什么可说的了. #include<bits/stdc++.h> using namespace std; cha ...
- 【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 & 莫比乌斯容斥)
Alex decided to try his luck in TV shows. He once went to the quiz named "What's That Word?!&qu ...
- [Codeforces 863E]Turn Off The TV
Description Luba needs your help again! Luba has n TV sets. She knows that i-th TV set will be worki ...
随机推荐
- Tcp下载文件
一.下载文件 tcp 客户端 1.创建套接字down_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)2.获取ip,portdown ...
- 转MVC3介绍
第一节:Asp.Net MVC3项目介绍 让我们先看一下,一个普通的Asp.Net MVC3项目的样例,如下图所示 跟WebFrom还是有区别的,如果你已经了解Asp.Net MVC2的话,那就感觉异 ...
- jQuery 阻止冒泡和默认事件
jQuery event.preventDefault() 方法 event.preventDefault() 方法阻止元素发生默认的行为. 例如: 当点击提交按钮时阻止对表单的提交 阻止以下 URL ...
- document文档对象
document 文挡对象 - JavaScript脚本语言描述———————————————————————注:页面上元素name属性和JavaScript引用的名称必须一致包括大小写否则会提示你一 ...
- (转)MySQL 插入数据时,中文乱码问题的解决
MySQL 插入数据时,中文乱码问题的解决 原文:http://www.cnblogs.com/sunzn/archive/2013/03/14/2960248.html 当向 MySQL 数据库插 ...
- (转)IBM AIX系统为rootvg实现镜像
IBM AIX系统为rootvg实现镜像 AIX系统安装的时候,没有选择安装镜像,因此在系统安装完成后,出于安全方面的考虑,决定为rootvg创建镜像. 工具/原料 AIX rootvg lspv c ...
- django第一课 简单的网页视图
注意本人django版本2.0 python3.6 第一步:创建自己的django项目 django-admin.py startproject ** 第二步:进入**创建app pytho ...
- 【jQuery源码】事件存储结构
a. jQuery事件原型——Dean Edwards的跨浏览器AddEvent()设计 源码解读 重新梳理一下数据结构,使用一个例子 <input type="text" ...
- 简述C和C++的学习历程
总是被问到,如何学习C和C++才不茫然,才不是乱学,想了一下,这里给出一个总的回复. 一家之言,欢迎拍砖哈. 1.可以考虑先学习C. 大多数时候,我们学习语言的目的,不是为了成为一个语言专家,而是希望 ...
- ubuntu 16.04 安装PhpMyAdmin
首先,安装mysql $ sudo apt-get install mysql-server $ sudo apt-get install mysql-client 安装时输出root用户的密码 然后 ...