http://acm.hdu.edu.cn/showproblem.php?pid=5869 题意:给定一个数组,然后给出若干个询问,询问[L, R]中,有多少个子数组的gcd是不同的. 就是[L, R]中不同区间的gcd值,有多少个是不同的. 给个样例 3 37 7 71 21 33 3 数学背景: 一个数字和若N个数字不断GCD,其结果只有loga[i]种,为什么呢?因为可以把a[i]质因数分解,其数目最多是loga[i]个数字相乘.(最小的数字是2,那么loga[i]个2相乘也爆了a[i]…
Problem Description This is a simple problem. The teacher gives Bob a list of problems about GCD (Greatest Common Divisor). After studying some of them, Bob thinks that GCD is so interesting. One day, he comes up with a new problem about GCD. Easy as…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5869 Different GCD Subarray Query Time Limit: 6000/3000 MS (Java/Others)Memory Limit: 65536/65536 K (Java/Others) 问题描述 This is a simple problem. The teacher gives Bob a list of problems about GCD (Great…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5869 问你l~r之间的连续序列的gcd种类. 首先固定右端点,预处理gcd不同尽量靠右的位置(此时gcd种类不超过loga[i]种). 预处理gcd如下代码,感觉真的有点巧妙... ; i <= n; ++i) { int x = a[i], y = i; ; j < ans[i - ].size(); ++j) { ][j].first); if(gcd != x) { ans[i].push_…
Different GCD Subarray Query Problem Description   This is a simple problem. The teacher gives Bob a list of problems about GCD (Greatest Common Divisor). After studying some of them, Bob thinks that GCD is so interesting. One day, he comes up with a…
还是想不到,真的觉得难,思路太巧妙 题意:给你一串数和一些区间,对于每个区间求出区间内每段连续值的不同gcd个数(该区间任一点可做起点,此点及之后的点都可做终点) 首先我们可以知道每次添加一个值时gcd要么不变要么减小,并且减小的幅度很大,就是说固定右端点时最多只能有(log2 a)个不同的gcd,而且我们知道gcd(gcd(a,b),c)=gcd(a,gcd(b,c)),所以我们可以使用n*(log2 n)的时间预处理出每个固定右端点的不同gcd的值和位置.解法就是从左到右,每次只需要使用上一…
离线操作,树状数组,$RMQ$. 这个题的本质和$HDU$ $3333$是一样的,$HDU$ $3333$要求计算区间内不同的数字有几个. 这题稍微变了一下,相当于原来扫描到$i$的之后是更新$a[i]$的情况,现在是更新$log$级别个数的数字(因为以$i$为结尾的区间,最多只有$log$级别种不同的$gcd$). 求区间$gcd$可以用$RMQ$预处理一下,然后就可以$O(1)$查询了. #pragma comment(linker, "/STACK:1024000000,102400000…
Different GCD Subarray Query Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 828    Accepted Submission(s): 300 Problem Description  and aN. In other words, ai,ai+1,⋯,aj−1,aj is a subarray of a,…
Problem Description This is a simple problem. The teacher gives Bob a list of problems about GCD (Greatest Common Divisor). After studying some of them, Bob thinks that GCD is so interesting. One day, he comes up with a new problem about GCD. Easy as…
hdu 6203 ping ping ping(LCA+树状数组) 题意:给一棵树,有m条路径,问至少删除多少个点使得这些路径都不连通 \(1 <= n <= 1e4\) \(1 <= m <= 5e4\) 思路: 根据路径的LCA深度从大到小排序,每次选择一个没被删除的LCA删除 当某个点删除时,跨越了以这个点为根的子树的路径都会被割断,而排序保证在同一子树内部的路径已经被处理过了,子树信息可以用dfs序来表示,区间操作可以用左右端点打标记,用树状数组维护即可. #include…