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], t[MAXN], s[MAXN];
int search(int x, int p){
int i = -1;
for(int j=1<<20; j/=2; ){
if(i+j >= n) continue;
i += j;
if(- i - 1 + x / t[i] * s[i] < 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(t, t+n, INF);
t[0] = s[0] = d[0];
for(int i=1; i<n; ++i){
int m = ((d[i] + s[i-1] - 1) / s[i-1]);
s[i] = m * s[i-1];
t[i] = m * t[i-1];
if(t[i] > INF) break;
}
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... |