Dark Alley

시간 제한3초메모리 제한1024 MB

요약
직선 위 전구가 거리에 따라 기하급수적으로 밝기를 잃을 때, 삽입과 삭제, 특정 지점의 밝기 질의를 10^9+7로 나눈 값으로 처리한다.
난이도

보통10점 중 7점

유형
세그먼트 트리, 수학, 누적 합
정답자
아직 제출이 없습니다

문제

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.

The alley can be modelled as a line with a length of nn metres. The fog has a uniform density and reduces the light of a lamp by a factor of 1−p1-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.

입력

The input consists of:

  • One line with two integers nn and qq and one real number pp (1≤n,q≤2⋅105,0<p<11\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 pp of the fog will be given with at most 66 digits behind the decimal point.

  • qq lines containing one of three query types:

    1. "+ b x" given two integers bb and xx (1≤b≤1091\leq b \leq 10^9 and 1≤x≤n1\leq x \leq n), place a lamp with brightness bb at position xx.
    2. "- b x" given integers bb and xx (1≤b≤1091\leq b \leq 10^9 and 1≤x≤n1\leq x \leq n), remove a lamp with brightness bb at position xx. It is guaranteed that a lamp with that brightness was placed there earlier.
    3. "? x" given one integer xx (1≤x≤n1\leq x \leq n), calculate the brightness at position xx.

출력

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

예제2

  1. 예제 1

    입력
    5 6 0.25
    + 4 2
    ? 1
    ? 2
    ? 3
    ? 4
    ? 5
    
    예상 출력
    3
    4
    3
    250000004
    187500003
    
  2. 예제 2

    입력
    5 7 0.33
    + 9 1
    ? 5
    + 4 3
    ? 2
    ? 5
    - 9 1
    ? 2
    
    예상 출력
    312342734
    470000012
    341542736
    760000008