From e018452176d509b6b2bb28ac4b43660f9379dc2c Mon Sep 17 00:00:00 2001 From: Zengtudor Date: Mon, 1 Sep 2025 20:28:21 +0800 Subject: [PATCH] =?UTF-8?q?fix(P6278.cpp):=20=E4=BF=AE=E6=AD=A3=E4=BA=8C?= =?UTF-8?q?=E8=BF=9B=E5=88=B6=E7=B4=A2=E5=BC=95=E6=A0=91=E5=AE=9E=E7=8E=B0?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复lb函数中错误的变量使用,将'n'改为'val' 修正upd函数中错误的加法操作,将'n'改为'add' 优化逆序对计算逻辑,调整索引计算方式 --- src/9/1/P6278.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/9/1/P6278.cpp b/src/9/1/P6278.cpp index 1e25d04..4ac1569 100644 --- a/src/9/1/P6278.cpp +++ b/src/9/1/P6278.cpp @@ -9,12 +9,12 @@ ll n,ans=0; std::vector a,t,s; static inline ll lb(ll val){ - return n&-n; + return val&(-val); } static inline void upd(ll idx,ll add){ while (idx<=n) { - t[idx]+=n; + t[idx]+=add; idx+=lb(idx); } } @@ -29,7 +29,7 @@ static inline ll get(ll idx){ } int main(){ - std::iostream::sync_with_stdio(false); + std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::cin>>n; @@ -40,13 +40,16 @@ int main(){ std::cin>>a[i]; ++a[i]; } + for(ll i=1;i<=n;++i){ - s[i]=get(a[i]); - upd(a[i],1); + ll x = n - a[i] + 2; + s[a[i]] += get(x-1); + upd(x, 1); } + std::cout<<"0\n"; - for(ll i=1;i<=n;i++){ - ans+=s[i]; + for(ll i=2;i<=n;i++){ + ans += s[i-1]; std::cout<