From 37ca18855adc2503452fc5ce6471667d7d519985 Mon Sep 17 00:00:00 2001 From: Zengtudor Date: Wed, 24 Sep 2025 17:36:30 +0800 Subject: [PATCH] =?UTF-8?q?perf(P8818):=20=E4=BD=BF=E7=94=A8=E9=A2=84?= =?UTF-8?q?=E8=AE=A1=E7=AE=97=E7=9A=84lg2=E6=95=B0=E7=BB=84=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E5=AF=B9=E6=95=B0=E8=AE=A1=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 用预计算的lg2数组替代多次log2调用,减少重复计算开销 --- src/9/23/P8818.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/9/23/P8818.cpp b/src/9/23/P8818.cpp index 2b18a9f..421572a 100644 --- a/src/9/23/P8818.cpp +++ b/src/9/23/P8818.cpp @@ -23,9 +23,9 @@ do{\ printf(#v" :%lld\n",(v));\ }while(0)\ -const ll inf = 1e9+7; +const ll inf = 1e9+7,maxn=1e5+5; ll n,m,q; -std::vector a,b; +std::vector a,b,lg2; struct BT{ std::vector> vmax, vmin, vupmin, vdownmax; @@ -33,7 +33,7 @@ struct BT{ ll vsize; inline BT(const std::vector &v){ - vsize = ceil(log2(v.size())); + vsize = ceil(lg2[v.size()]); vmax.resize(v.size(),std::vector(vsize+1, -inf)); vmin.resize(v.size(),std::vector(vsize+1,inf)); vupmin.resize(v.size(),std::vector(vsize+1,inf)); @@ -63,14 +63,14 @@ struct BT{ // pv(vdownmax); } inline ll getmax(const std::vector> &v,const ll l,const ll r){ - const ll lg = log2(r-l+1); + const ll lg = lg2[r-l+1]; return std::max( v[l][lg], v[r-(1ull<> &v,const ll l,const ll r){ - const ll lg = log2(r-l+1); + const ll lg = lg2[r-l+1]; return std::min( v[l][lg], v[r-(1ull<>n>>m>>q; a.resize(n+1);