[CF 475D] CGCDSSQ (RMQ)】的更多相关文章

题目链接:http://codeforces.com/contest/475/problem/D 是昨天晚上的CF题目,题意是给定你n个数,问你所有子区间内的最小公约数是x的个数是多少 问的康神,了解了ST表. 其实我也没太明白,看了看博文觉得还是不错的:http://hplonline20100103.blog.163.com/blog/static/1361364342010040044244/ 然后就是logn去扫了 代码: #include <bits/stdc++.h> using…
D. CGCDSSQ time limit per test 2 seconds memory limit per test 256 megabytes Given a sequence of integers a1, ..., an and q queries x1, ..., xq on it. For each query xi you have to count the number of pairs (l, r)such that 1 ≤ l ≤ r ≤ n and gcd(al, a…
题意:给你一个序列a[i],对于每个询问xi,求出有多少个(l,r)对使得gcd(al,al+1...ar)=xi. 表面上是询问,其实只要处理出每个可能的gcd有多少个就好了,当左端点固定的时候,随着右端点的移动,gcd必然是单调非增的,而且个数不会超过log(a[i])个,所以总的不同的个数的上界是nlog(ai),所以求出所有是可行的. 一个分治的做法是这样的,对于一个区间[l,r],分治成[l,mid],[mid+1,r]求解,然后就是合并,合并的时候首先求以[l,mid]右端点为结束点…
题目链接:点击打开链接 #include <cstdio> #include <cstring> #include <algorithm> #include <vector> #include <iostream> #include <cmath> using namespace std; typedef long long ll; template <class T> inline bool rd(T &ret)…
题目链接 题意 给定一个长度为 \(n\) 的数列 \(a_1,...,a_n\) 与 \(q\) 个询问 \(x_1,...,x_q\),对于每个 \(x_i\) 回答有多少对 \((l,r)\) 满足\(\ (1\leq l\leq r\leq n)\) 且 \(gcd(a_l,a_{l+1},...,a_r)=x_i\) 思路 对于固定的右端点 \(i\),将左端点从右 (\(i\)) 向左 (\(1\)) 延伸,\(gcd\) 值是递减的,且变化次数不超过 \(logC\) (\(C\)…
参考: 1. 郭华阳 - 算法合集之<RMQ与LCA问题>. 讲得很清楚! 2. http://www.cnblogs.com/lazycal/archive/2012/08/11/2633486.html 3. 代码来源yejinru 题意: 有一棵树, 按照顺序给出每条边, 再给出若干对点, 这两点之间的唯一的路( Simple path )上边权加1. 当所有对点处理完后, 按照边的输入顺序输出每条边的权. 思路: LCA问题. 最近公共祖先(Least Common Ancestors…
Description You are given circular array a0, a1, ..., an - 1. There are two types of operations with it: inc(lf, rg, v) - this operation increases each element on the segment [lf, rg] (inclusively) by v; rmq(lf, rg) - this operation returns minimal v…
3473: 字符串 Description 给定n个字符串,询问每个字符串有多少子串(不包括空串)是所有n个字符串中至少k个字符串的子串? Input 第一行两个整数n,k. 接下来n行每行一个字符串. Output 一行n个整数,第i个整数表示第i个字符串的答案. Sample Input 3 1 abc a ab Sample Output 6 1 3 HINT 对于 100% 的数据,1<=n,k<=10^5,所有字符串总长不超过10^5,字符串只包含小写字母. [分析] 这道题用后缀数…
CF原题(http://codeforces.com/blog/entry/4849, 204E), CF的解法是O(Nlog^2N)的..记某个字符串以第i位开头的字符串对答案的贡献f(i), 那么f(i-1)>=f(i)-1, 然后就是O(NlogN)了, 但是速度垫底了....被后缀自动机完爆了... ----------------------------------------------------------------------------------------------…
之前挂上的 今天填坑 2018.2.14 #462 A 给两个集合,B分别可以从一个集合中选一个数,B想乘积最大,A想最小,A可以删除一个第一个集合中的元素,问最小能达到多少. 这题..水死啦.我居然还wa了一发,因为ans初值定的0.....我真是傻. n3暴力就行 #include<bits/stdc++.h> using namespace std; #define ll long long #define inf 1000000000000000001ll int n,m; ll a[…