#P4135. 作诗

    ID: 3072 远端评测题 1500~2500ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>O2优化枚举,暴力概率论,统计块状链表,块状数组,分块

作诗

Description

Due to time pressure, after finishing a poem SHY still needs to crush OI, so she takes an article of length nn, reads it mm times, and each time reads only a contiguous segment [l,r][l, r]. From this segment, she selects some Chinese characters to form a poem. Because SHY likes parallelism, she requires that every selected character must appear a positive even number of times within [l,r][l, r]. Also, SHY wants the number of distinct selected characters (two identical characters are considered the same type) to be as large as possible. So SHY asks LYD to arrange the selection.

LYD, being a "sha×", certainly cannot do it, so he asks you for help.

Problem summary: Given nn positive integers a1ana_1 \dots a_n not greater than cc and mm queries, each query asks how many numbers in [l,r][l, r] appear a positive even number of times.

Input Format

This problem is strictly online.

The first line contains three integers nn, cc, and mm, representing the article length, the number of character types, and the number of selections.

The second line contains nn integers. The ii-th integer is the code aia_i of the ii-th character.

Each of the next mm lines contains two integers LL and RR. Let the previous query’s answer be ansans (for the first query, ans=0ans = 0). Define l=((L+ans)modn)+1l=((L+ans)\bmod n)+1, r=((R+ans)modn)+1r=((R+ans)\bmod n)+1, and if l>rl>r, swap ll and rr. Then the current query is [l,r][l, r].

Output Format

Output mm lines. The ii-th integer is the maximum number of distinct characters SHY can select for the ii-th query.

5 3 5
1 2 2 3 1
0 4
1 2
2 2
2 3
3 5
2
0
0
0
1

Hint

Constraints

For 100%100\% of the testdata, 1n,c,m1051 \le n, c, m \le 10^5, 1aic1 \leq a_i \leq c, 1l,rn1 \leq l, r \leq n.

Translated by ChatGPT 5