Range Sum Query#3252

Range Sum Query

1 sekunt
256 megabaýt
Örän ýeňil

Given an array of integers, initially filled with zeroes. There are two types of operations:

Giriş

The first line contains the size of the array and the number of queries (1 \le n \le 10^9 + 7, 1 \le m \le 2 \times 10^5). Then queries are given, one per line.

During program execution, maintain two numbers and . Initially, P = 91, Q = 47.

A query of the form ! A B means that you must assign the value (B + Q) \bmod (10^9 + 7) to the cell (A + P) \bmod n.

A query of the form ? A B means you must find the sum of elements from (A + P) \bmod n to (B + Q) \bmod n inclusive. Let the answer be . Then, update the values and as follows:

P = (P \times 31 + Z) \bmod (10^9 + 7)

Elements are numbered starting from zero.

All input numbers do not exceed 10^9 + 7.

Çykyş

For each sum query, print the answer on a separate line.

Mysallar

1-nji mysal

Loading
Loading

2-nji mysal

Loading
Loading