#K8086. Frequency Tracker

    ID: 35624 Type: Default 1000ms 256MiB

Frequency Tracker

Frequency Tracker

You are required to design a data structure named FrequencyTracker that supports three operations:

  • Add: add(number) adds number to the data structure.
  • Remove: remove(number) removes one occurrence of number from the data structure if it exists.
  • Query: hasFrequency(frequency) checks whether there exists any number in the data structure with exactly the specified frequency. It returns true if such a number exists and false otherwise.

You will be given a sequence of operations through the standard input. Each operation is represented as a pair of integers. The first integer is the operation code, and the second is the argument:

  • 1: add number
  • 2: remove number
  • 3: query if any number appears exactly frequency times

For each query operation, output the result (true or false) on a separate line to the standard output.

All formulas are rendered in LaTeX format when referring to mathematical expressions. For instance, an operation count is denoted by \(Q\), and the frequency by \(f\).

inputFormat

The input is given via standard input, and it has the following format:

  1. The first line contains an integer \(Q\) denoting the number of operations.
  2. Each of the next \(Q\) lines contains two integers separated by space: the first one is the operation code and the second one is the argument.

Operation codes:

  • 1 x: Add the number \(x\) to the data structure.
  • 2 x: Remove one occurrence of the number \(x\) (if present).
  • 3 f: Query whether there is any number with frequency exactly \(f\). For this operation, you should output true or false on a separate line.

outputFormat

For each query operation (operation code 3), print a single line containing either true or false to the standard output.

## sample
6
1 3
1 3
3 2
2 3
3 2
3 1
true

false true

</p>