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

题意:给出n个数,然后给q个询问,每次询问给出一个x。问有多少个区间的GCD是x

思路:比赛的时候yy的一个做法

            首先预处理出全部值的区间个数,这个用map存一下就好了,设为ans

            然后再开两个map 分别为mp mp2

            mp存的是以Xi结尾的全部区间的GCD的数的个数

            每次从Xi转移到Xi+1,仅仅须要累加以Xi结尾的区间的全部mp值与Xi+1的GCD的个数就好了,能够暂时赋给mp2,然后再赋给mp

            依照这种方法从左往右for一遍就好了

            然后查询的时候直接在ans里查就好了

            复杂度大概是O(N*(每一个数的因子个数))

Bayan 2015 Contest Warm Up D题(GCD)的更多相关文章

  1. 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 ...

  2. Bayan 2015 Contest Warm Up D. CGCDSSQ (math,pair,map,暴力)

    哎,只能转题解了,,, 8165031                 2014-10-10 15:53:42     njczy2010     D - CGCDSSQ             GN ...

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

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

  4. 2015北京网络赛 G题 Boxes bfs

    Boxes Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://hihocoder.com/contest/acmicpc2015beijingonl ...

  5. 2015北京网络赛 H题 Fractal 找规律

    Fractal Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://hihocoder.com/contest/acmicpc2015beijingo ...

  6. AtCoder Grand Contest 1~10 做题小记

    原文链接https://www.cnblogs.com/zhouzhendong/p/AtCoder-Grand-Contest-from-1-to-10.html 考虑到博客内容较多,编辑不方便的情 ...

  7. 2015 UESTC 数据结构专题B题 秋实大哥与花 线段树 区间加,区间查询和

    B - 秋实大哥与花 Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/59 De ...

  8. 2015 UESTC 搜索专题K题 秋实大哥の恋爱物语 kmp

    秋实大哥の恋爱物语 Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/61 De ...

  9. 2015 UESTC 搜索专题F题 Eight Puzzle 爆搜

    Eight Puzzle Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/61 ...

随机推荐

  1. 分布式框架Dubbo入门

    Dubbo简介 Dubbo是一个Alibaba开源额分布式服务框架,致力于提供高性能和透明化的RPC远程服务调用方案,以及SOA服务治理方案.dubbo就是个服务框架,只有在分布式的时候,才有dubb ...

  2. 【最新版】从零开始在 macOS 上配置 Lua 开发环境

    脚本语言,你可能更需要的是 Lua 不同的脚本语言有不同的特性,第一接触的脚本语言,可能会影响自己对整个脚本语言的理解和认知.我以前接触最多的脚本语言是 JavaScript.后果就是:我一度以为脚本 ...

  3. 北京地铁换乘算法(二维坐标系,图的深度搜索)开源下载Android源码、性能最优解

    距离2012年11月2日下午2:05:31 已经过去158751270这么多秒了,不小心暴露了我的当前时间. java代码贴出来. private static long gettimelong() ...

  4. 30.Linux-RTC驱动分析及使用

    linux中的rtc驱动位于drivers/rtc下,里面包含了许多开发平台的RTC驱动,我们这里是以S3C24xx为主,所以它的RTC驱动为rtc-s3c.c 1.进入./drivers/rtc/r ...

  5. 【原创】使用workstation安装Xenserver 6.5+cloudstack 4.10----本地存储模式

    1. 背景: 近期由于项目和个人学习得需求,开始接触到Cloudstack,虽然云计算概念在大学刚毕业的时候就已经略有耳闻,但是由于工作原因,也一直没有了解,下班后想自己折腾下cloudstack,便 ...

  6. matplotlib删除x轴

    组内有个同事,有个奇怪的需求需要matplotlib删除x轴 效果图如下:

  7. 使用JavaMail发送带附件的邮件

    所需jar包 链接:http://pan.baidu.com/s/1dFo4cDz 密码:akap 工具类: package com.javamail.utils; import java.util. ...

  8. T-SQL的进阶:超越基本级别3:构建相关子查询——701小组

    T-SQL的进阶:超越基本级别3:构建相关子查询 格雷戈里·拉森,2014/03/05 原文链接: http://www.sqlservercentral.com/articles/Stairway+ ...

  9. [最短路]P1828 香甜的黄油 Sweet Butter

    题目描述 农夫John发现做出全威斯康辛州最甜的黄油的方法:糖.把糖放在一片牧场上,他知道N(1<=N<=500)只奶牛会过来舔它,这样就能做出能卖好价钱的超甜黄油.当然,他将付出额外的费 ...

  10. Java 将两个有序数组合成为一个有序数组

    基本思路 1.如果其中一个数组的元素均大于另一个数组的元素,则可以直接组合,不用拆分. 即:其中一个数组的第一个元素大于或者小于另一个数组的最后一个元素 2.若不满足1中的情况,则表明数组需要拆分,拆 ...