Triangular Queries

All submissions for this problem are available.
You are given N lattice points (X_{i}, Y_{i}), i = 1, 2, ..., N on a 2D Coordinate System.
You have to process Q queries, each query will be given as the form "x y d".
Let ABC be the triangle having vertices at A(x+d, y), B(x, y) and C(x, y+d).
For each query, you have to find how many of the given lattice points lie inside or on the boundary of the triangle ABC.
Input
The first line of the input contains two spacesparated integers N and Q.
Each of the following N lines have two spacesparated integers X_{i}, Y_{i} giving the x and y coordinate of a lattice point.
Then the following Q lines contain three spacesparated integers x, y, d giving a query.
Output
For each query, output one integer on a line which denotes the number of the given lattice points which lie inside or on the boundary of the triangle.
Constraints
1 ≤ N ≤ 300000 (3 * 10^{5})
1 ≤ Q ≤ 200000 (2 * 10^{5})
1 ≤ X_{i}, Y_{i} ≤ 300000 (3 * 10^{5})
1 ≤ x, y, d ≤ 300000 (3 * 10^{5})
Sample
Input 1: 5 3 1 3 1 5 3 6 4 4 2 6 1 5 3 1 5 4 1 1 1 Output 1: 3 3 0 Input 2: 2 2 1 5 3 7 2 5 6 2 3 4 Output 2: 1 0
Author:  rustinpiece 
Tester:  laycurse 
Editorial  http://discuss.codechef.com/problems/TRIQUERY 
Tags  feb13, linesweep, medium, rustinpiece 
Date Added:  4112012 
Time Limit:  1 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.5, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, CLOJ, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 