#P2082. 区间覆盖(加强版)

区间覆盖(加强版)

Description

Given NN intervals, each with range [si,ti][s_i, t_i], compute the total length of the union of these intervals.

Input Format

The first line contains a positive integer NN, representing the number of intervals. Then NN lines follow, each containing two positive integers, representing sis_i and tit_i.

Output Format

Output one line with a single positive integer, which is the total length of the union after covering the intervals.

3
1 100000
200001 1000000
100000000 100000001
900002

Hint

For 40%40 \% of the testdata, N1000N \le 1000, 1si<ti100001 \le s_i < t_i \le 10000. For 100%100 \% of the testdata, N105N \le 10^5, 1si<ti10171 \le s_i < t_i \le 10^{17}.

Translated by ChatGPT 5