还是想不到,真的觉得难,思路太巧妙 题意:给你一串数和一些区间,对于每个区间求出区间内每段连续值的不同gcd个数(该区间任一点可做起点,此点及之后的点都可做终点) 首先我们可以知道每次添加一个值时gcd要么不变要么减小,并且减小的幅度很大,就是说固定右端点时最多只能有(log2 a)个不同的gcd,而且我们知道gcd(gcd(a,b),c)=gcd(a,gcd(b,c)),所以我们可以使用n*(log2 n)的时间预处理出每个固定右端点的不同gcd的值和位置.解法就是从左到右,每次只需要使用上一…
query \[ Time Limit: 2000 ms \quad Memory Limit: 262144 kB \] 题意 补题才发现比赛的时候读了一个假题意.... 给出长度为 \(n\) 的排列,在给出 \(m\) 次询问,每次询问有一对 \(l.r\),问满足 \(min(ai, aj) = gcd(ai, aj)\) 的 \(pair(i, j)\) 对数. 思路 考虑离线做 先把每个数出现的位置记录下来,然后预处理出所有的 \(pair\). 对于一个数字 \(x\),其满足条件…
题目链接: 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…
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,…
题目链接: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_…
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]…
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…
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…
离线操作,树状数组,$RMQ$. 这个题的本质和$HDU$ $3333$是一样的,$HDU$ $3333$要求计算区间内不同的数字有几个. 这题稍微变了一下,相当于原来扫描到$i$的之后是更新$a[i]$的情况,现在是更新$log$级别个数的数字(因为以$i$为结尾的区间,最多只有$log$级别种不同的$gcd$). 求区间$gcd$可以用$RMQ$预处理一下,然后就可以$O(1)$查询了. #pragma comment(linker, "/STACK:1024000000,102400000…
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…
树状数组... Different GCD Subarray Query Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1541    Accepted Submission(s): 599 Problem Description This is a simple problem. The teacher gives Bob a lis…
Different GCD Subarray Query Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Description This is a simple problem. The teacher gives Bob a list of problems about GCD (Greatest Common Divisor). After studyin…
Weak Pair Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 1468    Accepted Submission(s): 472 Problem Description You are given a rooted tree of N nodes, labeled from 1 to N. To the ith node…
Weak Pair Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Problem Description You are given a rooted tree of N nodes, labeled from 1 to N. To the ith node a non-negative value ai is assigned.An ordered pair of no…
A Simple Problem with Integers Time Limit: 5000/1500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4000    Accepted Submission(s): 1243 Problem Description Let A1, A2, ... , AN be N elements. You need to deal with…
Group Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 17    Accepted Submission(s): 5 Problem Description There are n men ,every man has an ID(1..n).their ID is unique. Whose ID is i and i-1 are…
题意: N个点形成一棵树.给出根结点P还有树结构的信息. 输出每个点的F[i].F[i]:以i为根的所有子结点中编号比i小的数的个数. 0<n<=10^5 思路: 方法一:直接DFS,进入结点x时记录一下比x小的数的个数.出来x时记录一下比x小的数的个数.相减就是F[x].结合树状数组. 方法二:写下DFS序.对DFS序列建线段树.然后从小到大对结点进行插入.用线段树统计. 代码:(方法一) int const N=1e5+5; int n,p; vector<int> G[N];…
Function Time Limit: 7000/3500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Problem Description The shorter, the simpler. With this problem, you should be convinced of this truth.    You are given an array A of N postive integers,…
Football Games Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Description A mysterious country will hold a football world championships---Abnormal Cup, attracting football teams and fans from all around th…
Sparse Graph Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Problem Description In graph theory, the complement of a graph G is a graph H on the same vertices such that two distinct vertices of H are adjacent if…
Function Time Limit: 7000/3500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 1498    Accepted Submission(s): 553 Problem Description The shorter, the simpler. With this problem, you should be convinced of this t…
bobo has a tree, whose vertices are conveniently labeled by 1,2,…,n. At the very begining, the i-th vertex is assigned with weight w i. There are q operations. Each operations are of the following 2 types: Change the weight of vertex v into x (denote…
分析:(别人写的) 对于所有(l, r)区间,固定右区间,所有(li, r)一共最多只会有log个不同的gcd值, 可以nlogn预处理出所有不同的gcd区间,这样区间是nlogn个,然后对于询问离线处理, 用类似询问区间不同数字的方法,记录每个不同gcd最后出现的位置,然后用树状数组进行维护 注:我是看了这段文字会的,但是他的nlogn预处理我不会,我会nlog^2n的 dp[i][j]代表以i为右端点,向左延伸2^j个点(包括i)的gcd,然后因为这样的gcd满足递减,所以可以二分找区间 代…
题目链接 http://acm.split.hdu.edu.cn/showproblem.php?pid=5869 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.…
Different GCD Subarray Query Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 221    Accepted Submission(s): 58 Problem Description This is a simple problem. The teacher gives Bob a list of probl…
Different GCD Subarray Query Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1328    Accepted Submission(s): 504 Problem Description This is a simple problem. The teacher gives Bob a list of pro…
题目大意:长度n的序列, m个询问区间[L, R], 问区间内的所有子段的不同GCD值有多少种. 子段就是表示是要连续的a[] 思路:固定右端点,预处理出所有的gcd,每次都和i-1的gcd比较,然后不断放入gcd即可. 然后就是树状数组的更新,枚举右端点即可.然后我们知道,大区间不如小区间来的实惠,所以我们每次有重复gcd出现的时候,都要把大区间更换成小区间即可 下午脑子有点不清楚...2333看别人的博客蒙了好久 //看看会不会爆int!数组会不会少了一维! //取物问题一定要小心先手胜利的…
Problem Different GCD Subarray Query 题目大意 给定n个数的序列,有q个询问,每次询问一个区间中所有子区间所形成不同的gcd的数量. 解题分析 由于固定一个数为右端点,所能形成的gcd共有logn,所以可以预处理出每个数为右端点所能形成的gcd,相同gcd取左端点靠右的. 然后将询问离线,按照r从小到大排序.处理gcd重复的方法是将相同的gcd值保留左端点较大的. 参考程序 #include <map> #include <set> #inclu…
GCD Array Time Limit: 11000/5500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 843    Accepted Submission(s): 205 Problem Description Teacher Mai finds that many problems about arithmetic function can be reduced to…
题目链接  2016 青岛网络赛  Problem C 题意  给出一些敏感词,和一篇文章.现在要屏蔽这篇文章中所有出现过的敏感词,屏蔽掉的用$'*'$表示. 建立$AC$自动机,查询的时候沿着$fail$指针往下走,当匹配成功的时候更新$f[i]$ $f[i]$表示要屏蔽以第$i$个字母结尾的长度为$f[i]$的字符串. #include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i(a); i &l…