Triangular Logs

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

문제

The local forest has a lot of trees! Each tree is located at integer coordinates and has an integer height. Cutting down any tree gives you a log with a length equal to its height. You want to obtain three triangular logs (that is, three logs that form a non-degenerate triangle) by cutting down three trees.

Given a list of queries which each specify an axis-aligned rectangular region, can you obtain three triangular logs by cutting down three trees in that region, possibly including those on the boundary of the rectangle?

입력

The first line of input contains two integers nn and qq (1n,q1051 \le n,q \le 10^5), where nn is the number of trees and qq is the number of queries.

Each of the next nn lines contains three integers xx, yy and hh (1x,y,h1091 \le x,y,h \le 10^9), which describes a tree at location (x,yx,y) with height hh. All tree locations are distinct.

Each of the next qq lines contains four integers x_lowx\_{low}, y_lowy\_{low}, x_highx\_{high} and y_highy\_{high} (1x_lowx_high1091 \le x\_{low} \le x\_{high} \le 10^9, 1y_lowy_high1091 \le y\_{low} \le y\_{high} \le 10^9), describing an axis-aligned rectangular region for a query.

출력

Output qq lines. Each line contains a single integer, which is the answer to the given query. Output 1 if there are three trees in the queried region that can form a non-degenerate triangle, and 0 otherwise. Output answers to the queries in the order of the input.