Description

You are given a sequence of n integers a1 , a2 , ... , an in non-decreasing order. In addition to that, you are given several queries consisting of indices i and j (1 ≤ i ≤ j ≤ n). For each query, determine the most frequent value among the integers ai , ... , aj.

Input

The input consists of several test cases. Each test case starts with a line containing two integers n and q (1 ≤ n, q ≤ 100000). The next line contains n integers a1 , ... , an (-100000 ≤ ai ≤ 100000, for each i ∈ {1, ..., n}) separated by spaces. You can assume that for each i ∈ {1, ..., n-1}: ai ≤ ai+1. The following q lines contain one query each, consisting of two integers i and j (1 ≤ i ≤ j ≤ n), which indicate the boundary indices for the 
query.

The last test case is followed by a line containing a single 0.

Output

For each query, print one line with one integer: The number of occurrences of the most frequent value within the given range.

Sample Input

10 3
-1 -1 1 1 1 1 3 10 10 10
2 3
1 10
5 10
0

Sample Output

1
4
3 题意:给出一个非降序的整数数组,对于一系列询问(i,j),求出范围i,j之间出现次数最多的值的出现次数。
思路:将整个数组进行游程编码,(a,b)表示有b个连续的a。用count[i]表示第i段的出现次数。num[p],left[p],right[p]分别表示位置p所在的段的编号和左右端点的位置。剩下的见白书

poj3368 uva11235 Frequent values的更多相关文章

  1. 【暑假】[实用数据结构]UVa11235 Frequent values

    UVa 11235 Frequent values Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 11241   Accep ...

  2. UVA-11235 Frequent values (RMQ)

    题目大意:在一个长度为n的不降序列中,有m次询问,每次询问(i,j)表示在区间(i,j)中找出出现次数最多的元素的出现次数. 题目分析:因为序列有序,可以将序列分段,并且记录每段的元素个数.每一个元素 ...

  3. UVA11235 Frequent values

    思路 连续的值只会分布在一起成一个块 讨论两边的块,中间就是RMQ了 ST表即可 代码 #include <cstdio> #include <algorithm> #incl ...

  4. UVA - 11235 Frequent values

    2007/2008 ACM International Collegiate Programming Contest University of Ulm Local Contest Problem F ...

  5. poj 3368 Frequent values(RMQ)

    /************************************************************ 题目: Frequent values(poj 3368) 链接: http ...

  6. H - Frequent values

    Problem F: Frequent values You are given a sequence of n integers a1 , a2 , ... , an in non-decreasi ...

  7. Frequent values && Ping pong

    Frequent values 题意是不同颜色区间首尾相接,询问一个区间内同色区间的最长长度. 网上流行的做法,包括翻出来之前POJ的代码也是RMQ做法,对于序列上的每个数,记录该数向左和向右延续的最 ...

  8. [HDU 1806] Frequent values

    Frequent values Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  9. 数据结构(RMQ):UVAoj 11235 Frequent values

    Frequent values You are given a sequence of n integers a1 , a2 , ... , an in non-decreasing order. I ...

随机推荐

  1. __main() 和 main() 【转】

    因为我们通常在BOOTLOADER中都已做好了比较细致的初始化工作,包括代码的搬运,所以我们最好别再调用库函数__main(),因为__main()作为ADS集成好的库函数,会对系统进行初始化设置,可 ...

  2. python的数据类型及操作

    简述python的几种简单的数据类型及使用方式 字符串 字符串是不可变数据类型,拥有多种内置方法可以操作. 创建字符串就是给变量分配一个字符串的值即可.通常用引号创建字符串. tell = 'my n ...

  3. 文件的默认权限UMASK

    当进入Linux系统后新创建的文件或者文件夹总是会有一个默认的权限,那么这个权限是如何设置的呢? umask就是设置文件与目录的默认权限 1. 查看umask 直接查看, [root@centos6 ...

  4. 禁止UIWebView随键盘的弹起而往上滚动

    问题:当UIWebView中的html有输入框,点击输入框,UIWebView会随键盘的弹起而整体往上移动,收起键盘后,UIWebView无法回到原来的位置; 问题的原因:由于UIWebView继承的 ...

  5. 构建高并发&高可用&安全的IT系统-高并发部分

    什么是高并发? 狭义来讲就是你的网站/软件同一时间能承受的用户数量有多少 相关指标有 并发数:对网站/软件同时发起的请求数,一般也可代表实际的用户 每秒响应时间:常指一次请求到系统正确响的时间(以秒为 ...

  6. 浅析python 的import 模块(转)

    摘要: 学习python有几天了,对import一直不是很清楚,和C里面的include是否一样,重复引入有问题么?搜索路径是怎样的?整理解决下我的疑问. 一 模块的搜索路径 模块的搜索路径都放在了s ...

  7. Django中ORM模型总结(一)[概述,查询语句]

    理解ORM框架 概述 O:(objects)->类和对象. R:(Relation)->关系,关系数据库中的表格. M:(Mapping)->映射. 作用: 可以通过类和类对象就可以 ...

  8. 关于Django的理解

    Django的理解 Django的核心是中间件, 所有的请求和响应都会经过中间件 中间件是一个钩子框架, 它们可以介入请求的响应处理过程, 它用于在全局修改Django的输入和输出 Django有以下 ...

  9. Python网络数据采集7-单元测试与Selenium自动化测试

    Python网络数据采集7-单元测试与Selenium自动化测试 单元测试 Python中使用内置库unittest可完成单元测试.只要继承unittest.TestCase类,就可以实现下面的功能. ...

  10. mysql-proxy读写分离

    实验环境: LAP+ 1.安装apache服务(192.168.2.131) yum install openssl-devel [root@LAP ~]# tar zxvf httpd-2.2.25 ...