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 <iostream>
#define ll long long
using namespace std;
ll n, q, t, ql, qr, l, r, ul, ur, mid, A[500001], D[500001], T[500001];
int main() {
cin >> n >> q;
for (int i=1; i<=n; ++i) cin >> A[i];
T[0] = D[0] = 1;
for (int i=1; i<=n; ++i) {
T[i] = T[i-1] * (ll)((A[i]+D[i-1]-1)/D[i-1]);
D[i] = (ll)((A[i]+D[i-1]-1)/D[i-1]) * D[i-1];
}
while (q--) {
cin >> t >> ql >> qr;
l = 0, r = n;
while (l < r) {
mid = (l+r+1)/2;
if (ql <= (ll)(t/T[mid]) * D[mid] - mid) l = mid;
else r = mid-1;
}
ur = l;
l = 0, r = n;
while (l < r) {
mid = (l+r)/2;
if ((ll)(t/T[mid]) * D[mid] - mid <= qr) r = mid;
else l = mid+1;
}
ul = l;
if (ql <= (ll)(t/T[ur]) * D[ur] - ur && (ll)(t/T[ul]) * D[ul] - ul <= qr) cout << ur-ul+1 << '\n';
else cout << "0\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... |