#include<bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
using namespace std;
using ll=long long;
using P=pair<int,int>;
const ll MOD=1000000007LL;
const ll INF=(1<<30);
const ll LINF=(1LL<<60);
template<typename T> void chmax(T &a,T b){a=max(a,b);}
template<typename T> void chmin(T &a,T b){a=min(a,b);}
int main(){
ll n,q;cin>>n>>q;
vector<ll> d(n+10),s(n+10);
for(int i=1;i<=n;i++)cin>>d[i];
s[0]=1;
s[1]=d[1];
for(int i=2;i<=n;i++){
s[i]=s[i-1]*((d[i]/s[i-1])+(d[i]%s[i-1]>0));
}
while(q--){
ll t,l,r;cin>>t>>l>>r;
if((t/s[0])*s[0]<l||-n+(t/s[n])*s[n]>r){
cout<<0<<endl;
continue;
}
ll ok=n,ng=-1;
while(ok-ng>1){
ll mid=(ok+ng)/2;
ll pos=-mid+(t/s[mid])*s[mid];
if(pos<=r){
ok=mid;
}else{
ng=mid;
}
}
int vr=ok;
ok=0,ng=n+1;
while(ng-ok>1){
ll mid=(ok+ng)/2;
ll pos=-mid+(t/s[mid])*s[mid];
if(pos>=l){
ok=mid;
}else{
ng=mid;
}
}
int vl=ok;
cout<<vl-vr+1<<endl;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2053 ms |
11916 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
384 KB |
Output is correct |
2 |
Correct |
6 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
6 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2053 ms |
11916 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |