[FreivaldsAlgorithm]The Freivalds Algorithm is an algorithm that determines w...Bomm Kim
油
The Freivalds Algorithm is an algorithm that determines whether AB=C is true/false with a time complexity of O(n2) when there are matrices A, B, and C.
This is a slide with an explanation and implementation code.
25. Segment Tree 一
Python/C++ Code
def calc_stree(stree: List, L: int, R: int):
length = len(stree) // 2
ret = 0
left = L 1 + length
right = R 1 + length
while left <= right:
if left % 2 == 1:
ret += stree[left]
left += 1
if right % 2 == 0:
ret += stree[right]
right -= 1
left //= 2
right //= 2
return ret
lld calc_stree(const vector<lld>& stree, const int L, const int R) {
const lld length = stree.size() / 2;
lld ret = 0;
lld left = L 1 + length;
lld right = R 1 + length;
for (left, right; left <= right; left /= 2, right /= 2) {
if (left % 2 == 1) {
ret += stree[left];
left++;
}
if (right % 2 == 0) {
ret += stree[right];
right--;
}
}
return ret;
}
Python
C++