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
function SegmentTree(size, merge, zero) | |
local tree = {} | |
local function get(v, tl, tr, index) | |
local value = tree[v] or zero | |
if tl == tr then | |
return value | |
end | |
local tm = math.floor((tl + tr) / 2) | |
if index <= tm then |
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
function SegmentTree(size, merge, zero) | |
local tree = {} | |
local function query(v, tl, tr, l, r) | |
if l == tl and r == tr then | |
return tree[v] or zero | |
end | |
local tm = math.floor((tl + tr) / 2) | |
if (r <= tm) then | |
return query(v * 2, tl, tm, l, r) |
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
function BinaryHeap(cmp) | |
local heap = {} | |
local function push(el) | |
table.insert(heap, el) | |
local i = #heap | |
while i > 1 do | |
local parent = math.floor(i / 2) | |
if cmp(heap[parent], heap[i]) then | |
break |
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
function BinarySearchTree(cmp) | |
local root | |
local size = 0 | |
local function has(v, el) | |
if not v then | |
return false | |
end | |
if v.value == el then | |
return true | |
end |
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
class BinaryHeap<T> | |
{ | |
public T[] Heap { get; } | |
public int Count { get; private set; } | |
public IComparer<T> Comparer { get; } | |
public BinaryHeap(int size, IComparer<T> comparer = null) | |
{ | |
Heap = new T[size]; | |
Count = 0; |
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
private static class SegmentTree { | |
private final long[] tree; | |
private final int size; | |
public SegmentTree(int size) { | |
this.tree = new long[size * 4]; | |
this.size = size; | |
} |
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
class SegmentTree: | |
def __init__(self, size, merge=min, default=0): | |
self.size = size | |
self.merge = merge | |
self.tree = [default] * size * 4 | |
pass | |
def build(self, values): | |
self._build(0, 0, self.size-1, values) |
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
import time | |
def timeit(f): | |
def _f(*args, **nargs): | |
begin = time.time() | |
r = f(*args, **nargs) | |
end = time.time() | |
print('Time %2.22f ms' % ((end - begin) * 1000)) | |
return r |
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
Common | |
-Xnovalidate | |
-XnoAneValidate | |
-Xruntime RUNTIME_DIR | |
set | |
-Xdebug | |
For IPA-packaging |
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
function SegmentTree(size, merge, zero) { | |
const tree = []; | |
return { | |
tree, | |
update(index, value) { | |
update(0, 0, size - 1, index, value) | |
}, | |
query(l, r) { | |
return query(0, 0, size - 1, l, r) | |
}, |
NewerOlder