Elena is yet again tasked with solving a problem involving subarrays with a special property. By now she finds these tasks banal, so she leaves writing a solution to you – the IATI contestants. The problem statement is as follows:
We define a “self-describing” array – an array in which for all it is true that the number appears exactly times in the entire array. are all examples of “self-describing” arrays, while (there is only one occurrence of ), (there are occurrences of ) are all examples of non-“self-describing” arrays.
Additionally for an array we define a “self-describing” subarray as a subarray that is itself “self-describing”.
You are given an array and queries such that . For each query you should find the number of “self-describing” subarrays for which for all queries.
Implementation details
You should implement the following two procedures:
void init(int N, int Q, const std::vector<int>& a)
This function will be called once per test and provides your program with the original array as a vector, consisting of the values in this order.
long long query(int l, int r)
This function will be called times per test and will correspond to a query for the range , it should return the answer to that query.
Local testing
To test your program locally, a local grader and a header file are provided. The local grader reads and queries in this order, calls your init and then outputs the answers your program gave to all query calls. You are free to modify the local grader.
Constraints and clarifications
- for all
- for all queries.
| Subtask | Points | Necessary subtasks | Other constraints | ||
|---|---|---|---|---|---|
| 0 | 0 | Example. | |||
| 1 | 6 | The only query is . | |||
| 2 | 6 | The only query is . | |||
| 3 | 39 | The only query is . | |||
| 4 | 11 | ||||
| 5 | 16 | ||||
| 6 | 22 |
Example
stdin
7 3
1 2 1 2 3 3 3
0 3
2 6
0 6
stdout
3
2
5