Skip to content

Commit

Permalink
Merge pull request #5 from oitl-5ab/indev-1
Browse files Browse the repository at this point in the history
Indev-1.2 Finished Coding.
  • Loading branch information
oitl-5ab authored Sep 25, 2020
2 parents 8558cea + 7d29c82 commit 2b85e33
Show file tree
Hide file tree
Showing 16 changed files with 325 additions and 283 deletions.
6 changes: 3 additions & 3 deletions assets/bad_assert.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace oitl

public:

std_error(const std::string &_s = "") : s("[OI Template Library] " + _s) { }
std_error(const std::string &_s = "") : s("[OITL] " + _s) { }
~std_error() { s.clear(); }

const char* what() { return s.c_str(); }
Expand All @@ -32,7 +32,7 @@ namespace oitl
template<typename T>
void __oitl_range_assert(const T &a, const T &b)
{
__oitl_assert(a <= b, "Input not make a range.");
__oitl_assert(a <= b, "Input do not make a range.");
}

// Check the range [l, r]
Expand All @@ -44,7 +44,7 @@ namespace oitl

void __oitl_array_assert(const int& len, const int& id)
{
__oitl_assert(id >= 0 && len > id, "Visit out of array.");
__oitl_assert(id >= 0 && len > id, "Not a vaild index.");
}
}

Expand Down
2 changes: 1 addition & 1 deletion assets/binary_indexed_tree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ namespace oitl

public:

binary_indexed_tree(value_type _Identity = value_type(0)) : __identity(_Identity)
explicit binary_indexed_tree(value_type _Identity = value_type(0)) : __identity(_Identity)
{
#if __cplusplus >= 201103L
__bit.fill(__identity);
Expand Down
Empty file removed assets/decimal.hpp
Empty file.
68 changes: 0 additions & 68 deletions assets/disjoint_set.hpp

This file was deleted.

17 changes: 13 additions & 4 deletions assets/disjoint_set_union.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace oitl

public:

disjoint_set_union(int __siz = 0)
explicit disjoint_set_union(int __siz = 0)
{
__dsu.resize(__siz);
for (register int __i = 0; __i < __siz; ++__i)
Expand All @@ -30,14 +30,14 @@ namespace oitl

bool empty() const { return __dsu.size() == 0; }
int size() const { return __dsu.size(); }
void reset() { __dsu.clear(); }
void clear() { __dsu.clear(); }

bool same_set(int __ap, int __bp)
{
return _Find_root(__ap) == _Find_root(__bp);
}

void unite_sets(int __ap, int __bp)
void unite(int __ap, int __bp)
{
if (same_set(__ap, __bp))
return;
Expand All @@ -51,7 +51,7 @@ namespace oitl
return __dsu.size() - 1;
}

void clear()
void reset()
{
for (register int __i = 0; __i < __dsu.size(); ++__i)
__dsu[__i] = __i;
Expand All @@ -65,7 +65,16 @@ namespace oitl
__dsu.push_back(__i);
}
else
{
for (register int __i = 0; __i < __siz; ++__i)
if (_Find_root(__i) >= __siz)
{
__dsu[_Find_root(__i)] = __i;
__dsu[__i] = __i;
}

__dsu.resize(__siz);
}
}
};
}
Expand Down
Empty file removed assets/longint.hpp
Empty file.
4 changes: 2 additions & 2 deletions assets/oitl_basic.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef OITL_BASIC_HPP
#define OITL_BASIC_HPP
#ifndef _OITL_ASSETS_BASIC
#define _OITL_ASSETS_BASIC 1

#define OITL_UPD 20200309L

Expand Down
108 changes: 84 additions & 24 deletions assets/sparse_table.hpp
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
8 changes: 0 additions & 8 deletions disjoint_set

This file was deleted.

Loading

0 comments on commit 2b85e33

Please sign in to comment.