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:  ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.3.2, CPP 4.9.2, CPP14, CS2, D, ERL, FORT, FS, GO, HASK, ICK, ICON, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, NODEJS, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.4, RUBY, SCALA, SCM guile, SCM qobi, ST, TCL, TEXT, WSPC 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions