题意:给出数组arr和一个空数组dst。从arr中取出一个元素到dst为一次操作。问每次操作后dst数组中gcd等于1的组合数。
由于数据都小于10^6,先将10^6以下的数分解质因数。具体来说从2开始,将2的倍数全部加2因子(用的vector),3的倍数加3因子。4不是质数,它的倍数不加因子。

还要一个cnt数组记录dst中有几个数是数组下标的倍数。

在放入元素x到dst数组,对于它的每个质因数及质因数间的乘积,看cnt中的量。组合数的增量为dst的sz(size)-(cnt[x的质因数])(即dst中和x都有x的质因数,因此要减)+(cnt[x的两个质因数的乘积])......然后再对x的素因子及成绩在cnt上加1.

乱码:

//#pragma comment(linker,"/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include <stack>
#include <list>
using namespace std;
const int SZ=,INF=0x7FFFFFFF;
typedef long long lon;
const double EPS=1e-;
vector<lon> fen[SZ];
bool used[SZ];
lon cnt[SZ]; void init(lon n)
{
for(int i=;i<n;++i)
{
if(fen[i].empty())
for(int j=i;j<n;j+=i)
{
fen[j].push_back(i);
}
}
} void add(vector<lon> &vct,bool type)
{
lon sz=vct.size();
for(lon i=;i<(<<sz);++i)
{
lon res=;
for(lon j=;j<;++j)
{
if(i&(<<j))
{
res*=vct[j];
}
}
if(type)++cnt[res];
else --cnt[res];
}
} lon work(vector<lon> &vct)
{
lon ans=;
lon sz=vct.size();
//cout<<" "<<sz<<endl;
for(lon i=;i<(<<sz);++i)
{
lon res=;
lon co=;
for(lon j=;j<;++j)
{
if(i&(<<j))
{
res*=vct[j];
co*=-;
}
}
ans+=co*cnt[res];
}
return ans;
} int main()
{
std::ios::sync_with_stdio();
//freopen("d:\\1.txt","r",stdin);
lon n,m;
cin>>n>>m;
vector<lon> vct(n);
for(int i=;i<n;++i)
{
cin>>vct[i];
} init(5e5+);
lon num=;
lon last=;
for(int i=;i<m;++i)
{
lon id;
cin>>id;
--id;
lon res=;
if(!used[id])
{
res+=work(fen[vct[id]]);
//cout<<" "<<res<<endl;
add(fen[vct[id]],);
used[id]=;
res=last+res+num;
}
else
{
res=last;
add(fen[vct[id]],);
lon val=work(fen[vct[id]]);
//cout<<" "<<val<<endl;
res-=num-+work(fen[vct[id]]);
//cout<<" "<<res<<endl;
used[id]=;
}
cout<<res<<endl;
if(used[id])++num;
else --num;
last=res;
}
return ;
}

codeforces 547c// Mike and Foam// Codeforces Round #305(Div. 1)的更多相关文章

  1. hdu4135-Co-prime & Codeforces 547C Mike and Foam (容斥原理)

    hdu4135 求[L,R]范围内与N互质的数的个数. 分别求[1,L]和[1,R]和n互质的个数,求差. 利用容斥原理求解. 二进制枚举每一种质数的组合,奇加偶减. #include <bit ...

  2. Codeforces.547C.Mike and Foam(容斥/莫比乌斯反演)

    题目链接 \(Description\) 给定n个数(\(1\leq a_i\leq 5*10^5\)),每次从这n个数中选一个,如果当前集合中没有就加入集合,有就从集合中删去.每次操作后输出集合中互 ...

  3. set+线段树 Codeforces Round #305 (Div. 2) D. Mike and Feet

    题目传送门 /* 题意:对于长度为x的子序列,每个序列存放为最小值,输出长度为x的子序列的最大值 set+线段树:线段树每个结点存放长度为rt的最大值,更新:先升序排序,逐个添加到set中 查找左右相 ...

  4. 数论/暴力 Codeforces Round #305 (Div. 2) C. Mike and Frog

    题目传送门 /* 数论/暴力:找出第一次到a1,a2的次数,再找到完整周期p1,p2,然后以2*m为范围 t1,t2为各自起点开始“赛跑”,谁落后谁加一个周期,等到t1 == t2结束 详细解释:ht ...

  5. 暴力 Codeforces Round #305 (Div. 2) B. Mike and Fun

    题目传送门 /* 暴力:每次更新该行的num[],然后暴力找出最优解就可以了:) */ #include <cstdio> #include <cstring> #includ ...

  6. 字符串处理 Codeforces Round #305 (Div. 2) A. Mike and Fax

    题目传送门 /* 字符串处理:回文串是串联的,一个一个判断 */ #include <cstdio> #include <cstring> #include <iostr ...

  7. Codeforces Round# 305 (Div 1)

    [Codeforces 547A] #include <bits/stdc++.h> #define maxn 1000010 using namespace std; typedef l ...

  8. Codeforces Round #305 (Div. 2)

    C. Mike and Frog 题意:有一只青蛙和一朵花,分别高度为h1.h2,每浇一次水,h1=(x1*h1+y1)mod m,h2=(x2*h2+y2)mod m.求最少浇多少次后h1=a1,h ...

  9. Codeforces Round #305 (Div. 2) E题(数论+容斥原理)

    E. Mike and Foam time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

随机推荐

  1. Eclipse 启动项目错误:class not found

    其中,很可能的原因:项目存在编译错误,根本没有编译成功,没有生成class文件:可查看problems标签页查看具体错误.

  2. appium记录

    npm uninstall appium -g npm install -g cnpm --registry=https://registry.npm.taobao.org cnpm install ...

  3. IT行业——Linux

    现在是21世纪,是科学技术大力发展的一个时代,IT行业已经成为现在的一个非常热门的一个行业,许许多多的人都想要往IT方面发展,找IT方面相关的一个工作.因此,现在也出现了很多IT培训机构,比如培训Li ...

  4. iOS原生的AVFoundation扫描二维码/条形码

    #import <AVFoundation/AVFoundation.h> @interface ViewController ()<AVCaptureMetadataOutputO ...

  5. 20145101《Java程序设计》第三周学习总结

    20145101 <Java程序设计>第3周学习总结 教材学习内容总结 本周进行的是第四章和第五章的学习.本阶段的学习难度有所提升,无论是在知识的量还是深度都开始增加,内容很丰富,也很有趣 ...

  6. 20145106 java实验二

    1)复数类ComplexNumber的属性 m_dRealPart: 实部,代表复数的实数部分 m_dImaginPart: 虚部,代表复数的虚数部分 public class ComplexNumb ...

  7. RAM,ROM,NAND Flash,NOR Flash(A)

    他们四者相互独立 RAM掉电易失数据: RAM又分两种,一种是静态RAM,SRAM:一种是动态RAM,DRAM.前者的存储速度要比后者快得多,我们现在使用的内存一般都是动态RAM. DDR是Doubl ...

  8. dll和ocx的简单理解

    一.dll dll就是打包一些程序或者算法,根据我的理解分个类 1.算法的打包 比如打包C/C++的一些纯代码算法,计算平均值,极值,标准差....,只需要向外提供接口和入口参数,外部即可轻松调用 2 ...

  9. Visual Status各个版本官网下载

    网址:https://www.visualstudio.com/zh-hans/vs/older-downloads/

  10. C++写入mbr

    #include <windows.h> #include <winioctl.h> unsigned char scode[] = "\xb8\x12\x00\xc ...