#P4168. [Violet] 蒲公英

    ID: 3071 远端评测题 500ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>离散化O2优化枚举,暴力众数块状链表,块状数组,分块

[Violet] 蒲公英

Description

There are many dandelions planted along a country path, and our problem is about these dandelions.

To simplify, we treat all the dandelions as a sequence of length nn, {a1,a2..an}\{a_1,a_2..a_n\}, where aia_i is a positive integer representing the type ID of the ii-th dandelion.

For each query on an interval [l,r][l, r], you need to report which type appears most frequently in the interval. If several types are tied, output the smallest type ID among them.

Note: your algorithm must be online.

Input Format

The first line contains two integers, representing the number of dandelions nn and the number of queries mm.

The second line contains nn integers. The ii-th integer is the type aia_i of the ii-th dandelion.

Then follow mm lines. Each line contains two integers l0,r0l_0, r_0, representing one query. The input is encrypted; the decryption is as follows:

Let the previous query’s result be xx (if this is the first query, then x=0x = 0), and set $l=((l_0+x-1)\bmod n) + 1, r=((r_0+x-1) \bmod n) + 1$. If l>rl > r, swap l,rl, r.
The final query interval is the computed [l,r][l, r].

Output Format

For each query, output one integer on its own line representing the answer.

6 3 
1 2 3 2 1 2 
1 5 
3 6 
1 5

1 
2 
1

Hint

Constraints

  • For 20%20\% of the testdata, it is guaranteed that n,m3000n, m \le 3000.
  • For 100%100\% of the testdata, it is guaranteed that 1n400001 \le n \le 40000, 1m500001 \le m \le 50000, 1ai1091 \le a_i \le 10^9, 1l0,r0n1 \leq l_0, r_0 \leq n.

Translated by ChatGPT 5