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
#include <bits/stdc++.h>
using namespace std;
int a[500004],b[500004];
unsigned long long oblicz(int x, int l, int r){
    int m = 1000000007;
   unsigned long long wyn = x;
   for(int i = l + 1; i <= r; i++){
        wyn = max(wyn+a[i],wyn*b[i]) % m;
   }
   return wyn;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n, q, x, l, r;
    cin >> n >> q;
    for(int i = 1; i <= n; i++) cin >> a[i] >> b[i];
    while(q--){
        cin >> x >> l >> r;
        cout << oblicz(x, l, r) << endl;
    }


  return 0;
}