From 9db115d255bf3cc1fc85f5ddef0e263d20de7b15 Mon Sep 17 00:00:00 2001 From: Zengtudor Date: Mon, 1 Sep 2025 15:26:27 +0800 Subject: [PATCH] =?UTF-8?q?refactor(9):=20=E9=87=8D=E6=9E=84P3608.cpp?= =?UTF-8?q?=E5=B9=B6=E6=B7=BB=E5=8A=A0P6278.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将P3608.cpp移动到9/1目录并扩展功能 新增P6278.cpp实现树状数组相关算法 修改test.cpp添加输入处理和异常检查 --- src/9/{ => 1}/P3608.cpp | 2 ++ src/9/1/P6278.cpp | 52 +++++++++++++++++++++++++++++++++++++++++ src/test.cpp | 21 +++++++++++++---- 3 files changed, 70 insertions(+), 5 deletions(-) rename src/9/{ => 1}/P3608.cpp (99%) create mode 100644 src/9/1/P6278.cpp diff --git a/src/9/P3608.cpp b/src/9/1/P3608.cpp similarity index 99% rename from src/9/P3608.cpp rename to src/9/1/P3608.cpp index 76520b3..5e1e176 100644 --- a/src/9/P3608.cpp +++ b/src/9/1/P3608.cpp @@ -12,6 +12,8 @@ std::vector a,raw; std::map m; std::vector t; + + static inline constexpr ll lb(ll n){ return n&(-n); } diff --git a/src/9/1/P6278.cpp b/src/9/1/P6278.cpp new file mode 100644 index 0000000..1e25d04 --- /dev/null +++ b/src/9/1/P6278.cpp @@ -0,0 +1,52 @@ +#include +#include +#include +#include + +using ll = int64_t; + +ll n,ans=0; +std::vector a,t,s; + +static inline ll lb(ll val){ + return n&-n; +} + +static inline void upd(ll idx,ll add){ + while (idx<=n) { + t[idx]+=n; + idx+=lb(idx); + } +} + +static inline ll get(ll idx){ + ll res=0; + while(idx){ + res+=t[idx]; + idx-=lb(idx); + } + return res; +} + +int main(){ + std::iostream::sync_with_stdio(false); + std::cin.tie(nullptr); + + std::cin>>n; + a.resize(n+2); + s.resize(n+2); + t.resize(n+2); + for(ll i=1;i<=n;++i){ + std::cin>>a[i]; + ++a[i]; + } + for(ll i=1;i<=n;++i){ + s[i]=get(a[i]); + upd(a[i],1); + } + std::cout<<"0\n"; + for(ll i=1;i<=n;i++){ + ans+=s[i]; + std::cout< #include -using namespace std; - +#include +#include +#include int main(){ - int a = 1; - a<<=32; - cout<>n; + std::set s; + std::cout<>tmp; + if(s.find(tmp)==s.end()){ + throw std::runtime_error(std::to_string(tmp)); + } + s.insert(tmp); + } } \ No newline at end of file