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
33
34
#include <bits/stdc++.h>

typedef long long ll;

using namespace std;

const ll MOD = 1e9+7;

int main()
{
    ios_base::sync_with_stdio(0);

    int n, q;
    cin >> n >> q;
    vector<ll> a(n), b(n);

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

    ll x, l, r;
    for (int i = 0; i < q; ++i) {
        cin >> x >> l >> r;

        for (int j = l; j < r; ++j) {
            if ((x + a[j]) > (x * b[j])) {
                x = (x + a[j]) % MOD;
            } else {
                x = (x * b[j]) % MOD;
            }
        }
        cout << x << endl;
    }
}