Tears

아직 제출이 없습니다시간 제한4초메모리 제한1024 MB

문제

Let (a,b)(c,d)(a,b) \le (c,d) denote two points (a,b),(c,d)(a,b),(c,d) on the plane satisfies ac,bda \le c,b \le d. There are nn events denoted by nn distinct points (x_i,y_i)_i=1n\\{(x\_i,y\_i)\\}\_{i=1}^n on the plane. There are mm epochs denoted by a rectangle (r_i,1,r_i,2,c_i,1,c_i,2)(r\_{i,1},r\_{i,2},c\_{i,1},c\_{i,2}) where (r_i,1,c_i,1)(r\_{i,1},c\_{i,1}) is the bottom-left corner of the rectangle and (r_i,2,c_i,2)(r\_{i,2},c\_{i,2}) is the upper-right corner, and it is guaranteed that (r_i,1,c_i,1)(r_i,2,c_i,2)(r\_{i,1},c\_{i,1}) \le (r\_{i,2},c\_{i,2}). We say epoch ii includes event jj if and only if (r_i,1,c_i,1)(x_j,y_j)(r_i,2,c_i,2)(r\_{i,1},c\_{i,1}) \le (x\_j,y\_j) \le (r\_{i,2},c\_{i,2}).

If two events i,ji,j satisfy (x_i,y_i)(x_j,y_j)(x\_i,y\_i) \le (x\_j,y\_j), then the two events constitute an occurrence of sadness. For all events in an epoch, the occurrences of sadness are called the tear of the epoch, and the size of the tear of the epoch is measured by the number of occurrences of sadness. We'd like to compute the size of the tears of the epochs.

입력

The first line contains two integers n,mn,m denoting the number of events and the number of epochs. The second line contains nn integers p_ip\_i, and the ii-th number denotes event ii has coordinate (i,p_i)(i,p\_i) on the plane. It is guaranteed that p_ip\_i is a permutation of 1,2,,n1, 2, \dots, n. In the following mm lines, each line contains four integers r_i,1,r_i,2,c_i,1,c_i,2r\_{i,1},r\_{i,2},c\_{i,1},c\_{i,2} denoting the rectangle corresponding to the epoch.

출력

There are mm lines and each line contains an integer. The ii-th line denotes the size of the tear of epoch ii.

제한

For all test cases, 1n1051 \le n \le 10^51m2×1051 \le m \le 2 \times 10^51r_i,1,r_i,2,c_i,1,c_i,2n1 \le r\_{i,1}, r\_{i,2}, c\_{i,1}, c\_{i,2} \le n.