Submission #82984

#TimeUsernameProblemLanguageResultExecution timeMemory
82984Bodo171Worst Reporter 3 (JOI18_worst_reporter3)C++14
100 / 100
1968 ms82172 KiB
#include <iostream> #include <fstream> using namespace std; const int nmax=500005; long long d[nmax],fv[nmax],val[nmax]; int n,q,p,i,l,r,t; string s; int num,ch; int getnum() { num=0; while(s[ch]>='0'&&s[ch]<='9') num=num*10+s[ch]-'0',ch++; ch++; return num; } int calc(int x,int t) { int ret=0; int 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;getline(cin,s); for(i=1;i<=n;i++) { getline(cin,s); ch=0;d[i]=getnum(); 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++) { getline(cin,s);ch=0; t=getnum();l=getnum();r=getnum(); 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...