A10899 | Beautiful fountains rows
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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)$ .
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)$ .
输入格式
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.
$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.
输出格式
Print one integer: the total length of all suitable segments.
输入输出样例
输入 #1
1 5 2 4
输出 #1
23
输入 #2
3 6 2 4 3 6 4 4
输出 #2
19
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)$ .
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)$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted