#K85357. Unique Element Updates

    ID: 36623 Type: Default 1000ms 256MiB

Unique Element Updates

Unique Element Updates

You are given an array of N integers and M queries. Each query updates the array by removing all occurrences of a specific integer x and replacing them with x_new. The update rule for each query is defined as follows:

( \text{If } q = 1, \text{ then } x_{new} = x + k ) ( \text{If } q = 2, \text{ then } x_{new} = x - k )

After processing all queries, you are required to output the number of unique elements present in the array.

For example, consider the array [1, 2, 2, 3, 4, 4] with 3 queries:

  1. (1, 2, 1): change all 2's to 3's
  2. (2, 3, 1): change all 3's to 2's
  3. (1, 4, 2): change all 4's to 6's The unique elements in the final array [1, 2, 6] are 3 in number.

inputFormat

The input is read from standard input and consists of multiple lines: The first line contains two integers N and M, where N is the number of elements in the array, and M is the number of queries. The second line contains N space-separated integers representing the array. The next M lines each contain three space-separated integers: q, x, and k, indicating a query. (q = 1) means increment operation (i.e. add (k)) and (q = 2) means decrement operation (i.e. subtract (k)).

outputFormat

Output a single integer to standard output: the number of unique elements in the array after processing all the queries.## sample

6 3
1 2 2 3 4 4
1 2 1
2 3 1
1 4 2
3