P17023 [ROI 2026 Day2] Night, Street, Streetlights, Pharmacy

Description

On a long street, there are some lamp posts with $n$ streetlights installed. We set up a coordinate system along the street. The lamp post of the $i$-th streetlight is located at coordinate $x_i$. In the first six subtasks of this problem (worth 85 points in total), no two streetlights are installed on the same lamp post, i.e. all $x_i$ are distinct. In the last two subtasks, each lamp post can have at most two streetlights. To light up the street, we can turn on some of the streetlights. If the $i$-th streetlight is turned on, it has **brightness** $s_i$. When it shines, starting from its lamp post, it can illuminate a continuous segment of the street with length $s_i$ meters. Each turned-on streetlight can be oriented either to the left or to the right. If the $i$-th streetlight shines to the left, it illuminates the interval $[x_i - s_i, x_i]$; if it shines to the right, it illuminates the interval $[x_i, x_i + s_i]$. We choose a non-empty set of streetlights to illuminate a segment of the street. If it is possible to choose, for every streetlight in the set, whether it shines left or right so that the following two conditions hold at the same time, then the set is called **economical**: - The illuminated intervals can be joined into one continuous street interval. - No non-zero-length interval is illuminated by two or more streetlights at the same time. The figure below shows an economical subset with two streetlights in Sample 2 and one way to illuminate a continuous interval. The brightness of each streetlight is labeled above it. :::align{center} ![](https://cdn.luogu.com.cn/upload/image_hosting/u6jmcl8w.png) ::: Please compute the number of economical subsets of streetlights. Output the answer modulo $10^9 + 7$.

Input Format

The first line contains an integer $n$ ($1 \le n \le 10^5$), the number of streetlights. The next lines describe the streetlights. Each of the next $n$ lines contains two integers $x_i$ and $s_i$, representing the coordinate of the lamp post of the $i$-th streetlight and its brightness, respectively ($1 \le x_i \le 5 \cdot 10^5$, $1 \le s_i \le 5 \cdot 10^5$, $x_1 \le x_2 \le \ldots \le x_n$). It is guaranteed that at most two streetlights are installed on the same lamp post, i.e. for any coordinate $v$, the number of indices $i$ such that $x_i = v$ is at most two.

Output Format

Output one integer: the number of economical subsets of streetlights modulo $10^9 + 7$.

Explanation/Hint

### Notes In the first sample, all three non-empty subsets of streetlights are valid. In the second sample, all subsets are valid except the set $\{1, 2, 3\}$. ### Subtasks Introduce a variable $t$, which denotes the maximum number of streetlights that may be located at the same coordinate $x_i$. If $t = 1$, then $x_1 < x_2 < \ldots < x_n$. If $t = 2$, then $x_1 \le x_2 \le \ldots \le x_n$, and if $x_i = x_{i+1}$, then $x_{i-1} < x_i$ and $x_{i+1} < x_{i+2}$ (when the corresponding indices exist). | Subtask | Points | $t$ | $n$ | Additional Constraints | Dependent Subtasks | |:---:|:---:|:---:|:---:|:---|:---:| | 1 | 10 | $t = 1$ | $n \le 10$ | | | | 2 | 15 | $t = 1$ | | For any two different lights $i, j$, $x_i - s_i \neq x_j$ and $x_i + s_i \neq x_j - s_j$ | | | 3 | 15 | $t = 1$ | | For any two different lights $i, j$, $s_i \neq s_j$ | | | 4 | 15 | $t = 1$ | | For any two different lights $i, j$, $s_i = s_j$ | | | 5 | 10 | $t = 1$ | $n \le 1000$ | $s_i, x_i \le 1000$ | | | 6 | 20 | $t = 1$ | | | 1–5 | | 7 | 10 | $t = 2$ | | If $x_i = x_{i+1}$, then $s_i \ne s_{i+1}$ | 1–6 | | 8 | 5 | $t = 2$ | | | 1–7 | The translation was completed by DeepSeek V4 Pro. Translated by ChatGPT 5