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>
#define int long long
using namespace std;
int a[100005], n, q;
int f(int t, int x)
{
int l=0, r=n+1;
while (l<r)
{
int m=(l+r)/2;
if (t/a[m]*a[m]-m<=x)
r=m;
else
l=m+1;
}
return n-r+2;
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> q;
a[0]=1;
for (int i=1; i<=n; i++)
{
cin >> a[i];
a[i]=((a[i]-1)/a[i-1]+1)*a[i-1];
}
for (int i=1; i<=q; i++)
{
int t, l, r;
cin >> t >> l >> r;
cout << f(t, r)-f(t, l-1) << '\n';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |