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;
typedef long long ll;
typedef pair<ll,ll> ii;
typedef long double ld;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
const int INF=2012345678;
const ll LLINF=4012345678012345678LL;
const ll MOD=1000000007; //998244353; //
const ld PI=3.1415926535898;
const ld EPS=1e-9;
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(b==0)return a;return gcd(b,a%b);}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll expo(ll b,ll p,ll m){ll res=1; while(p){if(p&1)res=(res*b)%m; b=(b*b)%m; p>>=1;} return res;}
inline ll modinv(ll a,ll m){return expo(a,m-2,m);}
int n,q;
ll d[500005],c[500005];
ll dist(ll t,int x){
return (t/c[x])*c[x]-x;
}
int main(){
scanf("%d%d",&n,&q);
for(int i=1;i<=n;i++)scanf("%lld",&d[i]);
d[0]=c[0]=1;
for(int i=1;i<=n;i++){
c[i]=ceil((double)(d[i])/(double)(c[i-1]))*c[i-1];
}
//period of entire thing is c[n]
ll t,l,r;
for(int i=0;i<q;i++){
scanf("%lld%lld%lld",&t,&l,&r);
if(dist(t,0)<l||dist(t,n)>r){printf("0\n");continue;}
//for(int j=0;j<=n;j++)printf("%lld ",dist(t,j));
int bl=0,br=n;
while(bl<br){
int m=(bl+br)/2;
//printf("%d %d %d %lld %lld\n",bl,m,br,dist(t,m),r);
if(dist(t,m)<=r)br=m;
else bl=m+1;
}
int right=bl;
bl=0;br=n;
while(bl<br){
int m=(bl+br+1)/2;
if(dist(t,m)>=l)bl=m;
else br=m-1;
}
int left=bl;
//printf("%d %d\n",left,right);
printf("%d\n",left-right+1);
}
}
Compilation message (stderr)
worst_reporter3.cpp: In function 'int main()':
worst_reporter3.cpp:31:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&n,&q);
~~~~~^~~~~~~~~~~~~~
worst_reporter3.cpp:32:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(int i=1;i<=n;i++)scanf("%lld",&d[i]);
~~~~~^~~~~~~~~~~~~~
worst_reporter3.cpp:40:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld%lld%lld",&t,&l,&r);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |