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;
long long d[500005],p[500005],s[500005];
int main(){
ios::sync_with_stdio(false);
int n,q;
cin >> n >> q;
for (int i=1;i<=n;i++) cin >> d[i];
p[0]=s[0]=d[0]=1;
for (int i=1;i<=n;i++) p[i]=((d[i]-1)/s[i-1]+1)*p[i-1],s[i]=((d[i]-1)/s[i-1]+1)*s[i-1];
for (int i=1;i<=q;i++){
long long T,l,r;
cin >> T >> l >> r;
int bl=0,br=n;
while (bl < br){
int bmid=(bl+br+1)/2;
if (T/p[bmid]*s[bmid]-bmid < l) br=bmid-1;
else bl=bmid;
}
if (T/p[bl]*s[bl]-bl < l) bl--;
int ansr=bl;
bl=0,br=n;
while (bl < br){
int bmid=(bl+br)/2;
if (T/p[bmid]*s[bmid]-bmid > r) bl=bmid+1;
else br=bmid;
}
if (T/p[bl]*s[bl]-bl > r) bl++;
int ansl=bl;
cout << ansr-ansl+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... |