codeforces548E Mike and Foam -- 容斥
来源:互联网 发布:独立网络经纪人登录 编辑:程序博客网 时间:2024/05/22 13:18
先对所有数质因数分解。显然相同的质因数可以看成一个。这样一个数最多只有
维护
时间复杂度
代码
#include<cmath>#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;#define N 200010#define M 500010#define ll long longinline char nc(){ static char buf[100000],*p1=buf,*p2=buf; return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;}inline void Read(int& x){ char c=nc(); for(;c<'0'||c>'9';c=nc()); for(x=0;c>='0'&&c<='9';x=(x<<3)+(x<<1)+c-48,c=nc());}char ss[30];int Len;inline void Print(ll x){ if(!x)putchar(48); for(Len=0;x;x/=10)ss[++Len]=x%10; while(Len)putchar(ss[Len--]+'0'); putchar('\n');}ll Ans;int s,a[N],c[N][20],l[N],p[N],i,j,k,n,m,f[M],num,Res,q,t;int x,y;bool b[M];inline void Init(){ for(i=2;i<=m;i++){ if(!b[i])p[++num]=i; int t; for(j=1;j<=num&&(t=p[j]*i)<=m;j++){ b[t]=1; if(!(i%p[j]))break; } }}inline void Dfs(int x,int y,int s,bool b){ if(x==l[y]+1){ Res+=(b?1:-1)*f[s]; return; } Dfs(x+1,y,s,b); Dfs(x+1,y,s*c[y][x],b^1);}inline void Dfs2(int x,int y,int s,int d){ if(x==l[y]+1){ if(s>1)f[s]+=d; return; } Dfs2(x+1,y,s,d); Dfs2(x+1,y,s*c[y][x],d);}inline void Update(int x,int d){ if(a[x]==1){ Ans+=d*(k+t);t+=d; if(d==-1)Ans++; return; } Res=0; Dfs(1,x,1,0); Ans+=t*d; Ans+=(k-Res)*d; Dfs2(1,x,1,d); k+=d;}int main(){ Read(n);Read(q);m=2; for(i=1;i<=n;i++)Read(a[i]),m=max(m,a[i]); Init(); for(i=1;i<=n;i++){ x=a[i];s=sqrt(x); for(j=1;p[j]<=s;j++) if(!(x%p[j])){ c[i][++l[i]]=p[j];x/=p[j]; while(!(x%p[j]))x/=p[j]; } if(x>1)c[i][++l[i]]=x; } memset(b,0,sizeof(b)); while(q--){ Read(x); if(!b[x])Update(x,1),b[x]=1; else Update(x,-1),b[x]=0; Print(Ans); } return 0;}
阅读全文
0 0
- codeforces548E Mike and Foam -- 容斥
- Codeforces548E:Mike and Foam
- Mike and Foam - CodeForces #547 C 容斥原理
- Codeforces 547C Mike and Foam 容斥
- CF 547 C Mike and Foam(容斥原理)
- CF 305 div2 E. Mike and Foam (容斥原理)
- codeforces/#305 Div1/547/C Mike and Foam 【容斥】
- E. Mike and Foam(容斥原理)
- Codeforces 548E Mike and Foam(容斥)
- CodeForces 548E Mike and Foam (容斥+数论)
- 【容斥原理】Codeforces547C[Mike and Foam]题解
- 【Codeforces】547C Mike and Foam 容斥
- Codeforces Round #305 (Div. 2) E. Mike and Foam 容斥原理
- *Codeforces Round #305 (Div. 1) C. Mike and Foam(容斥原理)
- Codeforces 548E Mike and Foam (容斥+莫比乌斯反演)
- Code Forces 547 C. Mike and Foam(素因子分解+容斥)
- Codeforces #305 div2 E. Mike and Foam 数论 容斥原理
- Codeforces Round #305 (Div. 1)C. Mike and Foam(素数+容斥)
- 如何在fedora26安装chromium安装flash
- Hibernate框架深入
- 【[Offer收割]编程练习赛23 D】【最小生成树+set的启发式合并】观光旅行
- 【玉蟾宫】codevs 2491
- 冒泡排序
- codeforces548E Mike and Foam -- 容斥
- SPLAY树
- linux,Ubuntu 16.04 设置MySQL远程访问权限
- 发送自定义事件
- max-points-on -a-line
- HDU3072 Intelligence System【最小树形图】
- 《数据库SQL实战》统计出当前各个title类型对应的员工当前薪水对应的平均工资。
- Java注解(二):注解处理器
- 树状数组求逆序对