This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
const int N = 5e5 + 5, inf = 1e9 + 7, LG = 30;
int n, q;
int d[N], t[N];
vector<int> p[LG];
int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);
  cin >> n >> q;
  for (int i = 1; i <= n; ++i) {
    cin >> d[i];
  }
  vector<int> comp = {1};
  t[0] = 1;
  for (int i = 1; i <= n; ++i) {
    t[i] = min((long long) inf, (long long) t[i - 1] * ((d[i] - 1) / t[i - 1] + 1));
    comp.push_back(t[i]);
  }
  sort(comp.begin(), comp.end());
  comp.erase(unique(comp.begin(), comp.end()), comp.end());
  for (int i = n; i >= 0; --i) {
    t[i] = lower_bound(comp.begin(), comp.end(), t[i]) - comp.begin();
    p[t[i]].push_back(-i);
  }
  auto qry = [&](vector<int> &cands, int l, int r) {
    int a = lower_bound(cands.begin(), cands.end(), l) - cands.begin();
    int b = upper_bound(cands.begin(), cands.end(), r) - cands.begin();
    return b - a;
  };
  while (q--) {
    int T, L, R; cin >> T >> L >> R;
    int res = 0;
    for (int i = 0; i < comp.size(); ++i) {
      int x = T / comp[i] * comp[i], l = L - x, r = R - x;
      res += qry(p[i], l, r);
    }
    cout << res << "\n";
  }
  return 0;
}
Compilation message (stderr)
worst_reporter3.cpp: In function 'int main()':
worst_reporter3.cpp:44:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |     for (int i = 0; i < comp.size(); ++i) {
      |                     ~~^~~~~~~~~~~~~| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |