Codeforces 595B. Pasha and Phone 容斥】的更多相关文章

B. Pasha and Phone time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consis…
B. Pasha and Phone Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/595/problem/B Description Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of ex…
B. Pasha and Phone   Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits. Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a…
题目链接: http://codeforces.com/problemset/problem/451/E E. Devu and Flowers time limit per test4 secondsmemory limit per test256 megabytes 问题描述 Devu wants to decorate his garden with flowers. He has purchased n boxes, where the i-th box contains fi flow…
题目链接 \(Description\) 给定\(n\)个正整数\(a_i\).求有多少个子序列\(a_{i_1},a_{i_2},...,a_{i_k}\),满足\(a_{i_1},a_{i_2},...,a_{i_k}\) \(and\)起来为\(0\). \(n\leq10^6,\quad 0\leq a_i\leq10^6\). \(Solution\) 这个数据范围..考虑按位容斥: 令\(g_x\)表示\(x\)的二进制表示中\(1\)的个数,\(f_x\)表示有多少个\(a_i\)…
595B - Pasha and Phone 代码: #include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back ; const int INF=0x3f3f3f3f; ; ll a[N]; int b[N]; ]={}; int main() { ios::sync_with_stdio(false); cin.tie(); int n,k; cin>>n>&g…
大意: 给定集合a, 求a的按位与和等于0的非空子集数. 首先由容斥可以得到 $ans = \sum \limits_{0\le x <2^{20}} (-1)^{\alpha} f_x$, 其中$\alpha$为$x$二进制中$1$的个数, $f_x$表示与和等于$x$的非空子集数. $f_x$是一个$20$维前缀和, 按传统容斥做法的话显然要超时, 可以每次求一维的和, 再累加 比方说对于2维前缀和, 用容斥的求法是这样 for (int i=1; i<=n; ++i) { for (in…
Relatively Prime Powers CodeForces - 1036F Consider some positive integer xx. Its prime factorization will be of form x=2k1⋅3k2⋅5k3⋅-x=2k1⋅3k2⋅5k3⋅- Let's call xx elegant if the greatest common divisor of the sequence k1,k2,-k1,k2,- is equal to 11. F…
C. Joty and Chocolate time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Little Joty has got a task to do. She has a line of n tiles indexed from 1 to n. She has to paint them in a strange pat…
题目链接 \(Description\) 给定n个数(\(1\leq a_i\leq 5*10^5\)),每次从这n个数中选一个,如果当前集合中没有就加入集合,有就从集合中删去.每次操作后输出集合中互质的数对个数. \(Solution1\) 考虑暴力一点,对于要修改的数分解质因数,集合中与它互质的数的个数就是 n-(有1个公共质因数)+(有2个公共质因数)-... 维护一下每种因子(可以是多个因数的积)对应集合中的多少个数就行. 真的好暴力..但是一个数的质因子大多也就4.5个,so是没问题的…