Codeforces 475 D.CGCDSSQ
题目说了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的更多相关文章
- 【CODEFORCES】 D. CGCDSSQ
		D. CGCDSSQ time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ... 
- Codeforces 475 B Strongly Connected City【DFS】
		题意:给出n行m列的十字路口,<代表从东向西,>从西向东,v从北向南,^从南向北,问在任意一个十字路口是否都能走到其他任意的十字路口 四个方向搜,搜完之后,判断每个点能够访问的点的数目是否 ... 
- codeforces 475D. CGCDSSQ
		D. CGCDSSQ time limit per test 2 seconds memory limit per test 256 megabytes Given a sequence of int ... 
- [codeforces round#475 div2 ][C Alternating Sum ]
		http://codeforces.com/contest/964/problem/C 题目大意:给出一个等比序列求和并且mod 1e9+9. 题目分析:等比数列的前n项和公式通过等公比错位相减法可以 ... 
- 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 解 对于题目要求,显然一开始的树,要求度数为偶数的节点个数为奇数个,通过奇 ... 
- Codeforces 475D CGCDSSQ(分治)
		题意:给你一个序列a[i],对于每个询问xi,求出有多少个(l,r)对使得gcd(al,al+1...ar)=xi. 表面上是询问,其实只要处理出每个可能的gcd有多少个就好了,当左端点固定的时候,随 ... 
- Codeforces 475D CGCDSSQ 求序列中连续数字的GCD=K的对数
		题目链接:点击打开链接 #include <cstdio> #include <cstring> #include <algorithm> #include < ... 
- Codeforces Round #475 Div. 1
		B:当n是偶数时无解,因为此时树中有奇数条边,而我们每次都只能删除偶数条.当n是奇数时一定有解,因为此时不可能所有点度数都为奇数,只要找到一个度数为偶数的点,满足将它删掉后,各连通块大小都为奇数就可以 ... 
- 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 ... 
随机推荐
- C#验证码
			using System; using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Imaging; us ... 
- XML文档部署到Tomcat服务器上总是加载出错
			config.xnl 起初文档路径是在src/Dao/config.xml 在Dao目录下BaseDao类中,解析config.xml文件路径 path="/Dao/config.xml&q ... 
- MVC 5 App 通过 Facebook OAuth2 登陆(Sign-on)的问题
			今天做了下MVC 5 App通过Google, Twitter, Linkedin 和 Facebook进行登录的例子, 算是对Asp.net Identity的一个入门,做的过程中发现了如下的问题, ... 
- Delphi 对象的创建(create)与释放(free/destory)
			Delphi 对象的创建(create)与释放(free/destory) 1.Create参数为:nil/self/application的区别,最好能看到实际效果的区别 例如: My := TMy ... 
- poj 1192最优连通子集(简单树形dp)
			题目链接:http://poj.org/problem?id=1192 #include<cstdio> #include<cstring> #include<iostr ... 
- bzoj3907: 网格
			http://www.cnblogs.com/Tunix/p/4354348.html #include<cstdio> #include<cstring> #include& ... 
- AlertDialog.Builder setCancelable用法
			AlertDialog.Builder的setCancelable public AlertDialog.Builder setCancelable (boolean cancelable) Sinc ... 
- UISegmentedControl   UISlider
			self.view.backgroundColor = [UIColor whiteColor]; //UISegmentedControl 是iOS中的分段控件,事实上是多个button的组合视图, ... 
- PNP8550(3.3V DC蜂鸣器) - 原理图系列
			一.截图 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveGlhb2Jpbl9ITEo4MA==/font/5a6L5L2T/fontsize/400/fi ... 
- UITableView的简单应用介绍
			创建一个tableView视图,然后把这个视图界面添加到主界面上. _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 20, [ ... 
