#P8441. The Unique Contest Problem
The Unique Contest Problem
The Unique Contest Problem
You are given a sequence of n sets a1, a2, ..., an. Initially, every set is empty. The sets are distinct in that they are standard mathematical sets which do not contain duplicate elements.
You need to support the following two types of operations:
- Update operation: Given three integers l, r and x, for every index i with l ≤ i ≤ r add the element x to the set ai. Mathematically, for each i in [l, r]:</p>
\(a_i = a_i \cup {\, x \,}\)
- Query operation: Given two integers l and r, let S be the union of all sets from al to ar (i.e. S = al \cup al+1 \cup \cdots \cup ar), and you must output the sum of all elements in S.
Good luck solving this challenge!
inputFormat
The first line contains two integers n and q (1 ≤ n, q ≤ some small number).
Each of the following q lines describes an operation.
- If the operation is an update, the line will contain four integers:
1 l r x
. - If the operation is a query, the line will contain three integers:
2 l r
.
It is guaranteed that the indices use 1-indexing.
outputFormat
For each query operation, print a single line containing the sum of the distinct elements in the union set defined by the query.
sample
5 5
1 1 3 4
1 2 5 3
2 1 5
1 3 3 5
2 1 3
7
12
</p>