OpenAIOA #2
Bacteria Coexistence (bioHazard)
估计中等可在线判题
The samples are arranged by number from 1 to n. The two samples of any conflicting pair cannot both appear in a range, and direction does not matter for a conflict. Count the valid non-empty contiguous ranges; the samples cannot be reordered. Duplicate conflicts are not subtracted twice.
输入格式
The first line contains n m, followed by m lines each with a b, denoting a conflicting pair. This site uses 1≤n≤200000, 0≤m≤200000, 1≤a,b≤n, and a≠b; duplicates and reversed duplicates are allowed.
输出格式
The number of valid ranges, as a 64-bit integer.
样例 1
输入:
3 3
2 3
1 3
3 1
输出:
4
样例 2
输入:
4 0
输出:
10
样例 3
输入:
4 3
1 4
4 1
2 3
输出:
6
样例说明
In Example 1, the valid ranges are the three single points and [1,2], for 4 in total. In Example 2, all 10 ranges are valid. In Example 3, the duplicated reversed relation counts as one, and there are 6 valid ranges in total.