哎,只能转题解了,,,

8165031                 2014-10-10 15:53:42     njczy2010     D - CGCDSSQ             GNU C++     Accepted 156 ms 27584 KB
8163765                 2014-10-10 13:03:56     njczy2010     D - CGCDSSQ             GNU C++     Time limit exceeded on test 10                 2000 ms                 32600 KB    
8163761                 2014-10-10 13:02:38     njczy2010     D - CGCDSSQ             GNU C++     Time limit exceeded on test 10                 2000 ms                 31600 KB    
8163755                 2014-10-10 13:01:12     njczy2010     D - CGCDSSQ             GNU C++     Wrong answer on test 9                 46 ms                 19700 KB    
8163749                 2014-10-10 12:59:54     njczy2010     D - CGCDSSQ             GNU C++     Wrong answer on test 9                 31 ms                 2100 KB
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 (l, r) such that 1 ≤ l ≤ r ≤ n and gcd(al, al + 1, ..., ar) = xi.

is a greatest common divisor of v1, v2, ..., vn, that is equal to a largest positive integer that divides all vi.

Input

The first line of the input contains integer n, (1 ≤ n ≤ 105), denoting the length of the sequence. The next line contains n space separated integers a1, ..., an, (1 ≤ ai ≤ 109).

The third line of the input contains integer q, (1 ≤ q ≤ 3 × 105), denoting the number of queries. Then follows q lines, each contain an integer xi, (1 ≤ xi ≤ 109).

Output

For each query print the result in a separate line.

Sample test(s)
Input
3 2 6 3 5 1 2 3 4 6
Output
1 2 2 0 1
Input
7 10 20 3 15 1000 60 16 10 1 2 3 4 5 6 10 20 60 1000
Output
14 0 2 2 2 0 2 2 1 1

题解以代码转自:http://blog.csdn.net/accelerator_/article/details/39892385

D:记录下gcd,每次多一个数字,就和前面的数字都取gcd,然后合并掉,下次利用这些已有的gcd去做,然后合并的过程要利用到gcd的递减性质,就可以直接从头往后找即可

 #include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<string>
//#include<pair> #define N 1000005
#define M 1000005
#define mod 1000000007
//#define p 10000007
#define mod2 100000000
#define ll long long
#define LL long long
#define maxi(a,b) (a)>(b)? (a) : (b)
#define mini(a,b) (a)<(b)? (a) : (b) using namespace std; int n,q;
int a[N];
map<int,ll>ans;
typedef pair<int,ll>PP;
PP save[N];
int tot; int gcd(int x,int y)
{
if(y==)
return x;
return gcd(y,x%y);
} void ini()
{
int i;
ans.clear();
tot=;
for(i=;i<=n;i++){
scanf("%d",&a[i]);
}
} void solve()
{
int i,j;
int sn;
for(i=;i<=n;i++){
for(j=;j<tot;j++){
save[j].first=gcd(save[j].first,a[i]);
}
save[tot]=make_pair(a[i],);
tot++;
sn=;
for(j=;j<tot;j++){
if(save[sn].first==save[j].first){
save[sn].second+=save[j].second;
}
else{
sn++;
save[sn]=save[j];
}
}
sn++;
tot=sn;
for(j=;j<tot;j++){
ans[ save[j].first ]+=save[j].second;
}
}
} void out()
{
int x;
scanf("%d",&q);
while(q--){
scanf("%d",&x);
printf("%I64d\n",ans[x]);
}
} int main()
{
//freopen("data.in","r",stdin);
//freopen("data.out","w",stdout);
// scanf("%d",&T);
// for(int ccnt=1;ccnt<=T;ccnt++)
// while(T--)
while(scanf("%d",&n)!=EOF)
{
//if(n==0 && k==0 ) break;
//printf("Case %d: ",ccnt);
ini();
solve();
out();
} return ;
}

Bayan 2015 Contest Warm Up D. CGCDSSQ (math,pair,map,暴力)的更多相关文章

  1. Bayan 2015 Contest Warm Up D题(GCD)

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

  2. map+pair Bayan 2015 Contest Warm Up D题

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

  3. COCI2014/2015 Contest#1 D MAFIJA【基环树最大独立点集】

    T1725 天黑请闭眼 Online Judge:COCI2014/2015 Contest#1 D MAFIJA(原题) Label:基环树,断环+树形Dp,贪心+拓扑 题目描述 最近天黑请闭眼在 ...

  4. 2018-2-6考试(COCI2014/2015 Contest#5)

    T1:FUNGHI(1s,32M,50pts)得分:50 题意:给你8个数组成一个环,要你求出其中连续的4个数,让它们的和最大 题解:暴力求出每一连续4个数之和,比较一下就好 标签:模拟 C++ Co ...

  5. C++算法代码——求数列[coci2014/2015 contest #1]

    题目来自:http://218.5.5.242:9018/JudgeOnline/problem.php?id=1815 题目描述 Mirko在数学课上以一种有趣的方式操作数列,首先,他写下一个数列A ...

  6. codeforces CF475 ABC 题解

    Bayan 2015 Contest Warm Up http://codeforces.com/contest/475 A - Bayan Bus B - Strongly Connected Ci ...

  7. Gym 100952E&&2015 HIAST Collegiate Programming Contest E. Arrange Teams【DFS+剪枝】

    E. Arrange Teams time limit per test:2 seconds memory limit per test:64 megabytes input:standard inp ...

  8. cf475A Bayan Bus

    A. Bayan Bus time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  9. 2015 浙江省赛 H - May Day Holiday

    H - May Day Holiday As a university advocating self-learning and work-rest balance, Marjar Universit ...

随机推荐

  1. 2018 北京区域赛 I - Palindromes (找规律)

    题目 HihoCoder - 1878 题目大意 给出k,让求出第k个回文数(k的“长度”不超过1e5) 题解 之前做过类似的题,是统计各阶段的数找到第K个回文数,但这里K太大,需要寻找新的方法. 打 ...

  2. css--背景和列表

    背景 背景样式: background-color    设置元素的背景颜色 background-image  把图像设置为背景 background-repeat     设置背景图像是否重复及如 ...

  3. PAT (Basic Level) Practise (中文)- 1022. D进制的A+B (20)

    PAT (Basic Level) Practise (中文)-  1022. D进制的A+B (20)  http://www.patest.cn/contests/pat-b-practise/1 ...

  4. Mac OSX用 dd 命令,浇灌ISO镜像到USB驱动器

    Mac OSX用 dd 命令,浇灌ISO镜像到USB驱动器 字数244 阅读197 评论0 喜欢0 把ISO镜像转换为一个可启动的USB设备.一种可行的方法是通过OS X的Terminal “浇灌”到 ...

  5. JS数组专题2️⃣ ➖ 数组去重

    距离上次发文,已经有一段时间了,最近工作比较忙,这不眼看快双十一了,就相当于给大家一些福利吧! 一.什么是数组去重 简单说就是把数组中重复的项删除掉,你 GET 到了吗 ?下面我将简单介绍下几种基本的 ...

  6. 初涉2-SAT

    2-SAT:有趣的图论模型 什么是2-SAT SAT是适定性(Satisfiability)问题的简称.之所以研究2-sat是因为当k>2时,k-sat问题已经被证明是NPC的了. 2-sat问 ...

  7. easyUI之datagrid绑定后端返回数据的两种方式

    先来看一下某一位大佬留下的easyUI的API对datagrid绑定数据的两种方式的介绍. 虽然精简,但是,很具有“师傅领进门,修行靠个人”的精神,先发自内心的赞一个. 但是,很多人和小编一样,第一次 ...

  8. mysql5.7.22-log 修改远程访问

    正常的设置账号远程访问依然访问不了的情况,可以看一下服务器 my.cnf配置文件下 [client] #password = your_password 把上面的#去掉就行了.

  9. (30)zabbix Trapper 监控项配置

    概述 zabbix获取数据有超时时间,如果一些数据需要执行比较长的时间才能获取的话,那么zabbix会出现异常,考虑到这种情况,zabbix增加了Trapper功能,客户端自己提交数据给zabbix, ...

  10. log4j日志输出到文件的配置

    1.Maven的dependency 2.log4j.properties的配置 3.Junit的Test类 4.web.xml的配置(非必要) 5.spring的db.config的配置(非必要) ...