#P13693. [CEOI 2025] Equal Mex

[CEOI 2025] Equal Mex

题目描述

It is well known among Romanian noblemen that the beauty of an integer array a[0]a[0], a[1]a[1], a[2]a[2], \ldots, a[m1]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 0) that does not appear in the array.

You are given an integer array v[0]v[0], v[1]v[1], \ldots, v[n1]v[n-1] and qq queries of the form (li,ri)(l_i, r_i), where 1lirin1 \leq l_i \leq r_i \leq n for all 0i<q0 \leq i < q.

For each query, you have to find the beauty of the array v[li1]v[l_i - 1], v[li]v[l_i], \ldots, v[ri1]v[r_i - 1].

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.

10 2
1 1 2 2 3 3 1 2 3 4
1 6
1 9
1
2

提示

Constraints

  • 1n6000001 \leq n \leq 600000
  • 1q6000001 \leq q \leq 600000
  • 1v[i]4000001 \leq v[i] \leq 400000 for all 0i<n0 \leq i < n
  • 1lirin1 \leq l_i \leq r_i \leq n for all 0i<q0 \leq i < q

Subtasks

  1. (4 points) 1n10,1q1001 \leq n \leq 10, 1 \leq q \leq 100
  2. (6 points) 1n,q1001 \leq n, q \leq 100
  3. (17 points) 1n,q10001 \leq n, q \leq 1000
  4. (10 points) 1n,q1000001 \leq n, q \leq 100000 and 1v[i]21 \leq v[i] \leq 2 for all 0i<n0 \leq i < n
  5. (30 points) 1n,q750001 \leq n, q \leq 75000
  6. (33 points) No additional constraints.