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 ...
随机推荐
- elasticsearch索引路径规则
Path to data on disk In prior versions of Elasticsearch, the path.data directory included a folder f ...
- canvas 绘制圆形进度条
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Android访问网络,使用HttpURLConnection还是HttpClient?
本文转自:http://blog.csdn.net/guolin_blog/article/details/12452307,感谢这位网友的分享,谢谢. 最近在研究Volley框架的源码,发现它在HT ...
- Requests库入门实例
爬虫入门5个实例 实例1:京东商品页面的爬取 import requests def getHTMLText(url): try: r = requests.get(url,timeout = 30) ...
- 如何使用 AutoWire方式注入 JdbcDaoSupport DataSource
@Repositorypublic class MyDaoImpl extends JdbcDaoSupport implements MyDao { @Autowired private Dat ...
- 02--STL算法(函数对象和谓词)
一:函数对象(仿函数):实现状态记录等其他操作<相对于普通函数> 重载函数调用操作符的类,其对象常称为函数对象(function object),即它们是行为类似函数的对象. 即是重载了“ ...
- 部署nexus服务
一.安装和启动 官网下载nexus-2.12安装包,地址:https://sonatype-download.global.ssl.fastly.net/nexus/oss/nexus-2.12.0- ...
- LNMT(Linux+Nginx+MySQL+Tomcat)常见性能参数调优
- Flow类
JLS参考:https://docs.oracle.com/javase/specs/jls/se7/html/jls-16.html This pass implements dataflow an ...
- ActiveMQ发布-订阅消息模式
一.订阅杂志我们很多人都订过杂志,其过程很简单.只要告诉邮局我们所要订的杂志名.投递的地址,付了钱就OK.出版社定期会将出版的杂志交给邮局,邮局会根据订阅的列表,将杂志送达消费者手中.这样我们就可以看 ...