Perpendicular Lines

3.7

859 votes
HashMap, Geometry, Easy-Medium, Hash table, Ready, Mathematics, Open, Approved
Problem

Foo gave Bar N lines in the 2D plane, of the form ax+by+c=0. He decided to ask Q questions to Bar. In every question, he would select a line, and Bar will have to find out how many lines are perpendicular to the line selected by Foo. Help Bar in answering the questions.

Input:
First line contains a single integer N - the total number of lines given by Foo to Bar.
N lines follow - each line contains 3 space separated integers: a, b and c, representing the line ax+by+c=0.
Next line contains a single integer Q - the number of questions asked by Foo to Bar.
Q lines follow - each line contains an index between 1 and N (inclusive) - denoting the line selected by Foo.

Output:
Print the number of lines perpendicular to the line selected by Foo.
Print the answer to each question asked by Foo on a new line.

Constraints:
1N105
10-9a, b, c109
1Q105

Note: All triplets (a, b, c) in the input denote valid straight lines.

Sample Input
4
1 1 1
-1 1 1
1 2 3
3 4 5
4
1
2
3
4
Sample Output
1
1
0
0
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Lines 1 and 2 are perpendicular to each other.

Editor Image

?