From 48ef07ec43b2af2f30ff2e8f7ed22bb62f7e3b5d Mon Sep 17 00:00:00 2001 From: Zengtudor Date: Tue, 19 Aug 2025 10:03:05 +0800 Subject: [PATCH] update --- src/8/18/sparsetable.cpp | 47 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/8/18/sparsetable.cpp diff --git a/src/8/18/sparsetable.cpp b/src/8/18/sparsetable.cpp new file mode 100644 index 0000000..78a1695 --- /dev/null +++ b/src/8/18/sparsetable.cpp @@ -0,0 +1,47 @@ +#include +#include +#include +#include +#include + +using ll = int64_t; + +std::vector lg2,nums; +std::vector> st; + +int main(){ + std::iostream::sync_with_stdio(false); + std::cin.tie(nullptr); + ll n; + std::cin>>n; + ll q; + std::cin>>q; + nums.resize(n+1); + lg2.resize(1e5+5); + for(ll i=2;i<1e5+5;i++){ + lg2[i]=lg2[i>>1]+1; + } + st.resize(n+1,std::vector(lg2[n]+2)); + for(ll i=1;i<=n;i++){ + std::cin>>nums[i]; + st[i][0]=nums[i]; + } + + for(ll j=1;jn){ + break; + } + st[i][j]=std::max(st[i][j-1],st[i+(1ll<<(j-1))][j-1]); + } + } + while(q--){ + ll l,r; + std::cin>>l>>r; + ll range = r-l+1; + ll k=lg2[range]; + std::cout<< + std::max(st[l][k],st[r-(1ll<