All Tracks Data Structures Advanced Data Structures Segment Trees Problem

This is Code Apocalypse !!!
Tag(s):

Medium-Hard

Problem
Editorial
Analytics

This is CODE APOCALYPSE!! People are fighting against each other ,not for food ,money or life but for points. There are n people and each of them is fighting for some number of points.

Now you will be given q queries containing l and r. You have to tell the maximum number of people who are fighting for same number of point from l to r.

INPUT

First line contains a integer t denoting the number of test cases.

Every first line of each test case contains n and q where n are the number of people and q is the number of queries.

Every second line of test case contains n space separated integer ai denoting the point in non decreasing order.

Next q lines contains two integer l and r.

OUTPUT

For every q queries you have to print the maximum number of people fighting for same number of points in a new line.

CONSTRAINT

1<=n,q<=105

1<=ai<=106

1<=l<=r<=n

SAMPLE INPUT
1
6 2
1 1 1 2 3 3
3 6
1 6
SAMPLE OUTPUT
2
3
Time Limit: 1.0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: C, C++, C++14, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), Julia, Kotlin, Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Swift, Visual Basic

CODE EDITOR

Initializing Code Editor...
Your Rating:

Contributor

Notifications
View All Notifications