def solve():
MOD = 10**9 + 7
n, q = map(int, input().split())
# Wczytaj opisy wydarzeń
events = []
for _ in range(n):
a, b = map(int, input().split())
events.append((a, b))
# Przetwórz zapytania
for _ in range(q):
x, l, r = map(int, input().split())
# Symuluj grę od wydarzenia l do r-1 (0-indexed)
current = x
for i in range(l, r):
a, b = events[i]
# Porównuj RZECZYWISTE wartości (bez modulo)
option1 = current + a
option2 = current * b
current = max(option1, option2)
# Aplikuj modulo tylko do wyniku końcowego
print(current % MOD)
solve()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | def solve(): MOD = 10**9 + 7 n, q = map(int, input().split()) # Wczytaj opisy wydarzeń events = [] for _ in range(n): a, b = map(int, input().split()) events.append((a, b)) # Przetwórz zapytania for _ in range(q): x, l, r = map(int, input().split()) # Symuluj grę od wydarzenia l do r-1 (0-indexed) current = x for i in range(l, r): a, b = events[i] # Porównuj RZECZYWISTE wartości (bez modulo) option1 = current + a option2 = current * b current = max(option1, option2) # Aplikuj modulo tylko do wyniku końcowego print(current % MOD) solve() |
English