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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#ifdef _MSC_VER
  #ifndef __GNUC__
    #pragma warning(disable: 4996)
  #endif
  #define main main0
#endif
#include <iostream>
#include <vector>
using namespace std;
typedef long long           ll;
typedef unsigned long long ull;
typedef unsigned int      uint;
const int Modulo = 1000000007;

struct Wydarzenia {
  int a;
  int b;
  int granica;
};

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

  int n, q;
  vector<Wydarzenia> wydarzenia;
  cin >> n >>q;
  wydarzenia.resize(n);
  for(int i = 0; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    wydarzenia[i].a = a;
    wydarzenia[i].b = b;
    if(b == 1)
      wydarzenia[i].granica = Modulo;
    else
      wydarzenia[i].granica = a / (b - 1);
  }

  for(int i = 0; i < q; ++i) {
    bool przekroczono = false;
    ll x;
    int l, r;
    cin >> x >> l >> r;
    for(int j = l; j < r; ++j) {
      if(wydarzenia[j].b == 1 || (!przekroczono && x <= wydarzenia[j].granica))
        x += wydarzenia[j].a;
      else
        x *= wydarzenia[j].b;
      if(x >= Modulo) {
        x %= Modulo;
        przekroczono = true;
      }
    }
    x %= Modulo;
    cout << x << '\n';
  }

  return 0;
}