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>
#pragma GCC optimize ("O3")
using namespace std;
long long a,s,d[500005],f,g,h,j,k,l,i,n,m;
long long pos(long long idx){
if(d[idx]==0) return 0;
return -idx+h/d[idx]*d[idx];
}
main(){
ios_base::sync_with_stdio(0);
cin>>n>>m;
d[0]=1;
for(i=1;i<=n;i++){
cin>>a;
if(d[i-1]==0) return 0;
d[i]=((a+d[i-1]-1)/d[i-1])*d[i-1];
//cout<<"*"<<d[i]<<endl;
}
for(i=0;i<m;i++){
cin>>h>>a>>s;
long long l=-1,r=n+1,p1,p2;
while(r-l>1){
long long k=(l+r)/2;
//cout<<"*"<<k<<" "<<h<<" "<<pos(k)<<endl;cout<<"#";
if(pos(k)<a) {r=k;} else l=k;
}
p1=l;
//if(p1!=-1 && pos(p1)>=a) p1++;
l=-1;r=n+1;
while(r-l>1){
long long k=(l+r)/2;//cout<<" *"<<k<<" "<<h<<" "<<pos(k)<<endl;
if(pos(k)<=s) {r=k;} else l=k;
}
p2=l;
//cout<<pos(p2)<<" "<<p2;
//if(p2!=-1 && pos(p2)>=a) p2++;
cout<<p1-p2<<endl;
}
}
Compilation message (stderr)
worst_reporter3.cpp:9:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(){
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |