P13719 [GCPC 2024] Dark Alley

Description

One cold and foggy night, you walk down a shady alley. There should be a lamp every few metres but none of them seem to work, and in this night, not even the moon enlightens your path. Alone and in the dark, you wonder: "Even if there was a working lamp somewhere, how much would it lighten my way". Now, back at home, you want to calculate this. ![](https://cdn.pixabay.com/photo/2019/06/13/05/24/the-park-at-night-4270765_1280.jpg) :::align{center} A foggy alley. [Photo by Henryk Niestrój](https://pixabay.com/de/photos/park-in-der-nacht-dunkle-stra\%C3\%9Fe-4270765/) ::: The alley can be modelled as a line with a length of $n$ metres. The fog has a uniform density and reduces the light of a lamp by a factor of $1-p$ every metre. The brightness at one point is the sum of the light that reaches this point from every lamp. You want to calculate this brightness at some points after placing some lamps.

Input Format

The input consists of: - One line with two integers $n$ and $q$ and one real number $p$ ($1\leq n, q\leq 2\cdot10^5, 0 < p < 1$), the length of the alley, the number of queries and the density of the fog. The density $p$ of the fog will be given with at most $6$ digits behind the decimal point. - $q$ lines containing one of three query types: 1. "$\texttt{+ b x}$" given two integers $b$ and $x$ ($1\leq b \leq 10^9$ and $1\leq x \leq n$), place a lamp with brightness $b$ at position $x$. 2. "$\texttt{- b x}$" given integers $b$ and $x$ ($1\leq b \leq 10^9$ and $1\leq x \leq n$), remove a lamp with brightness $b$ at position $x$. It is guaranteed that a lamp with that brightness was placed there earlier. 3. "$\texttt{? x}$" given one integer $x$ ($1\leq x \leq n$), calculate the brightness at position $x$.

Output Format

It can be shown that the brightness can be calculated as a fraction $\frac{P}{Q}$ where $Q$ is not divisible by $10^9+7$. For each query of type "$\texttt{?}$", print the brightness as $P\cdot Q^{-1} \bmod 10^9+7$ in a single line.

Explanation/Hint

In the first sample case, the brightness in the alley after placing the lamp will look like this: | $3$ | $4$ | $3$ | $2.25$ | $1.6875$ | |:-:|:-:|:-:|:-:|:-:|