Mode - MarisaOJ: Marisa Online Judge

Mode

Time limit: 1000 ms
Memory limit: 256 MB
Given an integer sequence A and q queries in the form of l,r, find the number of occurrences of the most frequent value in the range Al,Al+1,...,Ar. ### Input - The first line consists of two integers n,q. - The second line contains n integers Ai. - The next q lines each contain two integers x,y, representing a query. Two integers l,r are calculated as follows: + l=(x+lastans)modn+1 + r=(y+lastans)modn+1 + lastans is the answer from the previous query. In the first query, lastans is conventionally set to 0. If l>r, swap the values of l and r. ### Output - Print q lines, each line containing the corresponding answer for each query. ### Constraints - 1≤n,q≤2×105. - 1≤Ai≤2×105. - 1≤x,y≤n. ### Sample Input: 5312232131545 Output: 211