https://www.codechef.com/viewsolution/24881704
Performed several optimisations but couldn’t manage to get AC.
Any kind of help is appreciated.
https://www.codechef.com/viewsolution/24881704
Performed several optimisations but couldn’t manage to get AC.
Any kind of help is appreciated.
Try running ur query block in Qlog(N) without using lower/upper_bound, it’s easy to think
First few things I can see:
ll mul(ll x,ll y)
to inline ll mul(ll x,ll y)
mul
fact[0] = 1;
for( int i=1; i<=n; ++i )
fact[i] = 1ll*i*fact[i-1] %m;
ifac[n] = power(fact[n], m-2);
for( int i=n; i>0; --i )
ifac[i-1] = 1ll*i*ifac[i] %m;
for( int i=1; i<=n; ++i )
modinv[i] = 1ll*ifac[i]*fact[i-1] %m;
I will edit this if I see more.
Thanks, will try to remove lower/upper bound and precompute them.
Thanks, will optimise that.