APoorKingTag:ReversedBFSPreprocessingisneededtocalculateanswersforallpositions(states).Beginningwithallcheckmatestates,youshoulddoreversedBreath-FirstSearch(BFS)toupdatevalues.Thestatecanbespecifiedbythreepositions,so64*64*64statesinall.Foreachstate,makeallpossiblenextstatesandcheckifalltheirvalueshadalreadydetermined.Ifso,youcandeterminethevalue(answer)forthisstate.BestDivisionTag:DP,Trie,DatastructureThisisaDynamicProgramming(DP)problem.Letdp[i]betheanswer(maximumK)forthesubarrayA[1]~A[i].Then,dp[i]=(maxi-L≤j=dormin{dist(V,u),dist(V,v)}>=d,orthereexistsatleastonenodew,f(w)isonthepathfromf(u)tof(v)),min{dist(w,u),dist(w,v)}>=d.Thelastconditioncanbecheckedbyconsideringthecentercofthepathfromutov.Soforallnodesw,iff(w)isonthepathf(u)tof(c),dist(u,w)>=d,elsedist(v,w)>=dmustbeheld.Thisleadsasimplerangemaximumqueryproblem.Thesecanbepre-calculated,sowecananswereachquerybyO(1)time.SorequiredtimeisO(N*log(N)+Q).GeneratorTag:Inclusion/Exclusionprinciple,StringMatching,Linearequations.Considertheprobabilitythatallsequencesaregeneratediniseconds.Let’sdenotei...