RoAlgo PreOJI 2024 XI-XII | Dominant

This was the problem page during the contest. Access the current page here.
Time limit: 1s Memory limit: 256MB Input: dominant.in Output: dominant.out

Task

A sequence s1,s2,,sks_1, s_2, \ldots, s_k of natural numbers is called xyxy-dominant for given values xx and yy if:

  1. There are at least xx distinct numbers in the sequence.
  2. We can choose xx distinct numbers from the sequence such that the sum of their frequencies is greater than or equal to yy.

For example, for x=2x=2 and y=4y=4:

  • The sequence [1,2,1,2,3][1,2,1,2,3] is xyxy-dominant (we can choose the numbers 11 and 22, which appear a total of 2+2=42+2=4 times in the sequence).
  • The sequence [1,1,1,1][1,1,1,1] is not xyxy-dominant (there are not two distinct values in the sequence).
  • The sequence [1,2,1,3][1,2,1,3] is not xyxy-dominant (there are not two distinct values in the sequence that appear a total of at least 44 times).

Given n,x,yn, x, y, and a sequence of natural numbers a1,a2,,ana_1, a_2, \ldots, a_n,

Find the number of xyxy-dominant subarrays of the sequence aa.

Input data

The first line of the file dominant.in contains the numbers nn, xx, and yy.

The second line contains the sequence a1,a2,,ana_1, a_2, \ldots, a_n.

Output data

The first line of the file dominant.out will display the number of xyxy-dominant subarrays of the sequence aa.

Constraints and clarifications

  • 1n31051 \leq n \leq 3 \cdot 10^5
  • 1x1 \leq x \leq number of distinct values in the sequence aa
  • 1y,ain1 \leq y, a_i \leq n
  • To obtain points for a specific subtask, at least one source sent must pass all tests in that subtask.
# Points Constraints
0 0 Examples
1 25 1n3001 \leq n \leq 300
2 22 1n3 0001 \leq n \leq 3 \ 000
3 16 y=1y = 1
4 19 x=1x = 1
5 18 No other constraints

Example 1

dominant.in

4 3 1
1 2 3 4

dominant.out

3

Explanation

The xyxy-dominant subarrays are [1,2,3][1,2,3], [2,3,4][2,3,4], and [1,2,3,4][1,2,3,4].

Example 2

dominant.in

10 2 4
1 1 1 2 1 2 2 2 1 2

dominant.out

28

Explanation

There are a total of KaTeX parse error: Can't use function '$' in math mode at position 3: 28$̲ xydominantsubarrays,including*-dominant* subarrays, including [1,1,1,2],, [2,1,2,2],and, and [1,1,1,2,1,2,2,2,1,2]$.

Example 3

dominant.in

14 3 8
5 3 5 1 4 5 1 4 2 2 4 5 4 4

dominant.out

15

Explanation

There are a total of KaTeX parse error: Can't use function '$' in math mode at position 3: 15$̲ xydominantsubarrays,suchas*-dominant* subarrays, such as [5,3,5,1,4,5,1,4,2,2,4]$.

Log in or sign up to be able to send submissions!