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 ll = long long;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    ll n, q, x, l, r, i, j;
    cin >> n >> q;

    vector <ll> a(n);
    vector <ll> b(n);
    for (i=0; i<n; ++i)
        cin >> a[i] >> b[i];

    for (i=0; i<q; ++i){
        cin >> x >> l >> r;
        
        for (j=l; j<r; ++j)
            x = max(x+a[j], x*b[j]) %ll(pow(10, 9) +7);
        cout << x << '\n';
    }

    return 0;
}