| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 5 초 (추가 시간 없음) | 1024 MB (추가 메모리 없음) | 9 | 3 | 3 | 50.000% |
It is well known among Romanian noblemen that the beauty of an integer array $a[0], a[1], a[2],\dots , a[m − 1]$ is the number of positive integers $k$ for which you can split the array into $k$ disjoint subarrays (sequences of consecutive elements) such that each element is contained in exactly one subarray and all the subarrays have the same minimum excluded element. The minimum excluded element of an integer array is the smallest strictly positive integer (greater than $0$) that does not appear in the array.
You are given an integer array $v[0], v[1],\dots ,v[n − 1]$ and $q$ queries of the form $(l_i , r_i )$, where $0 ≤ l_i ≤ r_i < n$ for all $0 ≤ i < q$.
For each query, you have to find the beauty of the array $v[l_i ], v[l_i + 1], \dots , v[r_i ]$.
You should implement the following procedure:
std::vector<int> solve(int n, std::vector<int>& v, int q, std::vector<std::pair<int, int>>& queries);
| 번호 | 배점 | 제한 |
|---|---|---|
| 1 | 4 | $1 ≤ n ≤ 10$, $1 ≤ q ≤ 100$ |
| 2 | 6 | $1 ≤ n, q ≤ 100$ |
| 3 | 17 | $1 ≤ n, q ≤ 1\, 000$ |
| 4 | 10 | $1 ≤ n, q ≤ 100\, 000$ and $1 ≤ v[i] ≤ 2$ for all $0 ≤ i < n$ |
| 5 | 30 | $1 ≤ n, q ≤ 75\, 000$ |
| 6 | 33 | No additional constraints. |
Example 1
Consider the following call:
solve(10, {1, 1, 2, 2, 3, 3, 1, 2, 3, 4}, 2, {{0, 5}, {0, 8}})
In this sample $n = 10$ and there are $2$ queries for which:
For the first query, we can split the interval in only one subarray, which is from position $0$ to position $5$.
In the second query, $k$ could be either $1$ or $2$.
A possibility of splitting into $1$ subarray is by choosing the subarray from position $0$ to position $8$. A possibility of splitting into $2$ subarrays is by choosing the subarray from position $0$ to position $5$ and from position $6$ to position $8$.
The answer for the first query is $1$ and for the second query, it is $2$, so the call to solve will return {1, 2}.
The sample grader reads the input in the following format:
and outputs $q$ lines, the result of the call to function solve with the corresponding parameters.
C++17, C++20, C++23, C++26, C++17 (Clang), C++20 (Clang)