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;
using ll = long long;
int main () {
ios::sync_with_stdio(false);
cin.tie(0);
int n, q;
cin >> n >> q;
vector<int> a {1}, idx {0};
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
a.push_back(x);
a[i] = max(a[i-1], a[i]);
a[i] = (a[i]-1) / a[i-1] * a[i-1] + a[i-1];
idx.push_back(i);
}
reverse(idx.begin(), idx.end());
while (q--) {
int t, l, r;
cin >> t >> l >> r;
auto itl = lower_bound(idx.begin(), idx.end(), l, [&] (int x, int id) {return -x + t / a[x] * a[x] < id;});
auto itr = upper_bound(idx.begin(), idx.end(), r, [&] (int id, int x) {return id < -x + t / a[x] * a[x];});
cout << itr - itl << '\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... |