妙妙题……

这道题这要求%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;
}

最新文章

  1. Font Squirrel
  2. 【故障处理】CRS-1153错误处理
  3. python 核心编程第5章(习题)
  4. 【Linux高频命令专题(20)】du
  5. newClass a = Func(3)中隐藏的操作
  6. POJ 2159 Ancient Cipher
  7. [置顶] 获取激活码,激活myeclipse
  8. ASP.NET快速开发框架、这才是高大上档次后台管理UI界面
  9. JS+CSS打造三级折叠菜单,自动收缩其它级 js
  10. 关于jquery 1.9以上多次点击checkbox无法选择的
  11. ms_celeb_1m数据提取(MsCelebV1-Faces-Aligned.tsv)python脚本
  12. 学习CSS记录:选择符优先级
  13. 性能优化之reflow和repaint
  14. instanceof的用法
  15. 【Django】 gunicorn部署纪要
  16. redis状态监控可视化工具RedisLive使用
  17. 小知识,用myeclipes找jar
  18. Linux 系统开机自启的配置文件
  19. spring冲刺第一天
  20. Google&#39;s C++ coding style

热门文章

  1. Codeforces 1207 G. Indie Album
  2. 在jenkins中使用shell命令推送当前主机上的docker镜像到远程的Harbor私有仓库
  3. MVC-10HTML助手
  4. NEST search查询
  5. ADO.NET 七(一个例子)
  6. 5_PHP数组_3_数组处理函数及其应用_6_数组检索函数
  7. ZK中使用JS读取客户端txt文件内容问题
  8. CRM-Q模糊查询
  9. SQL SERVER-Exclusive access could not be obtained because the database is in use. (Microsoft.SqlServer.SmoExtended)
  10. c# ArrayList 类