Question: #include using namespace std; /* * Complete the dynamicLineIntersection function below. */ void dynamicLineIntersection(int n) { /* * Write your code here. */ } int
#include
using namespace std;
/* * Complete the dynamicLineIntersection function below. */ void dynamicLineIntersection(int n) { /* * Write your code here. */
}
int main() { int n; cin >> n; cin.ignore(numeric_limits
dynamicLineIntersection(n);
return 0; }
You are tasked to analyze trend lines and predict some important metrics for the company, and you realize that the first step is to master the science of finding line intersections.
Initially, you have the Cartesian plane without any lines. You are given queries of three types:
- add the line with equation .
- remove the line with equation . It is guaranteed that the line exists.
- Find the number of lines that intersect with the line at a point with an integer -coordinate.
Complete the function dynamicLineIntersection which takes in an integer denoting the number of queries and prints the answer of each query in a single line. You will need to take the queries from the standard input.
Input Format
The first line contains one integer . The next lines contain one of the following queries:
Constraints
Output Format
For each query, print a single line containing a single integer denoting the answer to that query.
Sample Input 0
4 + 1 0 + 2 0 ? 1 ? 2
Sample Output 0
1 2
Explanation 0
Two lines have been added, with equations and .
In the first query, we want to find the number of lines that intersect with in a point with an integer -coordinate. The intersections with both lines are and , and only the first one has an integer -coordinate, so the answer is .
In the second query, we want to find the number of lines that intersect with in a point with an integer -coordinate. The intersections with both lines are and , and both points have integer -coordinates, so the answer is .
WAS ASKED TO FILL IN THE FUNCTION:
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
