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
29
30
31
32
//Tadeusz Bindas
#include <iostream>
#include <cmath>

int main()
{
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    int n, q;
    std::cin >> n >> q;
    unsigned long long x, l, r;
    unsigned long long* a, * b;
    a = new unsigned long long[n] {};
    b = new unsigned long long[n] {};

    for (int i = 0; i < n; i++)
        std::cin >> a[i] >> b[i];

    for (int i = 0; i < q; i++)
    {
        std::cin >> x >> l >> r;
        for (int j = l; j < r; j++)
        {
            if (a[j] + x > b[j] * x)
                x += a[j];
            else
                x *= b[j];
            x %= 1000000007;
        }
        std::cout << x << std::endl;
    }
}