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 <bits/stdc++.h>
using namespace std;

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

    int n, q;
    cin >> n >> q;

    vector<pair<long long int, long long int>> tab(n);

    for(int i=0; i<n; i++){
        cin >> tab[i].first >> tab[i].second;
    }

    long long int M = (long long int)(1e9+7);

    for(int _=0; _<q; _++){
        long long int x;
        int l, r;
        cin >> x >> l >> r;
        l--;
        r--;

        for(int i=l+1; i<=r; i++){
            x = max(x + tab[i].first, x*tab[i].second)%M;
        }

        cout << x << "\n";
    }
}