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>
using namespace std;
#define int long long
int n,q;
int d[500005];
int calc_cur(int i, int ult)
{
return -i + ((ult + i - 1)/d[i]) * d[i];
}
signed main()
{
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>n>>q;
for(int i=1;i<=n;i++)
cin>>d[i];
int le,ri,t;
while(q--)
{
cin>>t>>le>>ri;
int cnt=0,mxm=0,ult=t;
if(le<=t && t<=ri)
cnt++;
for(int i=1;i<=n;i++)
{
int cur;
if(d[i]>mxm)
{
mxm=d[i];
cur=calc_cur(i,ult);
}
else
{
cur=ult-1;
}
ult=cur;
if(le<=cur && cur<=ri)
cnt++;
}
cout<<cnt<<"\n";
}
return 0;
}
/**
poz(t,i) = min(((x-i) - (x-i)%d[x])) pt x<=i
-9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9
4 2 1 3 3 *
-9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9
5 3 2 1 3 3 *
-9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9
7 3 2 1 3 3 *
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |