# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
281733 | MKopchev | Worst Reporter 3 (JOI18_worst_reporter3) | C++14 | 953 ms | 27408 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;
const int nmax=5e5+42,inf=1e9+42;
int n,q;
int inp[nmax];
long long help[nmax];
int score(int i,int t)
{
return (t/help[i])*help[i]-i;
}
int last_valid(int pos,int t)
{
int ok=n+1,not_ok=-1;
while(ok-not_ok>1)
{
int av=(ok+not_ok)/2;
if(score(av,t)<=pos)ok=av;
else not_ok=av;
}
//cout<<"last "<<ok<<endl;
return ok;
}
int first_valid(int pos,int t)
{
int ok=-1,not_ok=n+1;
while(not_ok-ok>1)
{
int av=(ok+not_ok)/2;
if(score(av,t)>=pos)ok=av;
else not_ok=av;
}
//cout<<"first "<<ok<<endl;
return ok;
}
int main()
{
scanf("%i%i",&n,&q);
for(int i=1;i<=n;i++)
{
scanf("%i",&inp[i]);
}
inp[0]=1;
help[0]=1;
for(int i=1;i<=n;i++)
{
help[i]=help[i-1]*((inp[i]+help[i-1]-1)/help[i-1]);
if(help[i]>inf)help[i]=inf;
//cout<<i<<" -> "<<help[i]<<endl;
}
for(int i=1;i<=q;i++)
{
int l,r,t;
scanf("%i%i%i",&t,&l,&r);
/*
for(int j=0;j<=n;j++)
cout<<j<<" -> "<<score(j,t)<<endl;
*/
printf("%i\n",first_valid(l,t)-last_valid(r,t)+1);
}
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... |