diff --git a/src/8/31/P5200.cpp b/src/8/31/P5200.cpp new file mode 100644 index 0000000..e0c9b13 --- /dev/null +++ b/src/8/31/P5200.cpp @@ -0,0 +1,65 @@ +#include +#include +#include +#include +using ll = int64_t; + +ll n; +std::vector v,t,ans; + +#define pv(v)do{std::cout<<#v<<" :"<<(v)<<"\n";}while(0) + +static inline constexpr ll lowbit(ll n){ + return n&(-n); +} + +static inline void set(ll idx,ll addval){ + while(idx<=n){ + t[idx]+=addval; + idx+=lowbit(idx); + } +} + +static inline ll getsfx(ll idx){ + ll res=0; + while(idx){ + res+=t[idx]; + idx-=lowbit(idx); + } + return res; +} + +static inline ll getrange(ll l,ll r){ + return getsfx(r)-getsfx(l-1); +} + +int main(){ + std::iostream::sync_with_stdio(false); + std::cin.tie(nullptr); + + std::cin>>n; + v.resize(n+1); + t.resize(n+1); + ans.reserve(n+1); + for(ll i=1;i<=n;++i){ + std::cin>>v[i]; + } + ll idx=n; + for(;idx>=2 && v[idx-1]<=v[idx];--idx); + // pv(idx); + for(ll i=idx;i<=n;i++){ + set(v[i], 1); + } + ll sum=0; + for(ll i=1;i