#K62162. Count Unique Integers in Intervals
Count Unique Integers in Intervals
Count Unique Integers in Intervals
You are given n intervals, each represented by two integers a and b (where a ≤ b), which denote that the interval includes all integers between a and b (inclusive). Your task is to compute the number of unique integers that occur in exactly one interval.
Note: If an integer appears in more than one interval, it is not counted as unique. For example, if the intervals [1, 3]
and [2, 5]
are given, the integers 2 and 3 appear twice, so only 1, 4, and 5 are considered unique, thus the answer is 3.
Constraints: The range within each interval is small enough such that iterating over all integers in the interval is feasible.
inputFormat
The input is given from standard input (stdin) in the following format:
n a1 b1 ... an bn
Here, n
denotes the number of intervals. Each of the next n
lines contains two space-separated integers, a
and b
, representing an interval.
outputFormat
Output a single integer to standard output (stdout), representing the number of unique integers that appear exactly once among all the intervals.
## sample1
1 3
3
</p>