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 $A_l, A_{l+1}, ..., A_r$. ### Input - The first line consists of two integers $n, q$. - The second line contains $n$ integers $A_i$. - The next $q$ lines each contain two integers $x, y$, representing a query. Two integers $l, r$ are calculated as follows: + $l = (x + \text{lastans}) \mod n + 1$ + $r = (y + \text{lastans}) \mod n + 1$ + $\text{lastans}$ is the answer from the previous query. In the first query, $\text{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 \le n, q \le 2 \times 10^5$. - $1 \le A_i \le 2 \times 10^5$. - $1 \le x,y \le n$. ### Sample Input: ``` 5 3 1 2 2 3 2 1 3 1 5 4 5 ``` Output: ``` 2 1 1 ```