codeforces 475D. CGCDSSQ】的更多相关文章

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\)…
题目链接: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…
题面: 传送门:http://codeforces.com/problemset/problem/475/D 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, al + 1, -, ar) = xi. 题目大意:…
题意:给定n(n<=100000)个1e9以内的数的数组a,然后最多有3*1e5的询问,对于每个询问,给定一个x,问有多少个(l<=r&&gcd(a[l],a[l+1]...a[r]) == x) 思路:昨天的比赛题..可惜我被c题wa到放弃了这场比赛..也就没看了..不妨设G(l,r) = gcd(a[l], a[l+1]...a[r]); 其实题目最关键的的性质是对于G(l,r),G(l,r+1)后者肯定比前者更小.. 所以就可以暴力了..从后往前扫描i,处理(i, n)这…
D. CGCDSSQ time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output 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…
题目说了a的范围小于10^9次方,可实际却有超过的数据...真是醉了 算出以f[i]结尾的所有可能GCD值,并统计: f[i]可以由f[i-1]得出. /* 递推算出所有GCD值,map统计 */ #include <iostream> #include <vector> #include <map> using namespace std; #define ll long long ; int n, m; ll x; map<ll , ll > sum,…
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题.. 今天,我们来扒一下cf的题面! PS:本代码不是我原创 1. 必要的分析 1.1 页面的获取 一般情况CF的每一个 contest 是这样的: 对应的URL是:http://codeforces.com/contest/xxx 还有一个Complete problemset页面,它是这样的:…