#include<bits/stdc++.h>
using namespace std;
#define task "reporter3"
#define lb lower_bound
#define ub upper_bound
#define ALL(v) (v).begin(),(v).end()
#define zs(v) int((v).size())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)
#define per(i,b,a) for(int i=(b),_a=(a);i>=_a;--i)
#define rep_(i,a,b) for(int i=(a),_b=(b);i<_b;++i)
typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
const int d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1};
const int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1};
const ll mod=1000000007; /// 998244353
const int base=311;
const int N=5e5+5;
int n,q,a[N];
ll b[N];
void biot()
{
cin>>n>>q;
for(int i=1;i<=n;++i) cin>>a[i];
b[0]=1;
for(int i=1;i<=n;++i)
{
b[i]=((a[i]+b[i-1]-1)/b[i-1])*b[i-1];
// cout<<b[i]<<' ';
}
// cout<<endl;
while(q--)
{
int L,R,t;
cin>>t>>L>>R;
int l=0, r=n;
int ansl=-1, ansr=-1;
while(l<=r)
{
int mid=(l+r)>>1;
if((t/b[mid])*b[mid]-mid>=L) l=mid+1, ansl=mid;
else r=mid-1;
}
l=0, r=n;
while(l<=r)
{
int mid=(l+r)>>1;
if(t/b[mid]*b[mid]-mid<=R) r=mid-1, ansr=mid;
else l=mid+1;
}
cout<<ansl-ansr+1<<'\n';
}
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
if(fopen(task".inp","r"))
{
freopen(task".inp","r",stdin);
freopen(task".out","w",stdout);
}
biot();
}
Compilation message
worst_reporter3.cpp: In function 'int main()':
worst_reporter3.cpp:65:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
65 | freopen(task".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
worst_reporter3.cpp:66:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
66 | freopen(task".out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
634 ms |
20216 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
634 ms |
20216 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |