CF799F.Beautiful fountains rows

NOI/NOI+/CTSC

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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).

巴特勒·奥斯汀想向阿尔卡季证明:奇数个喷泉排成的一行是美丽的,而偶数个喷泉排成的一行则不美丽。

奥斯汀想向阿尔卡季展示 nn 个花园。每个花园是一行 mm 个格子,第 ii 个花园在区间 [li,ri][l_i, r_i] 内的每个格子中均有一个喷泉,且该花园中再无其他喷泉。问题在于,某些花园包含偶数个喷泉,向阿尔卡季展示它们是错误的。

奥斯汀希望选择两个整数 a≤ba \leq b,并仅向阿尔卡季展示每个花园中从第 aa 个格子到第 bb 个格子的子段。当然,只有满足如下条件的子段 [a,b][a, b] 才符合奥斯汀的要求:每个花园在此子段内所含喷泉数量为 00 或奇数。此外,还必须保证至少有一个花园在子段 [a,b][a, b] 内至少含有一个喷泉。

请帮助奥斯汀计算所有满足条件的子段的总长度,即对每个符合条件的数对 (a,b)(a, b),求和 (b−a+1)(b - a + 1)。

输入格式

The first line contains two integers n and m (1 ≤ n, m ≤ 2·105) — 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.

第一行包含两个整数 nn 和 mm(1≤n,m≤2⋅1051 \leq n, m \leq 2 \cdot 10^5)—— 分别表示花园的数量以及每个花园的长度。

接下来有 nn 行。其中第 ii 行包含两个整数 lil_i 和 rir_i(1≤li≤ri≤m1 \leq l_i \leq r_i \leq m)—— 表示第 ii 个花园中喷泉所在区间的左右端点。

输出格式

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).

在第一个例子中,满足奥斯汀的数对 (a, b)(a,\,b) 有:(1, 2)(1,\,2)、(1, 4)(1,\,4)、(1, 5)(1,\,5)、(2, 2)(2,\,2)、(2, 4)(2,\,4)、(2, 5)(2,\,5)、(3, 3)(3,\,3)、(4, 4)(4,\,4)、(4, 5)(4,\,5)。

在第二个例子中,满足奥斯汀的数对 (a, b)(a,\,b) 有:(1, 2)(1,\,2)、(1, 5)(1,\,5)、(2, 2)(2,\,2)、(2, 5)(2,\,5)、(3, 3)(3,\,3)、(4, 4)(4,\,4)、(4, 6)(4,\,6)、(5, 5)(5,\,5)、(6, 6)(6,\,6)。

输入解题思路,AI测评打分。不知道怎么写?

首页