#K76517. Candy Distribution Queries

    ID: 34660 Type: Default 1000ms 256MiB

Candy Distribution Queries

Candy Distribution Queries

You are given n students and their respective candies counts. The candy counts are represented as an array \(a = [a_1, a_2, \ldots, a_n]\), where \(a_i\) is the number of candies student \(i\) has.

You will also be given \(q\) queries. There are three types of queries:

  • Type 1: "1 i j" - Student \(i\) gives one candy to student \(j\) if and only if \(a_i > a_j\). That is, the transfer happens only if the donor has strictly more candies than the receiver.
  • Type 2: "2 i" - Print the current number of candies of student \(i\).
  • Type 3: "3" - Print the minimum and maximum candies among all students (in that order, separated by a space).

Process the queries sequentially and output each result for queries of type 2 and type 3 to the standard output.

inputFormat

The first line contains two integers \(n\) and \(q\) \( (1 \leq n, q \leq 10^5 )\) representing the number of students and the number of queries, respectively.

The second line contains \(n\) integers, representing the initial number of candies for each student.

The following \(q\) lines each contain a query in one of the following formats:

  • Type 1: 1 i j
  • Type 2: 2 i
  • Type 3: 3

Note: \(i\) and \(j\) are 1-indexed.

outputFormat

For each query of type 2, output the number of candies that student \(i\) currently has.

For each query of type 3, output two integers separated by a space: the minimum and maximum number of candies among all students.

Each output should be printed on a new line in the order the queries appear.

## sample
5 7
5 3 7 8 2
2 1
1 3 1
2 1
3
1 4 2
2 4
3
5

6 2 8 7 2 7

</p>