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
#include <iostream>
using namespace std;
int mn[5000000], dod[5000000];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, q;
    cin >> n >> q;
   
    for (int i = 0; i < n;i++) {
        cin >> dod[i] >> mn[i];
    }
    long long x, l, r;
    for (int i = 0; i < q;i++) {
        cin >> x>>l>> r;
        while (l < r) {
            if ((dod[l] + x) > mn[l] * x) {
                x += dod[l];
            }
            else {
                x *= mn[l];
            }
            l+=1;
        }
        cout << x % 1000000007<<"\n";
    }
    return 0;
}