CF818C.Sofa Thief

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Yet another round on DecoForces is coming! Grandpa Maks wanted to participate in it but someone has stolen his precious sofa! And how can one perform well with such a major loss?

Fortunately, the thief had left a note for Grandpa Maks. This note got Maks to the sofa storehouse. Still he had no idea which sofa belongs to him as they all looked the same!

The storehouse is represented as matrix n×mn×m . Every sofa takes two neighbouring by some side cells. No cell is covered by more than one sofa. There can be empty cells.

Sofa AA is standing to the left of sofa BB if there exist two such cells aa and bb that x_{a}<x_{b} , aa is covered by AA and bb is covered by BB . Sofa AA is standing to the top of sofa BB if there exist two such cells aa and bb that y_{a}<y_{b} , aa is covered by AA and bb is covered by BB . Right and bottom conditions are declared the same way.

Note that in all conditions ABA≠B . Also some sofa AA can be both to the top of another sofa BB and to the bottom of it. The same is for left and right conditions.

The note also stated that there are cntlcnt_{l} sofas to the left of Grandpa Maks's sofa, cntrcnt_{r} — to the right, cnttcnt_{t} — to the top and cntbcnt_{b} — to the bottom.

Grandpa Maks asks you to help him to identify his sofa. It is guaranteed that there is no more than one sofa of given conditions.

Output the number of Grandpa Maks's sofa. If there is no such sofa that all the conditions are met for it then output -1.

输入格式

The first line contains one integer number dd ( 1<=d<=1051<=d<=10^{5} ) — the number of sofas in the storehouse.

The second line contains two integer numbers nn , mm ( 1<=n,m<=1051<=n,m<=10^{5} ) — the size of the storehouse.

Next dd lines contains four integer numbers x1x_{1} , y1y_{1} , x2x_{2} , y2y_{2} ( 1<=x1,x2<=n1<=x_{1},x_{2}<=n , 1<=y1,y2<=m1<=y_{1},y_{2}<=m ) — coordinates of the ii -th sofa. It is guaranteed that cells ( x1,y1x_{1},y_{1} ) and ( x2,y2x_{2},y_{2} ) have common side, ( x1,y1x_{1},y_{1} ) ( x2,y2x_{2},y_{2} ) and no cell is covered by more than one sofa.

The last line contains four integer numbers cntlcnt_{l} , cntrcnt_{r} , cnttcnt_{t} , cntbcnt_{b} ( 0<=cntl,cntr,cntt,cntb<=d10<=cnt_{l},cnt_{r},cnt_{t},cnt_{b}<=d-1 ).

输出格式

Print the number of the sofa for which all the conditions are met. Sofas are numbered 11 through dd as given in input. If there is no such sofa then print -1.

输入输出样例

  • 输入#1

    2
    3 2
    3 1 3 2
    1 2 2 2
    1 0 0 1
    

    输出#1

    1
    
  • 输入#2

    3
    10 10
    1 2 1 1
    5 5 6 5
    6 4 5 4
    2 1 2 0
    

    输出#2

    2
    
  • 输入#3

    2
    2 2
    2 1 1 1
    1 2 2 2
    1 0 0 0
    

    输出#3

    -1
    

说明/提示

Let's consider the second example.

  • The first sofa has 00 to its left, 22 sofas to its right ( (1,1)(1,1) is to the left of both (5,5)(5,5) and (5,4)(5,4) ), 00 to its top and 22 to its bottom (both 22 nd and 33 rd sofas are below).
  • The second sofa has cntl=2cnt_{l}=2 , cntr=1cnt_{r}=1 , cntt=2cnt_{t}=2 and cntb=0cnt_{b}=0 .
  • The third sofa has cntl=2cnt_{l}=2 , cntr=1cnt_{r}=1 , cntt=1cnt_{t}=1 and cntb=1cnt_{b}=1 .

So the second one corresponds to the given conditions.

In the third example

  • The first sofa has cntl=1cnt_{l}=1 , cntr=1cnt_{r}=1 , cntt=0cnt_{t}=0 and cntb=1cnt_{b}=1 .
  • The second sofa has cntl=1cnt_{l}=1 , cntr=1cnt_{r}=1 , cntt=1cnt_{t}=1 and cntb=0cnt_{b}=0 .

And there is no sofa with the set (1,0,0,0)(1,0,0,0) so the answer is -1.

首页