Logo
(追記) (追記ここまで)

20251번 - Homework 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
3 초 1024 MB611100.000%

문제

There are n children (numbered from 1 to n) learning the arithmetic operations, which include addition “+”, subtraction “−”, multiplication “×”, and division “÷” on rational numbers.

In the beginning, each child has a paper sheet with only a zero on it. Their teacher, Frank, will then give them q operations. The i-th operation consists of an operator ci and an integer xi. The children numbered li, li + 1, . . . , ri have to append the operator ci and the integer xi to their paper sheets. After that, every child has an expression on their sheet to be evaluated.

For example, suppose that n = 3, q = 2, c1 is “+”, x1 = 1, l1 = 1, r1 = 2, c2 is “−”, x2 = 2, l2 = 2, and r2 = 3. The expressions on the sheets are are 0 + 1, 0 + 1 − 2 and 0 − 2 for children 1, 2 and 3, respectively.

Since Frank is really lazy and wants to verify the answers quickly, he asks you to calculate the sums of the values of all children’s expressions. Suppose that the value of the expression assigned to child i is ai/bi, then the value will be a × b−1 mod 109 + 7 instead, where b−1 denotes the integer satisfying b × b−1 ≡ 1 mod 109 + 7. If the sum is not in [0, 109 + 7), then the sum modulo 109 + 7 should be returned to Frank.

Note: The arithmetic operations has PEMDAS rule, that is, multiplications and divisions should be evaluated before evaluating additions and subtraction.

입력

The first line consists of two space-separated integers n and q. The i-th of the following q lines consists of four space-separated tokens li, ri, ci, xi. For the sake of convenience, * and / are used to represent the multiplication and the division operators, respectively.

출력

Output the number that you should return to Frank.

제한

  • 1 ≤ n ≤ 105
  • 1 ≤ q ≤ 105
  • li, ri ∈ [1, n] for all 1 ≤ i ≤ q.
  • ci ∈ {+, -, *, /} for all 1 ≤ i ≤ q. For all 1 ≤ i ≤ q, xi = 0 implies that ci is not /.
  • xi ∈ [0, 109 + 7) for all 1 ≤ i ≤ q.

예제 입력 1

3 2
1 2 + 1
2 3 - 2

예제 출력 1

1000000005

힌트

출처

ICPC > Regionals > Asia Pacific > Taiwan > Taiwan Online Programming Contest > TOPC 2020 F번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /