The initial setting consists of the Cartesian plane without any lines. After that we're are given $n$ queries of the form:
$\bullet$ $k$ $b$ $+$ add the line with equation $y$ = $kx + b$ to the plane
$\bullet$ $k$ $b$ $-$ remove the line with equation $y = kx + b$ from the plane
$\bullet$ $?q$ find the number of lines $y= q$ that are currently on the plane at a point with an integer $x$-coordinate
All the aforementioned parameters are always integers. There can be up to $n = 10^5$ queries and $0 \leq b, q \leq 10^5$.
I've no idea how to come up with a solution that's better than $O(n^2)$ which is too slow. The key insight I've been able to extract up to this point is that in order for a line to satisfy the given constraints, the following must hold:
$$q \equiv b \text{ (mod k)}$$
But this doesn't seem particularly useful, since I still have to go through all the lines I've encountered so far.
Since this seems to be some kind of number theory, modulo arithmetic question, I figure there may be some solution of complexity $O(n\sqrt{n})$, but I haven't been able to arrive at it no matter how much I played with the data.
Here is an approach that takes $O(\sqrt n)$ time for each query, so $O(n \sqrt n)$ time total.
Divide lines into lines with a gentle slope (a nonzero slope less than $\sqrt n$ in absolute value) and a steep slope (a slope greater than $\sqrt n$ in absolute value, or, awkwardly, slope $0$).
The idea is that there are very few gentle slopes, so we can afford to just store a count of how many times we've added each possible unique line with gentle slope. (We replace $k$ by $|k|$ and $b$ by $b\bmod k$, if necessary, since this doesn't affect anything.)
On the other hand, there are infinitely many lines with steep slopes, but each one intersects only a few lines $y=q$ at an integer point. So we can just have an array indexed by $0,1,\dots,n$, and at the $q^{\text{th}}$ position, record how many lines with steep slopes intersect $y=q$ at an integer coordinate. This can be updated in $O(\sqrt n)$ time when a line is added or removed: just compute $y=kx+b$ for $x=0,1,\dots, \lfloor \frac nk\rfloor$.
Finally, to check how many lines intersect $y=q$ at an integer coordinate, we handle all steep lines with a single array access, and handle each gentle slope separately. There are $O(\sqrt n)$ gentle slopes, so this takes $O(\sqrt n)$ time.