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. kail的aircrack-ng 移到linux系统,Ubuntu等系统

    系统: debian (理论上基于debian的操作系统都可以, 如ubuntu, lubuntu, 等等) # apt-get install gcc make rt3070驱动安装: # apt- ...

  2. java+selenium3.0 运行时出的问题(system property)!

    按照之前的文章讲解,都已经搭建好了,可是在刚开始运行就报错了,代码和报错如下: WebDriver driver = new ChromeDriver(); driver.get("http ...

  3. nopCommerce 3.9 大波浪系列 之 网页加载Widgets插件原理

    一.插件简介 插件用于扩展nopCommerce的功能.nopCommerce有几种类型的插件如:支付.税率.配送方式.小部件等(接口如下图),更多插件可以访问nopCommerce官网. 我们看下后 ...

  4. (转)Java中equals和==的区别

    java中的数据类型,可分为两类:  1.基本数据类型,也称原始数据类型.byte,short,char,int,long,float,double,boolean    他们之间的比较,应用双等号( ...

  5. angularJS的$http.post请求,.net后台接收不到参数值的解决方案

    JS通用部分 var shoppingCartModule =angular.module('starter', ['ionic'], function ($httpProvider) { // Us ...

  6. phpMyAdmin安装部署

    phpMyAdmin 是一个用PHP编写的软件工具,可以通过web方式控制和操作MySQL数据库.通过phpMyAdmin 可以完全对数据库进行操作,例如建立.复制和删除数据等等.如果使用合适的工具, ...

  7. 数据结构随笔-php实现队列

    队列(Queue): 满足先进先出(FIFO)的规则: 下面使用php实现一个简单的循环队列模型: 初始状态的队列,队列长度为0,队头和队尾的指针相同均位于队列的开始: 入队操作:队尾指针向后移动,长 ...

  8. Java-将多线程停止的两种方法

    线程如何停止呢 stop方法过时了,看起描述发现,有其他解决方案. 线程结束:就是让线程任务代码执行完,run方法结束. run方法怎么结束呢? run方法中通常都定义循环,只要控制住循环就哦了. / ...

  9. 填涂颜色 洛谷 p1162

    题目描述 由数字0 组成的方阵中,有一任意形状闭合圈,闭合圈由数字1构成,围圈时只走上下左右4个方向.现要求把闭合圈内的所有空间都填写成2.例如:6X6的方阵(n=6),涂色前和涂色后的方阵如下: 0 ...

  10. TX2(1)--Jetson TX2 刷机并安装JetPack3.0

    一般而言,刷机是在Ubuntu16.04的系统上进行,本人在ubuntu16.04系统上进行了初步的测试,暂时存在一些问题,因此建议首先配备一台Ubuntu14.04的host主机(不建议使用虚拟机) ...