【CF1097F】Alex and a TV Show

题面

洛谷

题解

我们对于某个集合中的每个\(i\),令\(f(i)\)表示\(i\)作为约数出现次数的奇偶性。

因为只要因为奇偶性只有\(0,1\)两种,我们考虑用\(bitset\)维护这个\(f\)。

那么,

对于\(1\)操作你可以预处理一下\(v\)的\(bitset\),

对于\(2\)操作就是两个集合的\(bitset\)异或一下,

对于\(3\)操作就是两个集合的\(bitset\)与一下。

最后我们要由\(f(i)\)推回\(i\)的出现次数,记为\(g(i)\),显然有

\[f(n)=\sum_{d|n} g(d)
\]

莫比乌斯反演一下,

\[g(n)=\sum_{n|d} \mu (\frac dn) f(d)
\]

你对于每个\(n\)把\(n|d\)的\(\mu (\frac dn)\bmod 2\)预处理出来放在一个\(bitset\)就好了。

代码

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <bitset>
using namespace std;
inline int gi() {
register int data = 0, w = 1;
register char ch = 0;
while (!isdigit(ch) && ch != '-') ch = getchar();
if (ch == '-') w = -1, ch = getchar();
while (isdigit(ch)) data = 10 * data + ch - '0', ch = getchar();
return w * data;
}
const int MAX_N = 1e5 + 5, MAX_M = 7005;
bitset<MAX_M> bs[MAX_N], fact[MAX_M], mu[MAX_M], m;
int N = 7000, Q;
void Prepare() {
m.set();
for (int i = 2; i * i <= N; i++)
for (int j = i * i; j <= N; j += i * i) m[j] = 0;
for (int i = 1; i <= N; i++)
for (int j = i; j <= N; j += i) fact[j][i] = 1, mu[i][j] = m[j / i];
} int main () {
#ifndef ONLINE_JUDGE
freopen("cpp.in", "r", stdin);
#endif
Prepare();
N = gi(), Q = gi();
while (Q--) {
int op = gi(), x = gi(), y = gi(), z;
if (op == 1) bs[x] = fact[y];
if (op == 2) z = gi(), bs[x] = bs[y] ^ bs[z];
if (op == 3) z = gi(), bs[x] = bs[y] & bs[z];
if (op == 4) printf("%lu", (bs[x] & mu[y]).count() & 1);
}
return 0;
}

【CF1097F】Alex and a TV Show的更多相关文章

  1. 【CF1097F】Alex and a TV Show(bitset)

    [CF1097F]Alex and a TV Show(bitset) 题面 洛谷 CF 题解 首先模\(2\)意义下用\(bitset\)很明显了. 那么问题在于怎么处理那个\(gcd\)操作. 然 ...

  2. 【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 ...

  3. retrofit okhttp RxJava bk Gson Lambda 综合示例【配置】

    项目地址:https://github.com/baiqiantao/retrofit2_okhttp3_RxJava_butterknife.git <uses-permission andr ...

  4. CF1097F Alex and a TV Show

    题目地址:CF1097F Alex and a TV Show bitset+莫比乌斯反演(个人第一道莫比乌斯反演题) 由于只关心出现次数的奇偶性,显然用bitset最合适 但我们并不直接在bitse ...

  5. [CodeForces-1225B] TV Subscriptions 【贪心】【尺取法】

    [CodeForces-1225B] TV Subscriptions [贪心][尺取法] 标签: 题解 codeforces题解 尺取法 题目描述 Time limit 2000 ms Memory ...

  6. 【Codeforces Round #442 (Div. 2) A】Alex and broken contest

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 注意是所有的名字里面,只出现了其中某一个名字一次. [代码] #include <bits/stdc++.h> usin ...

  7. Python高手之路【六】python基础之字符串格式化

    Python的字符串格式化有两种方式: 百分号方式.format方式 百分号的方式相对来说比较老,而format方式则是比较先进的方式,企图替换古老的方式,目前两者并存.[PEP-3101] This ...

  8. Python高手之路【三】python基础之函数

    基本数据类型补充: set 是一个无序且不重复的元素集合 class set(object): """ set() -> new empty set object ...

  9. 【原】AFNetworking源码阅读(五)

    [原]AFNetworking源码阅读(五) 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 上一篇中提及到了Multipart Request的构建方法- [AFHTTP ...

随机推荐

  1. Identity Server4资料

    https://www.cnblogs.com/cgzl/p/9405796.html https://www.cnblogs.com/cgzl/p/7780559.html https://clou ...

  2. strpbrk(), strcasecmp(), strspn()

    Linux字符比较函数: strpbrk() strcasecmp() strspn() #if _MSC_VER #define strcasecmp _stricmp //strcasecmp 找 ...

  3. 关于全局异常(@ControllerAdvice)的学习与思考

    一声梧叶一声秋,一点芭蕉一点愁,三更归梦三更后.____徐再思<水仙子·夜雨> 今天的主题是全局异常的构建,处理,以及一些小细节: 至于全局异常的代码构建以及一些常用的异常处理类可以看这篇 ...

  4. APP兼容性测试 (一) 机型选择概要

    一.App兼容性问题有哪些 安装失败.启动失败.卸载失败,卸载不干净. 程序运行过程中闪退 部分控件显示不完整或者功能失效 屏幕显示异常 图片展示不全等 二.App兼容性测试的核心要点 测试软件是否能 ...

  5. C++:Copy & Reference Count

    浅拷贝.深拷贝 通常,我们会按如下方式书写拷贝构造函数: class LiF { public: LiF(int _lif = 0) : lif(_lif) {} // 默认构造函数 LiF(cons ...

  6. Springboot概述

    目录 什么是springboot Springboot的优点 SpringBoot的缺点 一:什么是springboot Springboot是Spring开源组织下的子项目,是Spring组件一站式 ...

  7. 启明星MRBS会议室预约系统V30.0发布

    MRBS系统官方网址 https://www.dotnetcms.org/ 在线演示 http://demo.dotnetcms.org/mrbs 用户名admin,密码123456 Meeting ...

  8. Tomcat put上传漏洞_CVE2017-12615( JSP Upload Bypass/Remote Code Execution)

    CVE2017-12615漏洞复现( tomcat JSP Upload Bypass /Remote Code Execution) 一.漏洞原理 在windows服务器下,将readonly参数设 ...

  9. python 字符前缀,运算符、换行符、数据类型和变量

    补充 *)/ 表示的除法即使是整数,结果也是浮点数 *)python表示的整数是没有大小限制的.而某些语言根据其储存长度是有大小限制的.例如Java对32位整数的范围限制在-2147483648-21 ...

  10. jvm常用排错命令

    jvm命令很多,有一篇博客整理的非常全 https://www.cnblogs.com/ityouknow/p/5714703.html.我只列举一些常用的排错用到的. jps   -l   -v  ...