codeforces Upgrading Array】的更多相关文章

思路:对于每个数分解质因子然后记录每一个质因子的个数,对与在b中出现的质因子就减去1,否则加1,求出总的,然后从后面一次对它们的最大公约数,然后判断除以最大公约数之后,改变量是不是变化,求最大值,变化量为负值的话减去. #include <cstdio> #include <cstring> #include <map> #include <set> #include <algorithm> using namespace std; set<…
http://codeforces.com/contest/494/problem/D 题意:给一个数组,和一个坏质数集合,可以无数次地让1到i这些所有数字除以他们的gcd,然后要求Σf(a[i])的最大值,其中 f(x)=f(x/p)+1,p为x的最小质数,且p不为坏质数 f(x/p)-1 ,p为x的最小质数,且p为坏质数 思路:我们考虑,如果f[j]取了1到j的gcd,那么对后面的决策并没有任何影响,因为我们统计的贡献,只统计1到i这个部分,不统计i以后的部分. 略坑,不知道第一次被什么卡了…
题目链接:http://codeforces.com/problemset/problem/402/D 题意: 给你一个长度为n的数列a[i],又给出了m个“坏质数”b[i]. 定义函数f(s),其中p是s的最小质因子: f(1) = 0 f(s) = f(s/p) + 1 (p不是坏质数) f(s) = f(s/p) - 1 (p是坏质数) 你可以任意次数地进行操作:给a[1 to i]的每个数都除以gcd(a[1 to i]). 问你 ∑ f(a[i)最大为多少. 题解: 函数f(s)的实际…
题目链接:http://codeforces.com/contest/402/problem/D 题意:给出一个a串和素数串b .f(1) = 0; p为s的最小素因子如果p不属于b , 否则 . a串还可以进行这样的操作找一个r使得(1<=r<=n)g=gcd(a[1],a[2]......a[r]),然后再是a[1~r]/g. 题解:其实f的求和可以理解为num1(好的素因子)-num2(不好的素因子). 然后就是对a操作的理解,a怎么样才需要进行这样的操作呢?只要g中不好的素因子大于好的…
题意:给出一个数列,可以进行一种操作将某一个前缀除去他们的gcd,有一个函数f(x),f(1) = 0 , f(x) = f(x/p)+1,f(x) = f(x/p)-1(p是坏素数), 求 sum(f[a[i]]) 的最大值. 析:因为f(1) = 0,否则如果是好素数,那么就加一,如果是坏素数就减一,很明显每个数 f(a[i]) 的值就是好素数的数目,送去坏素数的数目, 然后求总的和,这样可以预处理出所有的 gcd,好素数的个数,坏素数的个数,然后dp[i] 表示 sum(f(a[i]))…
E. Array Queries 题目链接:http://codeforces.com/problemset/problem/797/E time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output a is an array of n positive integers, all of which are not greater than…
Codeforces 1108E2 E2. Array and Segments (Hard version) Description: The only difference between easy and hard versions is a number of elements in the array. You are given an array \(a\) consisting of \(n\) integers. The value of the \(i\)-th element…
http://codeforces.com/problemset/problem/300/A 题意 :给你n个数字,让你分成3组,第一组各个数之积要小于0,第二组要大于0,第三组要等于0,符合要求的答案可能会有很多种,输出其中一种. 思路 :表示一开始以为要把n个数分成3组,第一组里的数都大于0这样子,所以一直卡在这儿....因为这个题也相当于special judge了吧,所以要找一个最不容易出错的输出,把n个数排序,最小的肯定是负的(题目保证至少有一个正确答案),所以直接把它分在第一组就行,…
题目链接:http://codeforces.com/problemset/problem/402/D /**算法分析: */ #include<bits/stdc++.h> #define MAXN 5005 #define MAXM 110000 #define PI acos(-1.0) #define REP(i,n) for(int i=0; i<n; i++) #define FOR(i,s,t) for(int i=s; i<=t; i++) #define mem(…
You have written on a piece of paper an array of n positive integers a[1], a[2], ..., a[n] and m good pairs of integers (i1, j1), (i2, j2), ..., (im, jm). Each good pair (ik, jk) meets the following conditions: ik + jk is an odd number and 1 ≤ ik < j…