#P4137. Rmq Problem / mex

    ID: 3073 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>莫队线段树RMQ可持久化块状链表,块状数组,分块清华集训

Rmq Problem / mex

Description

There is an array {a1,a2,,an}\{a_1,a_2,\ldots,a_n\} of length nn.

There are mm queries; for each query, find the smallest non-negative integer that does not appear in the interval (mex).

Input Format

The first line contains two positive integers n,mn,m.
The second line contains nn non-negative integers a1,a2,,ana_1, a_2, \ldots , a_n.
Then follow mm lines, each containing two positive integers l,rl,r, representing a query.

Output Format

Output mm lines, one number per line, giving the answer to each query in order.

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

Hint

For 30%30\% of the testdata: 1n,m10001\leq n,m\leq 1000.
For 100%100\% of the testdata: 1n,m2×1051\leq n,m\leq 2\times {10}^5, 1lrn1\leq l\leq r\leq n, 0ai2×1050\leq a_i\leq 2\times 10^5.

Translated by ChatGPT 5