2017 多校2 hdu 6053 TrickGCD】的更多相关文章

2017 多校2 hdu 6053 TrickGCD 题目: You are given an array \(A\) , and Zhu wants to know there are how many different array \(B\) satisfy the following conditions? \(1≤B_i≤A_i\) For each pair(\(l , r) (1≤l≤r≤n) , gcd(bl,bl+1...br)≥2\) Input The first line…
/* HDU 6053 - TrickGCD [ 莫比乌斯函数,筛法分块 ] | 2017 Multi-University Training Contest 2 题意: 给出数列 A[N],问满足: 1 <= B[i] <= A[i] ; 对任意(l, r) (1<=l<=r<=n) ,使得 gcd(bl,...br) >= 2 ; 的 B[N] 数列的个数 分析: 设 gcd(b1,...bn) = k (k >= 2),此时 k 对答案的贡献为 (a1/k)…
2017 多校3 hdu 6061 RXD and functions(FFT) 题意: 给一个函数\(f(x)=\sum_{i=0}^{n}c_i \cdot x^{i}\) 求\(g(x) = f(x - \sum a_i)\)后每一项\(x^{i}\)的系数mod998244353 \(n <= 10^{5},m <= 10^{5}\) \(0 <= c_i < 998244353\) \(0 <= a_i < 998244353\) 思路: 令\(d = -\s…
题意:给出n个数$a[i]$,每个数可以变成不大于它的数,现问所有数的gcd大于1的方案数.其中$(n,a[i]<=1e5)$ 思路:鉴于a[i]不大,可以想到枚举gcd的值.考虑一个$gcd(a_1,a_2,a_3…a_n)=d$,显然每个$a_i$的倍数都满足,有$\frac{a_i}{d}$种方案 那么一个d对答案的贡献为\[\prod_{i=1}^{min(a)}{\lfloor\frac{a_i}{d}\rfloor}    \] 但是所有的d计入会有重复情况,考虑容斥,对d进行素数分…
2017 多校5 Rikka with Number(数学 + 数位dp) 题意: 统计\([L,R]\)内 有多少数字 满足在某个\(d(d>=2)\)进制下是\(d\)的全排列的 \(1 <= L <= R <= 10^{5000}\) 题解: 首先转化成计算小于等于 \(N\)的好数有多少个.因为 \(n^n<(n+1)^n\) ​ ​​而对于 \(n\) 进制下的任何一个好数 \(K\),都有 \(n^{n-1}<K<n^n ​\) ​​ ​​ ,所以每一…
题目链接 定义f[n]表示n是最大公约数情况下的计数,F[n]为n是公约数情况下的计数 (可以和 http://www.cnblogs.com/Just--Do--It/p/7197788.html hdu1695 进行类比) 显然F[n]和f[n]是满足下面这个关系的 所以,可以用下面这个公式求解f[n] 得到下面的AC代码 #include<bits/stdc++.h> using namespace std; typedef long long LL; #define max(a,b)…
TrickGCD Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 2097    Accepted Submission(s): 816 Sample Input 1 4 4 4 4 4 Sample Output Case #1: 17   Source 2017 Multi-University Training Contest…
TrickGCD Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 2523    Accepted Submission(s): 965 Problem Description You are given an array A , and Zhu wants to know there are how many different a…
TrickGCD Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Problem Description You are given an array A , and Zhu wants to know there are how many different array B satisfy the following conditions? * 1≤Bi≤Ai* For…
http://acm.hdu.edu.cn/showproblem.php?pid=6053 题意:给出一个A数组,B数组满足Bi<=Ai. 现在要使得这个B数组的GCD值>=2,求共有多少种情况. 思路:在比赛的时候筛了素数表,然后枚举GCD来做,但是还是有些重复情况无办法剔除,赛后才知道是要用莫比乌斯来处理的,然后就趁机学习了一下莫比乌斯. 先是枚举GCD,每个数的可选情况就是GCD/a[i],在这里我们可以把GCD/a[i]相同的数一起处理,也就是用快速幂来计算,这样会显得更快. 那么莫…
TrickGCD Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 2649    Accepted Submission(s): 1007 Problem Description You are given an array A , and Zhu wants to know there are how many different…
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=6053 [题目大意] 给出一个数列每个位置可以取到的最大值, 问这个可以构造多少个数列,使得他们的最大公约数大于1 [题解] 我们可以枚举最大公约数k,对于k来说, 他对答案的贡献为∏[ai/k],我们将数列中的数字转化为权值数组 ∏_{i=1}^{100000}[i/k],对于求解i/k的部分我们可以进行数值分块, j*k-1~j*k+k-1的数值除k得到的结果都是相同的,因此可以直接求这个结果…
TrickGCD Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 3401    Accepted Submission(s): 1268 Problem Description You are given an array A , and Zhu wants to know there are how many different…
题意:给一个序列A,要求构造序列B,使得 Bi <= Ai, gcd(Bi) > 1, 1 <= i <= n, 输出构造的方法数. 析:首先这个题直接暴力是不可能解决的,可以先找出最大值mmax和最小值mmin,然后枚举每个gcd,也就是最大公约数d,那么其他数就应该是d 2*d 3*d 4*d ....如果把每个数的个数求出来.那么答案就是每一种 d 的数量的和,每一种的数量就是 a1 * a2 * a3 ... an,其中是 ai 是 第 i 个数所能取到 d 的数量. 这样…
// 判断相同区间(lazy) 多校8 HDU 5828 Rikka with Sequence // 题意:三种操作,1增加值,2开根,3求和 // 思路:这题与HDU 4027 和HDU 5634 差不多 // 注意开根号的话,遇到极差等于1的,开根号以后有可能还是差1.如 // 2 3 2 3... // 8 9 8 9... // 2 3 2 3... // 8 9 8 9... // 剩下就是遇到区间相等的话,就直接开根号不往下传 #include <bits/stdc++.h> u…
2017 多校5 Rikka with String(ac自动机+dp) 题意: Yuta has \(n\) \(01\) strings \(s_i\), and he wants to know the number of \(01\) antisymmetric strings of length \(2L\) which contain all given strings \(s_i\) as continuous substrings. A \(01\) string \(s\) i…
2017 多校4 Wavel Sequence 题意: Formally, he defines a sequence \(a_1,a_2,...,a_n\) as ''wavel'' if and only if \(a_1<a_2>a_3<a_4>a_5<a_6\)... Now given two sequences \(a_1,a_2,...,a_n\) and \(b_1,b_2,...,b_m\), Little Q wants to find two seque…
2017 多校4 Security Check 题意: 有\(A_i\)和\(B_i\)两个长度为\(n\)的队列过安检,当\(|A_i-B_j|>K\)的时候, \(A_i和B_j\)是可以同时过安检的,过安检必须按照队列的顺序,问你两个队列过完安检最少花费的时间 \(1<=n<=6e4\), \(1<=A_i,B_i<=n\) 题解: 设\(f_{i,j}\) 表示仅考虑\(a[1..i]\)与\(b[1..j]\)时,最少需要多少时间. 若\(|a_i-b_j|>…
2017 多校2 I Curse Myself(第k小生成树) 题目: 给一张带权无向连通图,该图的任意一条边最多只会经过一个简单环,定义\(V(k)为第k小生成树的权值和\),求出\(\sum_{k=1}^{K}k \cdot V(k) mod 2^{32}\) 思路: 比赛的时候看了一眼,没有看清楚是仙人掌那句话,觉得好难啊 看完题解之后觉得就算看清了还是过不了嘛. 直接上题解 由于图是一个仙人掌,所以显然对于图上的每一个环都需要从环上取出一条边删掉.所以问题就变为有 M 个集合,每个集合里…
有点麻烦.. /*hdu6136[模拟+优先队列] 2017多校8*/ #include <bits/stdc++.h> using namespace std; typedef long long LL; struct frac { LL p, q; frac(LL P, LL Q) { p = P / __gcd(P, Q); q = Q / __gcd(P, Q); } frac() {p = , q = ;} bool operator < (const frac& a)…
/*hdu6134[莫比乌斯反演] 2017多校8*/ #include <bits/stdc++.h> using namespace std; typedef long long LL; ; + ; LL f[maxn], g[maxn], d[maxn]; bool vis[maxn]; int prime[maxn], primes, mu[maxn]; void init_mu() { memset(vis, , sizeof(vis)); mu[] = ; primes = ; ;…
/*hdu6098[RMQ+筛法] 2017多校6*/ #include <bits/stdc++.h> using namespace std; ][], len[], a[]; void st_init() { len[] = -; ; i <= n; i++) { st[i][] = a[i]; len[i] = (i & (i - )) == ? len[i - ] + : len[i - ]; } ; j <= len[n]; j++) { ; i + ( <…
/*hdu6103[尺取法] 2017多校6*/ #include <bits/stdc++.h> using namespace std; int T, m; ]; void solve() { ; int n = strlen(str); ; i < n; i++) { , r = , p1 = i, p2 = i + , cost = ; && p2 + r < n) { if (cost + abs(str[p1 - r] - str[p2 + r]) &l…
/*hdu6097[二分+解析几何] 2017多校6*/ #include <bits/stdc++.h> using namespace std; ; struct node{ double x,y; node(double X=0.0,double Y=0.0): x(X),y(Y){} }p,q; double dist(node a,node b){ return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)); } int T; doubl…
/*hdu6085[压位+暴力] 2017多校5*/ /*强行优化..*/ #include <bits/stdc++.h> using namespace std; struct bits{ unsigned num[]; unsigned bitlen; bits(){memset(num,,;} bits get(int l, int r) { bits ret; ; ; left=l/; len1=(l%); len2=-len1; ){ ) ret.num[pos++]=num[le…
/*hdu6038[找规律+循环节] 2017多校1*/ #include<bits/stdc++.h> using namespace std; typedef long long LL; ; const int inf=0x3f3f3f3f; ; ,maxlop; ],b[],mark[]; LL Arep[],Brep[]; LL fastpow(LL a,LL b){ LL ret=,x=a; while(b){ ){ ret=(ret*x)%mod; } x=(x*x)%mod; b…
/*hdu6035[dfs+思维] 2017多校1*/ //合并色块, 妙啊妙啊 #include<bits/stdc++.h> using namespace std; ; const int inf=0x3f3f3f3f; typedef long long LL; vector<]; LL sum[]; ],son[],mark[]; ,kase=; LL ans,res; void dfs(int u,int fa){ son[u]=; LL y=sum[c[u]]; LL x=…
/*hdu6034[模拟] 2017多校1*/ //暴力模拟26个26进制数即可, 要注意进位 #include<bits/stdc++.h> using namespace std; typedef long long LL; ; const int inf=0x3f3f3f3f; struct node{ ]; int ch,high; }bits[]; ; ],w[],kase=; ]; LL fastpow(LL a,LL b){ LL ret=,x=a; while(b){ ){ r…
看了标答感觉思路清晰了许多,用并查集来维护全联通块的点数和边权和. 用另一个up[]数组(也是并查集)来保证每条边不会被重复附权值,这样我们只要将询问按权值从小到大排序,一定能的到最小的边权和与联通块中的点数. 下面是过程分析.过程中一共运用了两个并查集. [数据]110 31 21 32 42 53 63 74 85 95 109 6 3 1 501 4 2 5 209 10 8 10 40[分析]首先我们将图构建出来我们将m次询问按权值从小到大排序后: 1 4 2 5 209 10 8 10…
这道题一眼看过去好像和最长公共子序列有点像. 一开始只想到暴力的推法, 令dp[i][j][k]表示 a[i]=b[j](即以ai,bj为结尾的波浪序列的方案数), 且最终状态为k(0,1分别代表下降与上升)的方案数. 所以我们可能需要优化一下,用一个sum[i][j][k]表示枚举到ai时,能构成以bj为结尾且末状态为k的方案和,可以减少对 j 这一维的枚举. 比如我们在枚举ai+1时,在遍历b中元素时,如果遇到比ai+1大的,那么就加上sum[i][j][1],若遇到比ai+1小的,就加上s…