Submission #785864

#TimeUsernameProblemLanguageResultExecution timeMemory
785864winter0101Worst Reporter 3 (JOI18_worst_reporter3)C++14
100 / 100
315 ms29228 KiB
#include<bits/stdc++.h> using namespace std; #define all(fl) fl.begin(),fl.end() #define pb push_back #define fi first #define se second #define for1(i,j,k) for(int i=j;i<=k;i++) #define for2(i,j,k) for(int i=j;i>=k;i--) #define for3(i,j,k,l) for(int i=j;i<=k;i+=l) #define lb lower_bound #define ub upper_bound #define sz(a) (int)a.size() #define pii pair<int,int> #define pli pair<long long,int> #define pll pair<long long,long long> #define gcd __gcd #define lcm(x,y) x*y/__gcd(x,y) const int maxn=5e5+9; long long a[maxn]; long long jump[maxn]; signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); //freopen("temp.INP","r",stdin); //freopen(".OUT","w",stdout); int n,q; cin>>n>>q; for1(i,1,n){ cin>>a[i]; } jump[1]=1; for1(i,2,n){ jump[i]=jump[i-1]; long long l=1,r=(1e15)/(jump[i-1]*a[1]); while (l<=r){ long long mid=(l+r)/2; if (a[1]*(jump[i-1])*mid>=a[i]){ jump[i]=mid*jump[i-1]; r=mid-1; } else l=mid+1; } } vector<pll>line; line.pb({0,0}); for1(i,1,n){ if (jump[i]>jump[i-1]){ line.pb({-i,-i}); } else line.back().se=-i; } //for (auto v:line)cout<<v.fi<<" "<<v.se<<'\n'; //for1(i,1,n)cout<<jump[i]<<'\n'; for1(i,1,q){ long long ans=0; int l,r,t; cin>>t>>l>>r; vector<pll>cop=line; cop[0].fi+=t; cop[0].se+=t; //cout<<sz(cop)<<'\n'; for1(j,1,sz(cop)-1){ //cout<<cop[j].fi<<" "<<cop[j].se<<'\n'; long long dis=(cop[j-1].se-cop[j].fi)-1; dis/=(a[1]*jump[abs(cop[j].fi)]); //cout<<dis<<'\n'; dis*=(a[1]*jump[abs(cop[j].fi)]); cop[j].fi+=dis; cop[j].se+=dis; //cout<<cop[j].fi<<" "<<cop[j].se<<'\n'; } for (auto v:cop){ if (v.fi<l)continue; if (v.se>r)continue; long long l1=max(1ll*l,v.se),r1=min(1ll*r,v.fi); ans+=1ll*(r1-l1+1); //cout<<v.fi<<" "<<v.se<<'\n'; } cout<<ans<<'\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...