Codeforces Hello 2019 F. Alex and a TV Show

Alex and a TV Show

Description

添加链接描述

Solution

F i ( j ) F_i(j) Fi(j)表示第 i i i个集合中,是 j j j的倍数的数有多少个,我们对于每个集合只维护对应的 F F F
现在考虑第三个操作,显然有 F x ( j ) = F y ( j ) ∗ F z ( j ) F_x(j)=F_y(j)*F_z(j) Fx(j)=Fy(j)Fz(j)
现在考虑第二个操作,显然也有 F x ( j ) = F y ( j ) + F z ( j ) F_x(j)=F_y(j)+F_z(j) Fx(j)=Fy(j)+Fz(j)
考虑第一个操作,显然有 F x ( j ) = [ j ∣ v ] F_x(j)=[j|v] Fx(j)=[jv]
至于询问,由莫比乌斯反演可得 A n s = ∑ d μ ( d ) F x ( d v ) Ans=\sum_{d}\mu(d)F_x(dv) Ans=dμ(d)Fx(dv)

注意到答案对 2 2 2取模,而按位乘,按位加刚好对应了二进制下的 a n d and and x o r xor xor,于是我们可以对于每个 F F F b i t s e t bitset bitset压起来,求答案时也是按位乘,最后询问时答案就是对应的bitset中 1 1 1的个数。

Code

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<bitset>

#define fo(i,j,l) for(int i=j;i<=l;++i)
#define fd(i,j,l) for(int i=j;i>=l;--i)

using namespace std;
typedef long long ll;
const ll N=1e5+10,mo=1e9+7,V=7e3,K=V+1,P=500;

int n,q,op,x,y,z,oo;

int ys[K][P],gs[K];
bool bz[K];
int ss[K],mu[K];

bitset<K> f[N];
bitset<K> mm,uy;
bitset<K> g[K],h[K];

inline int read()
{
	int o=0; char ch=' ';
	for(;ch<'0'||ch>'9';ch=getchar());
	for(;ch>='0'&&ch<='9';ch=getchar())o=o*10+(ch^48);
	return o;
}

inline void prepare()
{
	mu[1]=1;
	fo(i,2,V){
		if(!bz[i])ss[++oo]=i,mu[i]=-1;
		fo(j,1,oo)if(i*ss[j]<=V){
			bz[i*ss[j]]=true;
			mu[ss[j]*i]=-mu[i];
			if(i%ss[j]==0){
				mu[i*ss[j]]=0;
				break;
			}
		}
	}
	mm=0;
	fo(i,1,V)if(mu[i]!=0)mm[i]=1;
	fo(i,1,V){
		int k=(int)sqrt(i);
		g[i]=0;
		fo(l,1,k)if(i%l==0){
			g[i][l]=1;
			g[i][i/l]=1;
		}
	}
	fo(i,1,V){
		h[i]=0;
		fo(l,1,V/i)h[i][l*i]=(mu[l]!=0);
	}
}

int main()
{
	scanf("%d%d",&n,&q);
	prepare();
	fo(i,1,q){
		op=read();
		if(op==1){
			x=read(); y=read();
			f[x]=g[y];
		}
		if(op==2){
			x=read(); y=read(); z=read();
			f[x]=f[y]^f[z];
		}
		if(op==3){
			x=read(); y=read(); z=read();
			f[x]=f[y]&f[z];
		}
		if(op==4){
			x=read(); y=read();
			uy=f[x]&h[y];
			int ans=(uy.count())%2;
			printf("%d",ans);
		}
	}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值