Official

C - One Sky, Many Stars Editorial by evima

Another Solution

Although it is inferior to the main solution in terms of implementation volume and time complexity, we introduce a solution that can be obtained through natural reasoning without using the special properties of this problem.

As in the main editorial, person $i$'s testimony yields the following constraints.

  • At least one of the coordinates $x_i - d_i, x_i + d_i$ has a star.
  • None of the coordinates $x_i - d_i + 1, x_i - d_i + 2, \cdots, x_i + d_i - 1$ has a star.

In other words, the problem Stargazing can be regarded as defining the interval $I_i$ as the open interval $(x_i - d_i, x_i + d_i)$, and determining whether, for every $i$, "$x_i - d_i \notin I_j$ for every $j$" or "$x_i + d_i \notin I_j$ for every $j$" holds. Here, since only the relative positions of $x_i - d_i, x_i + d_i$ matter, we consider reading the queries in advance and performing coordinate compression. Since there are $O(N + Q)$ kinds of coordinates, this can be done as preprocessing in $O((N + Q) \log (N + Q))$.

Consider processing the queries in blocks of $q$ queries. Among the $q$ queries, consider the people whose $d$ does not change as red, and those whose $d$ changes as blue. We also consider the indices of people and the intervals to be colored in the same way.
First, compute whether a contradiction already arises among the red people alone. This can be done by adding $1$ to the interval $(x_i - d_i, x_i + d_i)$ and then checking whether the values added at coordinates $x_i - d_i, x_i + d_i$ are $0$. Using the values after coordinate compression, this can be checked in $O(N + Q)$ by prefix sums. When no contradiction arises, each red person yields one of the following three constraints.

  • "$x_i - d_i \notin I_j$ for every blue $j$" is necessary and sufficient.
  • "$x_i + d_i \notin I_j$ for every blue $j$" is necessary and sufficient.
  • "$x_i - d_i \notin I_j$ for every blue $j$" or "$x_i + d_i \notin I_j$ for every blue $j$" is necessary and sufficient.

The first two conditions can be rephrased as: there are points $p_i$, and $I_j$ must not contain any $p_i$. In other words, for the left endpoint of $I_j$, the upper limit of the value that can be taken as the right endpoint is determined. This can be computed in $O(N + Q)$.
For the third condition, when no contradiction arises, $x_i - d_i, x_i + d_i$ are each monotonically non-decreasing, so the $i$ contained in $I_j$ each form an interval. For the proof of this part, refer to the main editorial.

Consider performing similar computations for the blue people. First, since the number of kinds of coordinates to consider due to blue people is $O(q)$, we perform coordinate compression on these again before processing the $q$ queries. This can be done in $O(q \log q)$.
Also, since there are $O(q)$ possible $I_j$ in the $q$ queries, we compute the interval of $i$ contained in each such $I_j$. This can be done in, for example, $O(q \log N)$. We perform coordinate compression on the endpoints of the intervals. This can be done in, for example, $O(q \log q)$.
For each query, compute whether a contradiction already arises among the blue people alone. This can be done in $O(q)$ as above.
Whether the testimonies of red people make the stars required by blue people impossible to place, and whether the testimonies of blue people make the stars required by red people impossible to place, can both be computed in $O(q)$.

In the end, we found that with sqrt decomposition on queries, it can be solved in $O(N + Q + q^2 + q \log N)$ per $q$ queries. That is, the overall complexity is $O((N + Q) \log (N + Q) + \frac{Q}{q}(N + Q + q^2))$, and setting $q = \Theta(\sqrt{Q})$ gives $O((N + Q) ( \log(N + Q) + \sqrt{Q} ))$.
We confirmed that it gets AC in around 1.5 seconds with bucket sizes in the range of 300 to 900, but it may result in TLE due to factors such as using a slow language, not paying attention to constant factors, or having an extra $\log$ in the complexity.

Sample Implementation (C++)