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
#include <iostream>

using namespace std;

int main(int argc, char const *argv[])
{
    int n, q;
    int a[500000], b[500000];
    int l, r;
    long long res, ovr;

    cin >> n >> q;

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

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

    return 0;
}