Submission #82979

#TimeUsernameProblemLanguageResultExecution timeMemory
82979Bodo171Worst Reporter 3 (JOI18_worst_reporter3)C++14
0 / 100
2061 ms15144 KiB
#include <iostream> #include <fstream> using namespace std; const int nmax=500005; long long d[nmax],fv[nmax],val[nmax]; long long l,r,t; int n,q,p,i; int calc(long long x,long long t) { int ret=0; long long vv; if(t<x) return 0; for(int p=18;p>=0;p--) { vv=ret+(1<<p); if(vv<=n&&(t/fv[vv])*(val[vv])-vv>=x) ret+=(1<<p); } return ret+1; } int main() { //freopen("data.in","r",stdin); ios_base::sync_with_stdio(false); cin>>n>>q; for(i=1;i<=n;i++) { cin>>d[i]; if(i==1) fv[i]=d[i],val[i]=d[i]; else { if(val[i-1]<d[i]) { fv[i]=(1LL*fv[i-1]*((d[i]+val[i-1]-1)/val[i-1])); val[i]=(d[i]+val[i-1]-(d[i]%val[i-1])); if(!d[i]%val[i-1]) val[i]=d[i]; } else { fv[i]=fv[i-1]; val[i]=val[i-1]; } fv[i]=min(fv[i],1LL*(1000*1000*1000+1)); } } for(i=1;i<=q;i++) { cin>>t>>l>>r; cout<<calc(l,t)-calc(r+1,t)<<'\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...