题目说了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. PowerDesigner将PDM导出生成WORD文档--温习老知识

    转:http://www.cnblogs.com/wudiwushen/archive/2010/05/13/1734812.html 今天的温习老知识,是如何将一个PD设计的PDM来导出WORD文档 ...

  2. A configuration error occurred during startup. Please verify the preference field with the prompt: Cannot connect to vm

    1.报错图 解决方法: Window->Preferences->MyEclipse Enterprice Workbench->Servers->Tomcat->选择你 ...

  3. Render To Texel Baker

    今天仔细研究了 Shaowgun 示例中那个金黄色雕像所使用的光照纹理烘焙工具:“Render To Texel Baker”.因为要在移动设备展现比较逼真的光照效果,但是实时使用法线贴图并大量用于场 ...

  4. poj 3575 Crosses and Crosses(SG函数)

    Crosses and Crosses Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 3063   Accepted: 11 ...

  5. Div 3 - SGU 105(找规律)

    分析:很容易知道序列1,2,3, 4,5, 6......与3的关系就是1,2, 0,1, 2,0,......如果是在一个数后面添加一个数就变成了这种序列1, 0, 0, 1, 0, 0, 1, 0 ...

  6. hdoj 3342 Legal or Not【拓扑排序】

    Legal or Not Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  7. [转载]通过jQuery的attr修改onclick

    var js = "alert('B:' + this.id); return false;"; // creates a function from the "js&q ...

  8. c# 发送邮件、附件 分类: C# 2014-12-17 16:41 201人阅读 评论(0) 收藏

    WinForm窗体代码如下: <span style="font-size:14px;">using System; using System.Collections. ...

  9. 【Android - V】之DrawerLayout的使用

    DrawerLayout是Android V4包中的一个布局控件,用来实现一个抽屉样式的布局. DrawerLayout通过设置子视图的layout_gravity来决定子视图停靠在屏幕的哪个边缘外侧 ...

  10. 《31天成为IT服务达人》之精准运维

     1       第十四章精准运维服务 近年来国内IT产业的发展格局始终与我国的经济转型与创新创业的社会大潮息息相关,纵观国内国际形势,IT产业仍是创新的领头者,是解决人类各种经济危机的主要扮演者 ...