妙妙题……

这道题这要求%2的个数,肯定有什么性质

于是我们想到了用\(bitset\)来处理

由于三操作有\(gcd\),于是我们又想到用反演来解决

我们回忆一下反演的柿子

设\(f(x)\)为x出现了多少次,\(F(x)\)为x的倍数出现了多少次

\[F(d) = \sum_{d|x}f(x)
\]

跟据反演,我们有:

\[f(x) = \sum_{x |d}F(d) * \mu(\frac{d}{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】的更多相关文章

  1. CF1097F Alex and a TV Show

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

  2. CF1097F Alex and a TV Show 莫比乌斯反演、bitset

    传送门 发现自己对mobius反演的理解比较浅显-- 首先我们只需要维护每一个数的出现次数\(\mod 2\)的值,那么实际上我们只需要使用\(bitset\)进行维护,每一次加入一个数将其对应次数异 ...

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

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

  4. 【CF1097F】Alex and a TV Show

    [CF1097F]Alex and a TV Show 题面 洛谷 题解 我们对于某个集合中的每个\(i\),令\(f(i)\)表示\(i\)作为约数出现次数的奇偶性. 因为只要因为奇偶性只有\(0, ...

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

  6. 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 ...

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

  8. 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 ...

  9. Codeforces 1097F Alex and a TV Show (莫比乌斯反演)

    题意:有n个可重集合,有四种操作: 1:把一个集合设置为单个元素v. 2:两个集合求并集. 3:两个集合中的元素两两求gcd,然后这些gcd形成一个集合. 4:问某个可重复集合的元素v的个数取模2之后 ...

随机推荐

  1. WCF与Web API在应用上的选择

    在最近发布的Visual  Studio 2012及.NET 4.5中, 微软正式推出新的网络服务框架ASP.NET Web API.作为ASP.NET MVC  4的一部分,ASP.NET Web ...

  2. mysql数据库备份之主从同步配置

    主从同步意义? 主从同步使得数据可以从一个数据库服务器复制到其他服务器上,在复制数据时,一个服务器充当主服务器(master),其余的服务器充当从服务器(slave).因为复制是异步进行的,所以从服务 ...

  3. isolate sqflite demo

    main.dart import 'package:flutter/material.dart'; import 'demo_isolates.dart'; import 'package:rxdar ...

  4. Java 之 方法引用

    方法引用 一.冗余的Lambda场景 来看一个简单的函数式接口以应用Lambda表达式: @FunctionalInterface public interface Printable { void ...

  5. iOS静态库相关-封装lib

    来源:http://blog.csdn.net/zsomsom/article/details/9163635 Library介绍 基本知识 在实际的编程过程中,通常会把一些公用函数制成函数库,供其它 ...

  6. 阿里P7整理20个非常有用的Java程序片段,你知道吗?

    1.字符串有整型的相互转换 String a = String.valueOf(2);  //integer to numeric string   int i = Integer.parseInt( ...

  7. MySQL Binlog--PURGE MASTER LOGS失败

    问题背景: 在我们磁盘空间维护策略中,BINLOG的默认保留期限为7天,但当磁盘空间不足时,会根据磁盘空间使用率自动清理超过一定数量的BINLOG. 问题原因: 某服务器上报磁盘空间不足,登录服务器发 ...

  8. Linux环境下安装RabbitMQ

    首先RabbitMQ是使用erLang编写的开源消息中间件.所以需要先安装erlang环境. 我使用的是CentOS的系统安装erlang21.0的步骤如下: #下载安装包 (下面是我用的比较匹配的版 ...

  9. DBA面对新mysql环境

    来源:http://blog.csdn.net/wyzxg/article/details/8491152 author:skatetime:2013/01/10 DBA面对新MySQL环境感悟 1. ...

  10. 通过扩展redis-cli来实现在redis集群中移动槽位

    下面的扩展代码基于redis 5.0.2进行扩展, 对于其他的redis版本, 我没有进行相关的测试.考虑到redis集群的修改频率,这段代码应该同时适用于其他的redis版本. 下面为修改的代码: ...