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>
using namespace std;
long long int n, a[500005], f[500005];
long long int check(long long int x, long long int i) {
return x / f[i] * f[i] - i;
}
int trya(long long int t, long long int x) {
int l = 0, r = n, res = -1;
while (l <= r) {
int mid = (l + r) / 2;
if (check(t, mid) >= x) {
res = mid;
l = mid + 1;
}
else r = mid - 1;
}
return res + 1;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int q;
cin >> n >> q;
f[0] = 1;
for (int i = 1; i <= n; i++) {
cin >> a[i];
f[i] = (a[i] + f[i - 1] - 1) / f[i - 1] * f[i - 1];
}
for (int jj = 0; jj < q; jj++) {
long long int t, l, r;
cin >> t >> l >> r;
if (t < l) {
cout << 0 << '\n';
continue;
}
if (t == l) {
cout << 1 << '\n';
continue;
}
long long int h = trya(t, l), k = trya(t, r + 1);
cout << h - k << '\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... |