列表

详情


NC237465. Segment

描述

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

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

上一题