This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>
 
using namespace std;
 
#define nl '\n'
#define pb push_back
#define pf push_front
 
#define mp make_pair
#define f first
#define s second
#define sz(x) int(x.size())
 
template<class T> using V = vector<T>;
using pi = pair<int, int>;
using vi = V<int>;
using vpi = V<pi>;
 
using ll = long long;
using pl = pair<ll, ll>;
using vpl = V<pl>;
using vl = V<ll>;
 
using db = long double;
 
template<class T> using pq = priority_queue<T, V<T>, less<T>>;
 
const int MOD = 1e9 + 7;
const ll INFL = ll(1e17);
const int LG = 19;
int main() {
	cin.tie(0)->sync_with_stdio(0);
	int N, Q; cin >> N >> Q;
	vi D(N); for(auto& x : D) cin >> x;
	ll mx = 1;
	vl MUL(N+1, 1), MOVE(N+1, 1);
	for(int i = 1; i <= N; i++) {
		MOVE[i] = MOVE[i - 1];
		if (mx < D[i - 1]) MOVE[i] = D[i - 1] + ((mx - (D[i - 1] % mx)) % mx);
		ll d = (MOVE[i] + mx - 1) / mx; 
		MUL[i] = min(MOD + 0LL, MUL[i - 1] * d);
		// cout << i << " => " << MUL[i] << " - " << MOVE[i] << " - " << d << endl;
		mx = max(mx, MOVE[i]);
	}
	auto get = [&](int t, int x) {
		int lo = 0, hi = N + 1;
		while(lo < hi) {
			int mid = (lo + hi) / 2;
			// cout << lo << " <= " << mid << " <= " << hi << endl;
			ll pos = (t / MUL[mid]) * MOVE[mid] - mid;
			// cout << t << " " << mid << " => " << pos << " - " << MUL[mid] << endl;
			if (pos <= x) hi = mid;
			else lo = mid + 1;
		}
		// cout << lo << " <<>> " << hi << endl;
		return N + 1 - lo;
	};
	for(int q = 0; q < Q; q++) {
		int t, l, r; cin >> t >> l >> r;
		cout << get(t, r) - get(t, l - 1) << nl;
	}
	exit(0-0);
} 		
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |