题目说了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
const int MAXN = ;
int n, m;
ll x;
map<ll , ll > sum, record[];
map<ll, ll>::iterator it;
ll gcd (ll a, ll b) {
return b == ? a : gcd (b, a % b);
}
int main() {
ios::sync_with_stdio ();
cin >> n;
int roll = ;
for (int i = ; i <= n; i++, roll ^= ) {
cin >> x;
record[roll].clear();
record[roll][x]++, sum[x]++;
for (it = record[roll ^ ].begin(); it != record[roll ^ ].end(); ++it) {
ll tem = gcd (x, (*it).first);
sum[tem] += (*it).second;
record[roll][tem] += (*it).second;
}
}
cin >> m;
for (int i = ; i <= m; i++) {
cin >> x;
cout << sum[x] << endl;
}
}

Codeforces 475 D.CGCDSSQ的更多相关文章

  1. 【CODEFORCES】 D. CGCDSSQ

    D. CGCDSSQ time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...

  2. Codeforces 475 B Strongly Connected City【DFS】

    题意:给出n行m列的十字路口,<代表从东向西,>从西向东,v从北向南,^从南向北,问在任意一个十字路口是否都能走到其他任意的十字路口 四个方向搜,搜完之后,判断每个点能够访问的点的数目是否 ...

  3. codeforces 475D. CGCDSSQ

    D. CGCDSSQ time limit per test 2 seconds memory limit per test 256 megabytes Given a sequence of int ...

  4. [codeforces round#475 div2 ][C Alternating Sum ]

    http://codeforces.com/contest/964/problem/C 题目大意:给出一个等比序列求和并且mod 1e9+9. 题目分析:等比数列的前n项和公式通过等公比错位相减法可以 ...

  5. Tinkoff Internship Warmup Round 2018 and Codeforces Round #475 (Div. 1) 963B 964D B Destruction of a Tree

    题 OvO http://codeforces.com/contest/963/problem/B CF 963B 964D 解 对于题目要求,显然一开始的树,要求度数为偶数的节点个数为奇数个,通过奇 ...

  6. Codeforces 475D CGCDSSQ(分治)

    题意:给你一个序列a[i],对于每个询问xi,求出有多少个(l,r)对使得gcd(al,al+1...ar)=xi. 表面上是询问,其实只要处理出每个可能的gcd有多少个就好了,当左端点固定的时候,随 ...

  7. Codeforces 475D CGCDSSQ 求序列中连续数字的GCD=K的对数

    题目链接:点击打开链接 #include <cstdio> #include <cstring> #include <algorithm> #include < ...

  8. Codeforces Round #475 Div. 1

    B:当n是偶数时无解,因为此时树中有奇数条边,而我们每次都只能删除偶数条.当n是奇数时一定有解,因为此时不可能所有点度数都为奇数,只要找到一个度数为偶数的点,满足将它删掉后,各连通块大小都为奇数就可以 ...

  9. Tinkoff Internship Warmup Round 2018 and Codeforces Round #475 (Div. 1)D. Frequency of String

    题意:有一个串s,n个串模式串t,问s的子串中长度最小的包含t k次的长度是多少 题解:把所有t建ac自动机,把s在ac自动机上匹配.保存每个模式串在s中出现的位置.这里由于t两两不同最多只有xsqr ...

随机推荐

  1. decodeURIComponent

    var s = '%%' try { s = decodeURIComponent(s) } catch(e) { console.log(e) } console.log(s)

  2. Unity 的“Vertex Lit Rendering path“中 shader Pass 的注意事项

    "MADFINGER/Environment/Unlit (Supports Lightmap)"是 ShadowGun 示例中最简单的 shader 了,如下: // Unlit ...

  3. HDOJ 2010 水仙花数

    Problem Description 春天是鲜花的季节,水仙花就是其中最迷人的代表,数学上有个水仙花数,他是这样定义的: "水仙花数"是指一个三位数,它的各位数字的立方和等于其本 ...

  4. awk替换第几行第几列的值

    代码如下: awk '{if(2==NR){gsub(/.*/, 300, $5)}print}' list.txt 将文件list.txt的第2行第5列的值替换为300

  5. 杭州(含嘉兴,绍兴,金华,湖州,义乌)Uber优步司机奖励政策(1月25日~1月31日)

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...

  6. cf493A

    Description Vasya has started watching football games. He has learned that for some fouls the player ...

  7. toString&&equals方法

    toString&&equals方法 先来看看这个题该怎样做? 分析: 1.java里的三大特性,有封装,继承,多态(方法的重载),super,this等关键字 2.常用的方法,equ ...

  8. Boa服务器在ARM+Linux上的移植

    下面给大家介绍一下Boa服务器移植的具体操作步骤,希望能够有帮助. 环境        主机:ubuntu8.10        交叉工具链:gcc-3.4.5-glibc-2.3.6         ...

  9. [置顶] JQuery插件学习教程

    这是JQuery其它常用插件的视频教程,包括validate插件,.comet插件等.同时有大量实例项目,如果你是喜欢JQuery的童鞋千万不要错过. 教程的内容有: 1_validate插件(1) ...

  10. [PWA] Enable Push Notification in your web app

    1. Clone the project: git clone https://github.com/GoogleChrome/push-notifications.git 2. install th ...