Playrix Codescapes Cup (Codeforces Round 413, rated, Div. 1 + Div. 2)
F
Beautiful fountains rows
Codeforces
3500
原题
← EG →
翻译中…

Butler Ostin wants to show Arkady that rows of odd number of fountains are beautiful, while rows of even number of fountains are not.

翻译中…

The butler wants to show Arkady $*n*$ gardens. Each garden is a row of $*m*$ cells, the $*i*$-th garden has one fountain in each of the cells between $*l*_{*i*}$ and $*r*_{*i*}$ inclusive, and there are no more fountains in that garden. The issue is that some of the gardens contain even number of fountains, it is wrong to show them to Arkady.

翻译中…

Ostin wants to choose two integers $*a* ≤ *b*$ and show only part of each of the gardens that starts at cell $*a*$ and ends at cell $*b*$. Of course, only such segments suit Ostin that each garden has either zero or odd number of fountains on this segment. Also, it is necessary that at least one garden has at least one fountain on the segment from $*a*$ to $*b*$.

翻译中…

Help Ostin to find the total length of all such segments, i.e. sum up the value $(*b* - *a* + 1)$ for each suitable pair $(*a*, *b*)$.

翻译中…

Input

翻译中…

The first line contains two integers $*n*$ and $*m*$ ($1 ≤ *n*, *m* ≤ 2·10^{5}$) — the number of gardens and the length of each garden.

翻译中…

$*n*$ lines follow. The $*i*$-th of these lines contains two integers $*l*_{*i*}$ and $*r*_{*i*}$ ($1 ≤ *l*_{*i*} ≤ *r*_{*i*} ≤ *m*$) — the bounds of the segment that contains fountains in the $*i*$-th garden.

翻译中…

Output

翻译中…

Print one integer: the total length of all suitable segments.

翻译中…

Note

翻译中…

In the first example the following pairs suit Ostin: $(*a*, *b*)$: $(1, 2)$, $(1, 4)$, $(1, 5)$, $(2, 2)$, $(2, 4)$, $(2, 5)$, $(3, 3)$, $(4, 4)$, $(4, 5)$.

翻译中…

In the second example the following pairs suit Ostin: $(*a*, *b*)$: $(1, 2)$, $(1, 5)$, $(2, 2)$, $(2, 5)$, $(3, 3)$, $(4, 4)$, $(4, 6)$, $(5, 5)$, $(6, 6)$.

翻译中…

样例

Input #1
1 5
2 4
Output #1
23
InputCopy OutputCopy
Input #2
3 6
2 4
3 6
4 4
Output #2
19
InputCopy OutputCopy
题目信息
题号
799F
时间限制
3 s
内存限制
256 MB
标签
数据结构

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。