A3686 「CEOI2025」等于 mex

暂无评定 传统题 CEOI(中欧) 上传者
时间限制5000ms
内存限制1024MiB
通过 / 提交0/0

A3686「CEOI2025」等于 mex

暂无评定 传统题 CEOI(中欧) 上传者
时间限制5000ms
内存限制1024MiB
通过 / 提交0/0

Description

It is well known among Romanian noblemen that the beauty of an integer array a[0],a[1],a[2],…,a[m−1]a[0], a[1], a[2], \ldots, a[m-1] is the number of positive integers kk for which you can split the array into kk 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 00) that does not appear in the array.

You are given an integer array v[0],v[1],…,v[n−1]v[0], v[1], \ldots, v[n-1] and qq queries of the form (l,r)(l, r), where 0≤l≤r<n0 \leq l \leq r < n for all 0≤i<q0 \leq i < q.

For each query, you have to find the beauty of the array v[l],v[l+1],…,v[r]v[l], v[l+1], \ldots, v[r].

Implementation Details

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);
  • nn: the size of the integer array
  • vv: array of length nn, the initial array
  • qq: the number of queries
  • queriesqueries: array of length qq describing the queries
  • This procedure should return a vector of qq integers containing the answer for each query.
  • This procedure is called exactly once for each test case.

Constraints

  • 1≤n≤600 0001 \leq n \leq 600\,000
  • 1≤q≤600 0001 \leq q \leq 600\,000
  • 1≤v[i]≤400 0001 \leq v[i] \leq 400\,000 for all 0≤i<n0 \leq i < n
  • 0≤l≤r<n0 \leq l \leq r < n for all 0≤i<q0 \leq i < q

Subtasks

  1. (4 points) 1≤n≤101 \leq n \leq 10, 1≤q≤1001 \leq q \leq 100
  2. (6 points) 1≤n,q≤1001 \leq n, q \leq 100
  3. (17 points) 1≤n,q≤10001 \leq n, q \leq 1000
  4. (10 points) 1≤n,q≤100 0001 \leq n, q \leq 100\,000 and 1≤v[i]≤21 \leq v[i] \leq 2 for all 0≤i<n0 \leq i < n
  5. (30 points) 1≤n,q≤75 0001 \leq n, q \leq 75\,000
  6. (33 points) 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=10n=10 and there are 22 queries for which:

  • l=0l = 0 and r=5r = 5
  • l=0l = 0 and r=8r = 8

For the first query, we can split the interval in only one subarray, which is from position 00 to position 55.

In the second query, kk could be either 11 or 22. A possibility of splitting into 11 subarray is by choosing the subarray from position 00 to position 88. A possibility of splitting into 22 subarrays is by choosing the subarray from position 00 to position 55 and from position 66 to position 88.

The answer for the first query is 11 and for the second query, it is 22, so the call to solve will return {1, 2}.

Sample grader

The sample grader reads the input in the following format:

  • line 11: n qn\ q
  • line 22: v[0] v[1] … v[n−1]v[0]\ v[1]\ \ldots\ v[n-1]
  • line 3+i3+i: l rl\ r for all 0≤i<q0 \leq i < q

and outputs qq lines, the result of the call to function solve with the corresponding parameters.