NOI '20 P3 - Tears

View as PDF

Submit solution

Points: 40 (partial)
Time limit: 4.0s
Memory limit: 1G

Problem type

Let (a,b)(c,d) denote two points (a,b),(c,d) on the plane satisfies ac,bd. There are n events denoted by n distinct points {(xi,yi)}i=1n on the plane. There are m epochs denoted by a rectangle (ri,1,ri,2,ci,1,ci,2) where (ri,1,ci,1) is the bottom-left corner of the rectangle and (ri,2,ci,2) is the upper-right corner, and it is guaranteed that (ri,1,ci,1)(ri,2,ci,2). We say epoch i includes event j if and only if (ri,1,ci,1)(xj,yj)(ri,2,ci,2).

If two events i,j satisfy (xi,yi)(xj,yj), 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.

Input Specification

The first line contains two integers n,m denoting the number of events and the number of epochs. The second line contains n integers pi, and the i-th number denotes event i has coordinate (i,pi) on the plane. It is guaranteed that pi is a permutation of 1,2,,n. In the following m lines, each line contains four integers ri,1,ri,2,ci,1,ci,2 denoting the rectangle corresponding to the epoch.

Output Specification

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

Sample Input 1

Copy
9 9
9 8 7 6 2 4 5 3 1
4 9 3 6
2 9 1 8
3 8 2 4
3 9 2 7
2 8 1 6
1 9 1 9
1 3 5 7
2 3 3 3
6 6 6 6

Sample Output 1

Copy
1
4
2
4
4
4
0
0
0

Constraints

For all test cases, 1n105, 1m2×105, 1ri,1,ri,2,ci,1,ci,2n.

Test CasenmAdditional Constraints
1~31010None.
430003000
540004000
650005000
72500025000For every epoch i, we have ci,1=1 and ci,2=n.
850000100000
975000150000
10100000200000
1160000120000For any two rectangles representing different epochs, either one is contained in another (the boundaries may overlap) or they are disjoint.
1280000160000
13100000200000
142000020000None.
153000030000
164000040000
175000050000
186000060000
197000070000
20~22100000200000There exists at most 50 pairs of events (i,j) (1i<jn) that do not satisfy (i,pi)(j,pj).
23~25100000200000None.

Comments

There are no comments at the moment.