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>
#define int long long
using namespace std;
const int N = 1 << 19, INF = 1e18 + 42;
int n, q, period[N];
int dicho(int t, int obj) {
int ans = -1;
for(int i = 18; i >= 0; i--)
if(period[ans + (1 << i)] * (t / period[ans + (1 << i)]) - ans - (1 << i) >= obj)
ans += (1 << i);
return ans;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> q;
n++;
period[0] = 1;
for(int i = 1; i < n; i++) {
cin >> period[i];
period[i] = ((period[i] + period[i-1] - 1) / period[i-1]) * period[i-1];
}
for(int i = n; i < N; i++)
period[i] = INF;
for(int i = 0; i < q; i++) {
int t, l, r; cin >> t >> l >> r;
cout << dicho(t, l) - dicho(t, r+1) << '\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... |