Last active
August 29, 2021 22:12
-
-
Save nhalq/aa79f077b2f3d1ca079b4d3e6709e963 to your computer and use it in GitHub Desktop.
Competitive programming template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
//////// DATA TYPE //////// | |
template<typename DType> | |
using Vector2D = std::vector<std::vector<DType>>; | |
//////// BINARY OPERATORS //////// | |
template<typename DType> | |
struct MinOper { | |
DType operator()(const DType& shl, const DType& shr) const { | |
return std::min(shl, shr); | |
} | |
}; | |
template<typename DType> | |
struct MaxOper { | |
DType operator()(const DType& shl, const DType& shr) const { | |
return std::max(shl, shr); | |
} | |
}; | |
//////// SPREAD TABLE //////// | |
template<typename DType, class BFunc> | |
class SpreadTable { | |
public: | |
SpreadTable(const std::vector<DType>& arr) : | |
m_Size(static_cast<int>(arr.size())), | |
m_Table(32 - __builtin_clz(arr.size())) | |
{ | |
*m_Table.begin() = arr; | |
for (size_t lg = 1; lg < m_Table.size(); ++lg) { | |
m_Table[lg].resize(m_Size - (1 << lg) + 1); | |
for (size_t i = 0; i < m_Table[lg].size(); ++i) { | |
m_Table[lg][i] = m_BFunc(m_Table[lg - 1][i], m_Table[lg - 1][i + (1 << (lg - 1))]); | |
} | |
} | |
} | |
DType get(size_t u, size_t v) const { | |
assert(0 <= u && u <= v && v < m_Size); | |
int lg = 32 - __builtin_clz(v - u + 1) - 1; | |
return m_BFunc(m_Table[lg][u], m_Table[lg][v - (1 << lg) + 1]); | |
} | |
private: | |
size_t m_Size; | |
Vector2D<DType> m_Table; | |
BFunc m_BFunc; | |
}; | |
//////// MAIN FUNCTION //////// | |
int main(const int argc, const char** argv) { | |
std::ios::sync_with_stdio(false); | |
std::cout.tie(nullptr), std::cin.tie(nullptr); | |
int num_tests; | |
std::cin >> num_tests; | |
while (num_tests--) { | |
// Solution | |
} | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment