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;
#define all(x) (x).begin(), (x).end()
#define sz(x) ( (int)(x).size() )
using LL = long long;
mt19937 rng( (uint32_t)chrono::steady_clock::now().time_since_epoch().count() );
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef FourLeafClover
freopen("input", "r", stdin);
#endif // FourLeafCLover
int n, q; cin >> n >> q;
vector<int> d(n);
for (int i = 0; i < n; ++i) cin >> d[i];
vector<int> f(n); f[0] = d[0];
for (int i = 1; i < sz(f); ++i) f[i] = (int)min( (LL)2e9, (LL)( (d[i] + f[i - 1] - 1) / f[i - 1]) * f[i - 1]);
while (q--) {
int t, l, r; cin >> t >> l >> r;
int ans = (l <= t && t <= r);
int L = 0, R = n;
while (L < R) {
int M = (L + R) >> 1;
if (t - t % f[M] - (M + 1) <= r) R = M;
else L = M + 1;
}
ans += -L;
L = 0; R = n;
while (L < R) {
int M = (L + R) >> 1;
if (t - t % f[M] - (M + 1) < l) R = M;
else L = M + 1;
}
ans += L;
cout << ans << '\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... |