#P11570. 「chaynOI R1 T3」镍铬合金机器人

「chaynOI R1 T3」镍铬合金机器人

Background

Problem Description

You are given a sequence botbot of length nn.

There are qq queries. Each query gives three numbers l,x,yl, x, y. For each query, find how many intervals [l,r][l, r] (with lrl \le r) starting at ll satisfy $\text{mex}(\{bot_l, bot_{l+1}, \cdots, bot_r\}) \in [x, y]$.

Note: For a multiset SS, the mex\text{mex} function mex(S)\text{mex}(S) is defined as the smallest non-negative integer that does not appear in SS. For example, mex({0,1,1,3})=2\text{mex}(\{0,1,1,3\}) = 2.

Input Format

The first line contains two positive integers n,qn, q, representing the length of the sequence and the number of queries.

The second line contains nn numbers, representing the sequence botbot.

The next qq lines each contain three integers l,x,yl, x, y.

Output Format

Output qq lines in total. Each line contains one integer, representing the answer.

4 2
0 1 3 2
1 2 2
2 1 4
2
0
10 10
0 0 1 1 1 0 0 1 0 1
1 0 0
2 0 1
3 1 2
4 0 1
5 0 2
6 0 1
7 1 1
8 2 2
9 0 0
10 1 2

0
1
5
2
6
2
1
2
0
0

Hint

For 100%100\% of the data, 1n,q3×1051 \le n, q \le 3 \times 10^5, 0boti<n0 \le bot_i < n, 0xyn0 \le x \le y \le n, 1ln1 \le l \le n.

This problem uses bundled testdata.

  • Subtask 1 (10 pts): n,q300n, q \le 300.
  • Subtask 2 (15 pts): n,q2000n, q \le 2000.
  • Subtask 3 (15 pts): boti1bot_i \le 1.
  • Subtask 4 (20 pts): x=yx = y.
  • Subtask 5 (40 pts): No special constraints.

Translated by ChatGPT 5