-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from oitl-5ab/indev-1
Indev-1.2 Finished Coding.
- Loading branch information
Showing
16 changed files
with
325 additions
and
283 deletions.
There are no files selected for viewing
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
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
Empty file.
This file was deleted.
Oops, something went wrong.
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
Empty file.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,99 @@ | ||
#ifndef OITL_SPARSE_TABLE_HPP | ||
#define OITL_SPARSE_TABLE_HPP | ||
#ifndef _OITL_ASSETS_SPARSE_TABLE | ||
#define _OITL_ASSETS_SPARSE_TABLE 1 | ||
|
||
#include <vector> | ||
|
||
#if __cplusplus >= 201103L | ||
#include <array> | ||
#endif | ||
|
||
namespace oitl | ||
{ | ||
template<int n, typename val_t = long long> | ||
class sparse_table | ||
{ | ||
private: | ||
namespace __oitl_builtin | ||
{ | ||
template<int _N> | ||
class _Pow_tab | ||
{ | ||
private: | ||
|
||
#if __cplusplus >= 201103L | ||
std::array<int, _N> __val; | ||
#else | ||
int __val[_N]; | ||
#endif | ||
|
||
public: | ||
|
||
_Pow_tab() | ||
{ | ||
int __lay = -1, __pw = 1; | ||
|
||
for (register int __i = 0; __i < _N; ++__i) | ||
{ | ||
if (__pw == __i) | ||
++__lay, __pw <<= 1; | ||
|
||
__val[__i] = __lay; | ||
} | ||
} | ||
|
||
int operator[](int id) const | ||
{ | ||
return __val[id]; | ||
} | ||
}; | ||
} | ||
|
||
template<int _N, class _Val_t, class _Op> | ||
class sparse_table | ||
{ | ||
public: | ||
|
||
typedef _Val_t value_type; | ||
typedef _Op operate_type; | ||
|
||
private: | ||
|
||
std::vector<std::vector<value_type> > __tab; | ||
__oitl_builtin::_Pow_tab<_N> __ask; | ||
|
||
operate_type __calc; | ||
|
||
public: | ||
|
||
struct __line | ||
{ | ||
__id_type __up; | ||
val_t __rmq[n]; | ||
}; | ||
sparse_table() { } | ||
|
||
std::vector<__line> __tab; | ||
template<typename _Iterator> | ||
void refill(_Iterator __lp) | ||
{ | ||
register int __cra = 1, __ptr = 0, __tar = 0; | ||
_Iterator __rp = __lp; | ||
|
||
template<typename it> | ||
void build(it __l, it __r) | ||
{ | ||
__tab.clear(); | ||
__tab.push_back(std::vector<value_type>(_N)); | ||
|
||
for (register int __i = 0; __i < _N; ++__i) | ||
++__rp; | ||
__tab[0].assign(__lp, __rp); | ||
|
||
} | ||
|
||
public: | ||
while (__tab[__ptr].size() > __cra) | ||
{ | ||
++__ptr; | ||
__tab.push_back(std::vector<value_type>()); | ||
|
||
sparse_table() { } | ||
sparse_table(const sparse_table<n, val_t>& __st) | ||
{ | ||
for (register int __i = __cra; __i < __tab[__tar].size(); ++__i) | ||
__tab[__ptr].push_back(__calc(__tab[__tar][__i-__cra], __tab[__tar][__i])); | ||
|
||
} | ||
++__tar, __cra <<= 1; | ||
} | ||
} | ||
|
||
~sparse_table() { } | ||
}; | ||
value_type query(int __lp, int __rp) const | ||
{ | ||
return __calc(__tab[__ask[__rp-__lp]][__lp], | ||
__tab[__ask[__rp-__lp]][__rp-(1<<__ask[__rp-__lp])]); | ||
} | ||
}; | ||
} | ||
|
||
#endif |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.