This file contains hidden or 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
SegmentTreeNode query(int stIndex, int start, int end) { | |
if (nodes[stIndex].start == start && nodes[stIndex].end == end) { | |
SegmentTreeNode result = nodes[stIndex]; | |
if (result.hasPendingUpdate()) | |
result.applyPendingUpdate(); | |
return result; | |
} | |
int mid = (nodes[stIndex].start + nodes[stIndex].end) >> 1, | |
leftChildIndex = stIndex << 1, |
This file contains hidden or 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
struct SegmentTreeNode { | |
int start, end; // this node is responsible for the segment [start...end] | |
ll total; | |
bool pendingUpdate; | |
SegmentTreeNode() : total(0), pendingUpdate(false) {} | |
void assignLeaf(ll value) { | |
total = value; | |
} |
This file contains hidden or 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
void update(int stIndex, int start, int end, UpdateType value) { | |
if (nodes[stIndex].start == start && nodes[stIndex].end == end) { | |
lazyPropagatePendingUpdateToSubtree(stIndex, value); | |
return; | |
} | |
int mid = (nodes[stIndex].start + nodes[stIndex].end) >> 1, | |
leftChildIndex = stIndex << 1, | |
rightChildIndex = leftChildIndex + 1; | |
This file contains hidden or 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
struct SegmentTreeNode { | |
int start, end; // this node is responsible for the segment [start...end] | |
double total; | |
void assignLeaf(double value) { | |
total = value; | |
} | |
void merge(SegmentTreeNode& left, SegmentTreeNode& right) { | |
total = left.total + right.total; |
This file contains hidden or 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
void update(int stIndex, int start, int end, UpdateType value) { | |
if (start == end) { | |
nodes[stIndex].applyUpdate(value); | |
return; | |
} | |
int mid = (nodes[stIndex].start + nodes[stIndex].end) / 2, | |
leftChildIndex = 2 * stIndex, | |
rightChildIndex = leftChildIndex + 1; | |
This file contains hidden or 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
template<class InputType, class UpdateType, class OutputType> | |
class SegmentTree { | |
SegmentTreeNode* nodes; | |
int N; | |
public: | |
SegmentTree(InputType arr[], int N) { | |
this->N = N; | |
nodes = new SegmentTreeNode[getSegmentTreeSize(N)]; | |
buildTree(arr, 1, 0, N-1); |
This file contains hidden or 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
struct SegmentTreeNode { | |
int start, end; // this node is responsible for the segment [start...end] | |
// variables to store aggregate statistics and | |
// any other information required to merge these | |
// aggregate statistics to form parent nodes | |
void assignLeaf(InputType value) { | |
// InputType is the type of input array element | |
// Given the value of an input array element, |
This file contains hidden or 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 random, os | |
# define constants | |
correct_program = "correct.exe" | |
incorrect_program = "incorrect.exe" | |
input_file = "input.txt" | |
correct_output = "correct_output.txt" | |
incorrect_output = "incorrect_output.txt" | |
num_testcases = 10 |
This file contains hidden or 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
struct SegmentTreeNode { | |
int maxNum, secondMaxNum; | |
void assignLeaf(int num) { | |
maxNum = num; | |
secondMaxNum = -1; | |
} | |
void merge(SegmentTreeNode& left, SegmentTreeNode& right) { | |
maxNum = max(left.maxNum, right.maxNum); |
This file contains hidden or 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
struct SegmentTreeNode { | |
int unmatchedOpenParans, unmatchedClosedParans; | |
void assignLeaf(char paranthesis) { | |
if (paranthesis == '(') | |
unmatchedOpenParans = 1, unmatchedClosedParans = 0; | |
else | |
unmatchedOpenParans = 0, unmatchedClosedParans = 1; | |
} | |