E. Mike and Foam(容斥原理)】的更多相关文章

http://codeforces.com/problemset/problem/548/E 这题是询问id,如果这个id不在,就插入这个id,然后求a[id1] ,  a[id2]互质的对数. 询问有多少个互质这个套路出了很多次,这次是在线 首先维护当前的ans,可以知道每一步的ans,都是由于上一步的ans递推过来的.就是小答案可以由大答案推过来. 就是现在数组是a[] = 1, 2, 3,维护一个ans表示有多少对gcd等于1,然后添加一个4,只需要询问4在a[] = {1, 2, 3}中…
hdu4135 求[L,R]范围内与N互质的数的个数. 分别求[1,L]和[1,R]和n互质的个数,求差. 利用容斥原理求解. 二进制枚举每一种质数的组合,奇加偶减. #include <bits/stdc++.h> using namespace std; typedef long long ll; ; int fac[N], cnt; void factor(int n) { cnt = ; int limit = sqrt(n); ; i <= limit; ++i) { ) fa…
E. Mike and Foam Mike is a bartender at Rico's bar. At Rico's, they put beer glasses in a special shelf. There are n kinds of beer at Rico's numbered from 1 to n. i-th kind of beer has ai milliliters of foam on it. Maxim is Mike's boss. Today he told…
目录 Codeforces 547C/548E - Mike and Foam 题解 前置芝士 - 容斥原理 题意 想法(口胡) 做法 程序 感谢 Codeforces 547C/548E - Mike and Foam 题解 前置芝士 - 容斥原理 容斥原理是简单的小学奥数求多个集合的并集的算法,最基本的思想大概是如下内容: 这是一道简单例题:有\(10\)个学生喜欢唱歌,有\(15\)个学生喜欢跳舞,有\(5\)个学生两种活动都喜欢,没有不喜欢前述两种活动的学生,那么一共有多少个学生呢? 相…
C. Mike and Foam time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Mike is a bartender at Rico's bar. At Rico's, they put beer glasses in a special shelf. There are n kinds of beer at Rico's…
Mike is a bartender at Rico's bar. At Rico's, they put beer glasses in a special shelf. There are n kinds of beer at Rico's numbered from 1to n. i-th kind of beer has ai milliliters of foam on it. Maxim is Mike's boss. Today he told Mike to perform q…
题面 链接:CF548E Description Mike is a bartender at Rico's bar. At Rico's, they put beer glasses in a special shelf. There are n kinds of beer at Rico's numbered from 1 to n. i-th kind of beer has *a**i* milliliters of foam on it. Maxim is Mike's boss. T…
English reading: bartender == barmaid:酒吧女招待 milliliter:毫升:千分之一毫升 foam:泡沫 a glass of beer with a good head of foam:上面有厚厚一层泡沫的一杯啤酒 the greenness of the countryside:乡村的青葱翠绿 geek 题目:https://vjudge.net/contest/238720#problem/A 解析:http://codeforces.com/blo…
首先我们注意到ai<=50w 因为2*3*5*7*11*13*17=510510 所以其最多含有6个质因子 我们将每个数的贡献分离, 添加就等于加上了跟这个数相关的互素对 删除就等于减去了跟这个数相关的互素对 问题转化为了求跟某个数相关的互素对的数目 我们可以用容斥来解决 即加上至少跟这个数有0个公共质因子的数 减去至少跟这个数有1个公共质因子的数 加上至少跟这个数又2个公共质因子的数…… 这样我们就可以在2^6的时间算出答案了 #include<cstdio> #include<…
题意:给出数组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的质因数])(即…