版本比较
【模板】ST表
正文
增加 32 行删除 0 行
1234567891011121314151617181920212223242526272829303132333435369 行未改动4647484950:::warning{open}代码未经充分测试,正确性未知。:::
```cpptemplate<typename T>struct maximum{constexpr T operator()(const T&a,const T&b)const{return std::max(a,b);}};template<typename T>struct minimum{constexpr T operator()(const T&a,const T&b)const{return std::min(a,b);}};template <typename T,typename C>struct ST{ static const int N = 1e5+5,M = 20; static inline const C comp; static inline int lg[N]; T rmq[N][M]; void init(int n,T *a) { static auto __init = [](){ lg[0] = -1; for (int i = 1;i < N;i ++) lg[i] = lg[i/2]+1; return 0; }(); for (int i = 1;i <= n;i ++) rmq[i][0] = a[i]; for (int i = 1;i <= lg[n];i ++) for (int j = 1;j <= n-(1<<i)+1;j ++) rmq[j][i] = comp(rmq[j][i-1],rmq[j+(1<<i-1)][i-1]); } T query(int l,int r) {return comp(rmq[l][lg[r-l+1]],rmq[r-(1<<lg[r-l+1])+1][lg[r-l+1]]);}};```
:::error[弃用]```cpptemplate <typename T>struct RMQ{ static const int N = 1e6+5,M = 21;9 行未改动 } inline T query(int l,int r) {return cmp(rmq[l][lg[r-l+1]],rmq[r-(1<<lg[r-l+1])+1][lg[r-l+1]]);}};```:::