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;
#define int long long
int32_t main() {
ios::sync_with_stdio(0); cin.tie(0);
int n, q;
cin >> n >> q;
vector<int> d(n + 1, 1);
for (int i = 1; i <= n; i++) cin >> d[i];
for (int i = 1; i <= n; i++) {
if (d[i] < d[i - 1]) d[i] = d[i - 1];
else d[i] = ((d[i] + d[i - 1] - 1) / d[i - 1]) * d[i - 1];
}
while (q--) {
int T, L, R, l = 1, r = n, idL = 0, idR = 0;
cin >> T >> L >> R;
// min index s.t.
while (l < r) {
int mid = (l + r) >> 1;
int pos = (-mid + (T / d[mid]) * d[mid]);
if (pos <= R) r = mid;
else l = mid + 1;
}
if (-l + (T / d[l]) * d[l] <= R) idL = l;
l = 1, r = n;
while (l < r) {
int mid = (l + r + 1) >> 1;
int pos = (-mid + (T / d[mid]) * d[mid]);
if (pos >= L) l = mid;
else r = mid - 1;
}
if (-l + (T / d[l]) * d[l] >= L) idR = l;
int add = 0;
if (L <= T && T <= R) add++;
// cout << idL << ' ' << idR << '\n';
if (idL != 0 && idR != 0) cout << (idR - idL + 1) + add << '\n';
else cout << add << "\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |