# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
917139 | alexdd | Worst Reporter 3 (JOI18_worst_reporter3) | C++17 | 1 ms | 348 KiB |
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;
ifstream fin("input.in");
ofstream fout("output.out");
#define cin fin
#define cout fout
#define int long long
int n,q;
int d[500005];
int p[500005];
int calc_cur(int i, int ult)
{
int poz = -i;
while(poz + p[i] < ult)
poz += p[i];
return poz;
//return -i + ((ult + i - 1)/d[i]) * d[i];
}
void calc_p()
{
int mxm=d[1];
p[1]=d[1];
for(int i=2;i<=n;i++)
{
if(d[i]>=mxm)
{
mxm=((d[i]-1)/mxm + 1)*mxm;
p[i]=mxm;
}
else
p[i]=1;
}
}
signed main()
{
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>n>>q;
for(int i=1;i<=n;i++)
cin>>d[i];
calc_p();
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=calc_cur(i,ult);
ult=cur;
if(le<=cur && cur<=ri)
cnt++;
}
cout<<cnt<<"\n";
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |