博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
树状数组 gcd 查询 Different GCD Subarray Query
阅读量:5858 次
发布时间:2019-06-19

本文共 2087 字,大约阅读时间需要 6 分钟。

Different GCD Subarray Query

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 1328    Accepted Submission(s): 504

Problem Description
This is a simple problem. The teacher gives Bob a list of problems about GCD (Greatest Common Divisor). After studying some of them, Bob thinks that GCD is so interesting. One day, he comes up with a new problem about GCD. Easy as it looks, Bob cannot figure it out himself. Now he turns to you for help, and here is the problem:
  
  Given an array 
a of N positive integers a1,a2,aN1,aN; a subarray of a is defined as a continuous interval between a1 and aN. In other words, ai,ai+1,,aj1,aj is a subarray of a, for 1ijN. For a query in the form (L,R), tell the number of different GCDs contributed by all subarrays of the interval [L,R].
  
 

 

Input
There are several tests, process till the end of input.
  
  For each test, the first line consists of two integers 
N and Q, denoting the length of the array and the number of queries, respectively. N positive integers are listed in the second line, followed by Q lines each containing two integers L,R for a query.
You can assume that 
  
    1N,Q100000 
    
   1ai1000000
 

 

Output
For each query, output the answer in one line.
 

 

Sample Input
5 3 1 3 4 6 9 3 5 2 5 1 5
 

 

Sample Output
6 6 6
 

 

Source
 

 

Recommend
wange2014
长度n的序列, m个询问区间[L, R], 问区间内的所有子段的不同GCD值有多少种.
树状数组满足这种操作,但是知道这个我也不会啊,不懂后来那种统计操作
#include
using namespace std;const int N=200005;int c[N],a[N],n,Q,last[N*10],ans[N];vector < pair
>q[N],b[N];void add(int k,int num) { while(k<=n) { c[k]+=num; k+=k&-k; }}int read(int k) { int res=0; while(k) { res+=c[k]; k-=k&-k; } return res;}int main() { while(~scanf("%d%d",&n,&Q)) { for(int i=1; i<=n; i++) { scanf("%d",&a[i]); q[i].clear(); b[i].clear(); } for(int i=1; i<=n; i++) { int x=a[i],y=i; b[i].push_back(make_pair(x,y)); for(int j=0; j

 

 

转载于:https://www.cnblogs.com/BobHuang/p/7228374.html

你可能感兴趣的文章
ubuntu13.04 有线网卡驱动安装 无法上网 网络配置
查看>>
xml格式说明文档
查看>>
Text
查看>>
可见面判别算法---线框图可见算法
查看>>
根据特定的值划分链表 Partition List
查看>>
【原创】MySQL Proxy - query注入动作中的脚本序列
查看>>
MongoDB小技巧-用ObjectID查询某一时间范围内的数据
查看>>
java多线程详解一线程的内存模型和线程特性
查看>>
修改数据
查看>>
Hibernate_01
查看>>
网络互联参考模型(详解)
查看>>
Mathtype与LaTeX相互转换
查看>>
通用社区登陆组件技术分享(开源)上篇:OAuth 授权登陆介绍
查看>>
SpringMVC学习系列(9) 之 实现注解式权限验证
查看>>
hadoop学习笔记-HDFS原理
查看>>
GC日志分析工具GCViewer
查看>>
Kubernetes的四种用户部署场景,你知吗?
查看>>
eclipse中使用maven创建项目
查看>>
JFinal框架操作oracle数据库
查看>>
Android设置通知Notification
查看>>