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 Nero
#include "Deb.h"
#else
#define deb(...)
#endif
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, q;
cin >> n >> q;
vector<long long> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
for (int i = 1; i < n; ++i) {
if (a[i] < a[i - 1]) {
a[i] = a[i - 1];
} else {
a[i] = ((a[i] + a[i - 1] - 1) / a[i - 1]) * a[i - 1];
}
}
while (q--) {
int t, l, r;
cin >> t >> l >> r;
int ans = t >= l && t <= r;
int lo = -1, hi = n - 1;
while (lo < hi) {
int mid = (lo + hi + 1) / 2;
long long p = (long long) t / a[mid] * a[mid] - mid - 1;
if (p >= l) {
lo = mid;
} else {
hi = mid - 1;
}
}
int lo2 = 0, hi2 = n;
while (lo2 < hi2) {
int mid = (lo2 + hi2) / 2;
long long p = (long long) t / a[mid] * a[mid] - mid - 1;
if (p <= r) {
hi2 = mid;
} else {
lo2 = mid + 1;
}
}
cout << ans + (hi - lo2 + 1) << '\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... |