This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/* in the name of allah */
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define F first
#define S second
#define mk make_pair
typedef long long ll;
const int N=5e5+7;
ll n,q,d[N],s[N],x[N];
ll pos(int i,ll t){
return -i+(t/s[i])*x[i];
}
int main(){
ios:: sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin>>n>>q;
for(int i=1;i<=n;i++){
cin>>d[i];
}
s[0]=1,x[0]=1;
for(int i=1;i<=n;i++){
ll f=d[i]/x[i-1]+(d[i]%x[i-1]!=0);
s[i]=f*s[i-1];
x[i]=f*x[i-1];
}
while(q--){
ll t,s,e;
cin>>t>>s>>e;
int L,R=0;
int l=-1,r=n;
while(r-l>1){
int m=(l+r)/2;
if(pos(m,t)<=e)r=m;
else l=m;
}
L=r;
l=0,r=n+1;
while(r-l>1){
int m=(l+r)/2;
//cout<<m<<endl;
if(pos(m,t)>=s)l=m;
else r=m;
}
R=l;
if(pos(L,t)<s)L++;
cout<<R-L+1<<endl;
//cout<<L<<" "<<R<<endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |