UVA 11235 Frequent values

 这段代码贴出来就被和谐掉了。。。

UVA 11235 Frequent values

007/2008 ACM International Collegiate Programming Contest University of Ulm Local ContestProblem F: Frequent valuesYou 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 SpecificationThe 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 SpecificationFor each query, print one line with one integer: The number of occurrences of the most frequent value within the given range.Sample Input10 3-1 -1 1 1 1 1 3 10 10 102 31 105 100Sample Output143A naive algorithm may not run in time!

https://github.com/CKboss/ACM-ICPC/commit/405398c60826794b9f4073b1e46feda72a5589db

https://github.com/CKboss/ACM-ICPC/blob/405398c60826794b9f4073b1e46feda72a5589db/UVA%2011235%20Frequent%20values 
posted @ 2013-06-23 04:13  码代码的猿猿  阅读(142)  评论(0编辑  收藏  举报