Codeforces Round 837 (Div. 2)
B
Hossam and Friends
Codeforces
1400
原题
← AC →
翻译中…

Hossam makes a big party, and he will invite his friends to the party.

翻译中…

He has $n$ friends numbered from $1$ to $n$. They will be arranged in a queue as follows: $1, 2, 3, \ldots, n$.

翻译中…

Hossam has a list of $m$ pairs of his friends that don't know each other. Any pair not present in this list are friends.

翻译中…

A subsegment of the queue starting from the friend $a$ and ending at the friend $b$ is $[a, a + 1, a + 2, \ldots, b]$. A subsegment of the queue is called good when all pairs of that segment are friends.

翻译中…

Hossam wants to know how many pairs $(a, b)$ there are ($1 \le a \le b \le n$), such that the subsegment starting from the friend $a$ and ending at the friend $b$ is good.

翻译中…

Input

翻译中…

The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \le t \le 2 \cdot 10^4$), the number of test cases. Description of the test cases follows.

翻译中…

The first line of each test case contains two integer numbers $n$ and $m$ ($2 \le n \le 10^5$, $0 \le m \le 10^5$) representing the number of friends and the number of pairs, respectively.

翻译中…

The $i$-th of the next $m$ lines contains two integers $x_i$ and $y_i$ ($1 \le x_i, y_i\le n$, $x_i \neq y_i$) representing a pair of Hossam's friends that don't know each other.

翻译中…

Note that pairs can be repeated.

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$, and the sum of $m$ over all test cases does not exceed $10^5$.

翻译中…

Output

翻译中…

For each test case print an integer — the number of good subsegments.

翻译中…

Note

翻译中…

In the first example, the answer is $4$.

翻译中…

The good subsegments are:

翻译中…

[1]

翻译中…

[2]

翻译中…

[3]

翻译中…

[1, 2]

翻译中…

In the second example, the answer is $5$.

翻译中…

The good subsegments are:

翻译中…

[1]

翻译中…

[2]

翻译中…

[3]

翻译中…

[4]

翻译中…

[3, 4]

翻译中…

样例

Input #1
2
3 2
1 3
2 3
4 2
1 2
2 3
Output #1
4
5
InputCopy OutputCopy
题目信息
题号
1771B
时间限制
2 s
内存限制
256 MB
标签
二分
构造
动态规划
双指针

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