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;
#define all(x) (x).begin(), (x).end()
const int N = 5e5 + 7;
int n, q;
ll d[N], c[N];
int main() {
cin.tie(0)->sync_with_stdio(false);
cin >> n >> q;
c[0] = 1;
for (int i = 1; i <= n; i++) {
cin >> d[i];
c[i] = (d[i] + c[i - 1] - 1) / c[i - 1] * c[i - 1];
}
auto query = [&](ll t, ll x) {
ll res = n + 1, shift = 0;;
while (t > 0) {
int i = upper_bound(c, c + n + 1, t) - c - 1;
ll dist = t - (t % c[i]);
t -= dist, shift += dist;
res = min(res, n + 1 - i + max(x - (shift - i), -1LL));
}
return res;
};
while (q--) {
ll t, l, r;
cin >> t >> l >> r;
cout << query(t, r) - query(t, l - 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... |