generated from Tiphereth-A/TINplate
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: mono_{stack,queue} & hoverline
- Loading branch information
1 parent
ca65969
commit 9f28ae5
Showing
38 changed files
with
316,441 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#ifndef TIFALIBS_DS_MONO_QUEUE | ||
#define TIFALIBS_DS_MONO_QUEUE | ||
|
||
#include "../util/util.hpp" | ||
|
||
namespace tifa_libs::ds { | ||
|
||
template <class T, class Comp = std::less<T>> | ||
class mono_queue { | ||
static CEXP Comp compare{}; | ||
|
||
const u32 k; | ||
u32 i; | ||
std::deque<std::pair<T, u32>> q; | ||
|
||
public: | ||
CEXPE mono_queue(u32 k) NE : k{k}, i{0} { assert(k > 0); } | ||
// @return minimum of last k (at most) pushed elements | ||
CEXP T CR push(cT_(T) x) NE { | ||
if (!q.empty() && q.front().second + k == i) q.pop_front(); | ||
while (!q.empty() && compare(x, q.back().first)) q.pop_back(); | ||
q.emplace_back(x, i++); | ||
return q.front().first; | ||
} | ||
}; | ||
|
||
} // namespace tifa_libs::ds | ||
|
||
#endif |
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#ifndef TIFALIBS_DS_MONO_STACK | ||
#define TIFALIBS_DS_MONO_STACK | ||
|
||
#include "../util/util.hpp" | ||
|
||
namespace tifa_libs::ds { | ||
|
||
template <class T, class Comp = std::less<T>> | ||
class mono_stack { | ||
static CEXP Comp compare{}; | ||
|
||
vec<T> s; | ||
template <bool use_bf = false> | ||
CEXP auto find_(cT_(T) x) NE { | ||
if CEXP (use_bf) { | ||
auto it = s.rbegin(); | ||
while (it != s.rend() && compare(x, *it)) ++it; | ||
return (--it).base(); | ||
} else return upper_bound(s, x, compare); | ||
} | ||
|
||
public: | ||
CEXPE mono_stack() NE = default; | ||
|
||
template <bool use_bf = false> | ||
CEXP void pop_greater(cT_(T) x) NE { s.erase(find_<use_bf>(x), s.end()); } | ||
CEXP void push_nocheck(cT_(T) x) NE { s.push_back(x); } | ||
template <bool use_bf = false> | ||
CEXP void push(cT_(T) x) NE { pop_greater<use_bf>(x), s.push_back(x); } | ||
template <bool use_bf = false> | ||
CEXP void insert(cT_(T) x) NE { | ||
if (auto it = find_<use_bf>(x); it == s.end()) s.push_back(x); | ||
else *it = x; | ||
} | ||
CEXP T CR top() CNE { return s.back(); } | ||
CEXP u32 size() CNE { return (u32)s.size(); } | ||
}; | ||
|
||
} // namespace tifa_libs::ds | ||
|
||
#endif |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#ifndef TIFALIBS_OPT_HOVERLINE | ||
#define TIFALIBS_OPT_HOVERLINE | ||
|
||
#include "../util/util.hpp" | ||
|
||
namespace tifa_libs::opt { | ||
|
||
// @return {l, r} s.t. $\forall x\in[l_i,r_i],~a_x\geq a_i$, $l_i$ leftmost, $r_i$ rightmost | ||
template <class T, class C = std::less<T>> | ||
CEXP ptt<vecu> hoverline(vec<T> CR a, C&& comp = C{}) NE { | ||
if (a.empty()) return {{}, {}}; | ||
vecu l(a.size()); | ||
std::iota(l.begin(), l.end(), 0_u32); | ||
auto r = l; | ||
flt_ (u32, i, 0, (u32)a.size()) | ||
while (l[i] && !comp(a[l[i] - 1], a[i])) l[i] = l[l[i] - 1]; | ||
for (u32 i = (u32)a.size() - 2; ~i; --i) | ||
while ((i32)r[i] < (i32)a.size() - 1 && !comp(a[r[i] + 1], a[i])) r[i] = r[r[i] + 1]; | ||
return {l, r}; | ||
} | ||
|
||
} // namespace tifa_libs::opt | ||
|
||
#endif |
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 |
---|---|---|
@@ -0,0 +1,101 @@ | ||
100 | ||
100005758 | ||
99995645 | ||
99978130 | ||
99947079 | ||
99941452 | ||
99918442 | ||
99911023 | ||
99894811 | ||
99890725 | ||
99887976 | ||
99875209 | ||
99866125 | ||
99854065 | ||
99821840 | ||
99804297 | ||
99779208 | ||
99758025 | ||
99732888 | ||
99707322 | ||
99680356 | ||
99675378 | ||
99654883 | ||
99644572 | ||
99633205 | ||
99603151 | ||
99586120 | ||
99572975 | ||
99553093 | ||
99527357 | ||
99496833 | ||
99468328 | ||
99439934 | ||
99417832 | ||
99392981 | ||
99373914 | ||
99361160 | ||
99349507 | ||
99342946 | ||
99315850 | ||
100032085 | ||
100027942 | ||
100020975 | ||
99989569 | ||
99965404 | ||
99952001 | ||
99926439 | ||
99901605 | ||
99870252 | ||
99869332 | ||
99858888 | ||
99834085 | ||
99826123 | ||
99806805 | ||
99805383 | ||
99774056 | ||
99763599 | ||
99761654 | ||
99747175 | ||
99717192 | ||
99698441 | ||
99694547 | ||
99675877 | ||
99667618 | ||
99651370 | ||
99643613 | ||
99627984 | ||
99614678 | ||
99586072 | ||
99572082 | ||
99560344 | ||
99547828 | ||
99546414 | ||
99541152 | ||
99524036 | ||
99501211 | ||
99498030 | ||
99484896 | ||
99459553 | ||
99451531 | ||
99440298 | ||
99432762 | ||
99423002 | ||
99413023 | ||
99383952 | ||
99382751 | ||
99361415 | ||
99348354 | ||
99326194 | ||
99302189 | ||
99271460 | ||
99263816 | ||
99236341 | ||
99204648 | ||
99179134 | ||
99164995 | ||
99142907 | ||
99116386 | ||
99111184 | ||
99102013 | ||
99097579 |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
2571 |
Oops, something went wrong.