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 int long long
const int INF = 2e9, MAXN = 5e5;
int n, q, d[MAXN], s[MAXN];
int search(int x, int p){
int i = -1; p -= x;
for(int j=1<<20; j/=2; )
if(i+j < n && -i-j-x%s[i+j] > p) i += j;
return i;
}
signed main(){
cin.tie(0)->sync_with_stdio(0);
cin >> n >> q;
for(int i=0; i<n; ++i) cin >> d[i];
fill(s, s+n, INF);
s[0] = d[0];
for(int i=1; i<n && s[i-1] < INF; ++i)
s[i] = ((d[i] + s[i-1] - 1) / s[i-1]) * s[i-1];
while(q--){
int x, l, r; cin >> x >> l >> r;
cout << search(x, l) - search(x, r+1) + (l <= x && x <= r) << '\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... |