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 ...
随机推荐
- (6)Oracle基础--简单查询
.基本查询语句 SELECT [DISTINCT] column_name1,... | * FROM table_name [WHERE conditions]; P: DISTINCT关键字的作 ...
- 《JAVA与模式》之代理模式
在阎宏博士的<JAVA与模式>一书中开头是这样描述代理(Proxy)模式的: 代理模式是对象的结构模式.代理模式给某一个对象提供一个代理对象,并由代理对象控制对原对象的引用. 代理模式的结 ...
- MFC多线程技术
MFC中有两类线程,分别称之为工作者线程和用户界面线程.二者的主要区别在于工作者线程没有消息循环,而用户界面线程有自己的消息队列和消息循环. 工作者线程没笑消息机制,通常用来执行后台计算和维护任务,如 ...
- Found an unexpected Mach-O header code: 0x72613c21
在按照第三方sdk文档中的Emedded Binaries 中加入了他们的framework,在删除这下面的对应的framework后,问题就得到了解决 发下有个英文的页面也是涉及这个问题的, 描述的 ...
- iOS 11 application 新特性
1.- (void)applicationWillResignActive:(UIApplication *)application 说明:当应用程序将要入非活动状态执行,在此期间,应用程序不接收消息 ...
- java编写service详细笔记 - centos7.2实战笔记(windows类似就不在重复了)
java编写service详细笔记 - centos7.2实战笔记(windows类似就不在重复了) 目标效果(命令行启动服务): service xxxxd start #启动服务 servic ...
- (转)Python标准库:内置函数print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False)
原文:https://blog.csdn.net/caimouse/article/details/44133241 https://www.cnblogs.com/owasp/p/5372476.h ...
- 摘要:ASP.NET的路由
原文:ASP.NET的路由系统:路由映射 对物理存在文件的路由 在成功注册路由的情况下,如果我们按照传统的方式访问一个物理文件(比如http://localhost:2738/Default.aspx ...
- Intellij-怎么避免import.*包,以及import包顺序问题
Intellij版本 IntelliJ IDEA 2018.1.2 (Ultimate Edition) Build #IU-181.4668.68, built on April 24, 2018 ...
- win10上走网络打印机(不需找驱动包,会自动)
不多说,直接上干货! 之前是 现在是 结束 欢迎大家,加入我的微信公众号:大数据躺过的坑 人工智能躺过的坑 同时,大家可以关注我的个人博客: http://www.cn ...