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
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using u64 = uint64_t;

const i64 MOD = 1e9 + 7;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    i64 n, q;
    cin >> n >> q;

    vector<pair<i64, i64>> options(n);
    for (int i = 0; i < n; i++) cin >> options[i].first >> options[i].second;

    while (q--) {
        i64 x;
        i64 l, r;
        cin >> x >> l >> r;

        for (i64 i = l; i < r; i++) {
            x = max(x + options[i].first, x * options[i].second);
        }
        cout << x % MOD << "\n";
    }
}