Segment
题号:NC237465
时间限制:C/C++/Rust/Pascal 14秒,其他语言28秒
空间限制:C/C++/Rust/Pascal 512 M,其他语言1024 M
64bit IO Format: %lld

题目描述

Alice know how to solve the puzzle called counting game.

You are given an array a of n integers numbered from 1 to n.

You have to perform q queries.

For each query, you are given m_i subsegments. Suppose the left and the right endpoints of the i-th segment are l_i and r_i () respectively. You need to calculate the total number of pairs of integers (p,q), that .   

输入描述:

The first line contains two integer n,q (), denoting the length of the array a and the number of queries.

The second line contains n integers ().

Each of the following blocks of lines contains the description of one query. 
For each query, the first line contains an integer m_i, denotes the number of segments. The following m_i lines contains two integers l_i, r_i (), representing the m_i segments in the query.

It guaranteed that , .

输出描述:

For each query, output a number in a line indicating the answer.
示例1

输入

复制
5 2
5 4 2 3 1
3
1 1
2 3
4 4
2
1 2
3 4

输出

复制
1
0