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 ll long long
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ld long double
#define sz(a) ((ll)(a).size())
using namespace std;
const ll maxn=500005;
ll d[maxn], inc[maxn];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
ll n, q; cin >> n >> q;
for (ll i=1; i<=n; i++) cin >> d[i];
for (ll i=0; i<=n; i++) inc[i]=i?(d[i]+inc[i-1]-1)/inc[i-1]*inc[i-1]:1;
auto find=[&](ll idx, ll t){return -idx+t/inc[idx]*inc[idx];};
for (ll i=1; i<=q; i++)
{
ll t, l, r; cin >> t >> l >> r;
ll fir=0, las=0;
// find first <=r
{
ll lo=0, hi=n+1;
while (hi>lo)
{
ll mid=(lo+hi)/2;
if (find(mid, t)<=r) hi=mid;
else lo=mid+1;
}
fir=lo;
}
// find last >=l
{
ll lo=-1, hi=n;
while (hi>lo)
{
ll mid=(lo+hi+1)/2;
if (find(mid, t)>=l) lo=mid;
else hi=mid-1;
}
las=lo;
}
cout << las-fir+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... |