#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
int n, q;
cin >> n >> q;
vector<int> d(n+1);
for (int i = 1; i <= n; i++) cin >> d[i];
d[0] = 1;
for (int i = 1; i <= n; i++) {
d[i] = ((d[i]/d[i-1]) + (d[i] % d[i-1] == 0 ? 0 : 1)) * d[i-1];
}
while (q--) {
int t, l, r;
cin >> t >> l >> r;
int lo = 0, hi = n;
while (lo < hi) {
// last person whose location is >= l
int mid = (lo+hi+1)/2;
if (mid == 0) break;
int loc = (t/d[mid])*d[mid] - mid;
if (loc >= l) lo = mid;
else hi = mid-1;
}
int x = lo;
lo = 0, hi = n;
int x2 = 0;
while (lo < hi) {
// first person whose location is > r
int mid = (lo+hi+1)/2;
if (mid == 0) break;
int loc = (t/d[mid]) * d[mid] - mid;
if (loc > r) lo = mid;
else hi = mid-1;
}
x2 = lo;
cout << x-x2 + (t >= l && t <= r) << '\n';
}
return 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... |