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. javascript 二维(多维)数组的复制问题

    最近在项目中遇到一个动画暂停的效果,需要在动画停止的时候检测当前坐标和已经运行的时间,从而调节时间轴为再次运行时加速. 但是在数组保存方面折腾了半天. var orbitArray = [], lin ...

  2. 按键(vb)启动指定目录的程序以及获取当前应用路径

    Private Declare Function GetDesktopWindow Lib "user32" () As Long Private Declare Function ...

  3. IDEA搭建SSMM框架(详细过程)

    IDEA搭建SSMM框架(详细过程) 相关环境 Intellij IDEA Ultimate Tomcat JDK MySql 5.6(win32/win64) Maven (可使用Intellij ...

  4. C# 扩展方法使用

    为指定类型扩展方法: 定义类Class1: public static class Class1                                  //必须为static类,且不能包含 ...

  5. Python之matplotlib学习(一)

    小试牛刀 在上一节已经安装好matplotlib模块,下面使用几个例子熟悉一下. 对应的一些文档说明: http://matplotlib.org/1.3.1/api/pyplot_summary.h ...

  6. iOS项目的命名规范

    一.关于本文档1.本文档的书写目的    <iOS项目的命名规范>的书写目的,在于让后续参加到该项目的iOS开发人员通过阅读该文档,了解在当前iOS项目的代码中的命名要求并严格按照本文档执 ...

  7. 获取request header的值

    1Sring mvc 中可以通过注解  : @RequestHeader ("host") String hostName 2httpservletrequest request ...

  8. mysql b-tree 索引下联合索引的顺序测试方案

    使用联合索引需要注意的列顺序比如在使用select * from user where x=1 and y=2;的时候,应该需要建立的索引可能是 add key(x,y)如何确定索引的顺序一般经验而言 ...

  9. 匿名HTTP透明HTTP高匿HTTP区别

    透明代理的意思是客户端根本不需要知道有代理服务器的存在,但是它传送的仍然是真实的IP.你要想隐藏的话,不要用这个. 普通匿名代理能隐藏客户机的真实IP,但会改变我们的请求信息,服务器端有可能会认为我们 ...

  10. Innodb中的锁

    Innodb中的锁 共享锁和排它锁(Shared and Exclusive Locks)共享锁和排它锁是行级锁,有两种类型的行级锁 共享锁(s lock)允许持有锁的事务对行进行读取操作 排它锁(x ...