#573. 「Nowcoder多校 2019 Day2」Subarray

「Nowcoder多校 2019 Day2」Subarray

当前没有测试数据。

题目描述

Given an array A of length 10910^9containing only 1 and -1. The number of 1 is not more than 10710^7. Please count how many pairs of (l, r) satisfy i=lrAi>0\sum\limits_{i=l}^r A_i > 0 and 0lr<1090 \leq l \leq r < 10^9

输入格式

The first line of input contains an integers N indicating how many segments of A is 1. Following N lines each contains two space-separated integers li,ril_i, r_i indicating that AjA_j is 1 for lijril_i \leq j \leq r_i

输出格式

Output one line containing an integer representing the answer.

样例

样例输入 1

1
0 1

样例输出 1

4

样例输入 2

1
1 2

样例输出 2

5

样例输入 3

2
0 1
3 4

样例输出 3

16

数据范围与提示

0<n1060<n≤106

liril_i \leq r_i

ri+1<li+1r_i + 1 < l_{i+1} for 0i<n10 \leq i < n - 1

0l00 \leq l_0

rn1<109r_{n-1} < 10^9

(rili+1)107\sum (r_i - l_i + 1) \leq 10^7