#include<bits/stdc++.h>
#pragma GCC optimize ("O3")
using namespace std;
int a,s,d[500005],f,g,h,j,k,l,i,n,m;
int pos(int idx){
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;
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;
int l=-1,r=n+1,p1,p2;
while(r-l>1){
int 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){
int 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
worst_reporter3.cpp:8:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(){
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1650 ms |
5560 KB |
Output is correct |
2 |
Correct |
1685 ms |
5560 KB |
Output is correct |
3 |
Correct |
1714 ms |
5560 KB |
Output is correct |
4 |
Correct |
1656 ms |
5588 KB |
Output is correct |
5 |
Correct |
1628 ms |
5636 KB |
Output is correct |
6 |
Correct |
1757 ms |
5636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
5636 KB |
Output is correct |
2 |
Correct |
4 ms |
5636 KB |
Output is correct |
3 |
Correct |
4 ms |
5636 KB |
Output is correct |
4 |
Correct |
4 ms |
5636 KB |
Output is correct |
5 |
Correct |
4 ms |
5636 KB |
Output is correct |
6 |
Correct |
4 ms |
5636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1650 ms |
5560 KB |
Output is correct |
2 |
Correct |
1685 ms |
5560 KB |
Output is correct |
3 |
Correct |
1714 ms |
5560 KB |
Output is correct |
4 |
Correct |
1656 ms |
5588 KB |
Output is correct |
5 |
Correct |
1628 ms |
5636 KB |
Output is correct |
6 |
Correct |
1757 ms |
5636 KB |
Output is correct |
7 |
Correct |
5 ms |
5636 KB |
Output is correct |
8 |
Correct |
4 ms |
5636 KB |
Output is correct |
9 |
Correct |
4 ms |
5636 KB |
Output is correct |
10 |
Correct |
4 ms |
5636 KB |
Output is correct |
11 |
Correct |
4 ms |
5636 KB |
Output is correct |
12 |
Correct |
4 ms |
5636 KB |
Output is correct |
13 |
Runtime error |
2 ms |
5636 KB |
Execution killed with signal 8 (could be triggered by violating memory limits) |
14 |
Halted |
0 ms |
0 KB |
- |