I'm solving a problem with the segment tree. It has got a very strict memory limit, so I don't want to use extra n memory for remembering information about single segments and return it from the array I built the tree from.
...
struct SegTree {
vector<int>* singleElements;
vector<int> tree;
SegTree() : singleElements(nullptr) {}
SegTree(vector<int>* arr) : singleElements(arr) {
tree.resize(arr.size() - 1);
build(...);
}
...
}
int main() {
vector<int> a(10, 1), b(10, -1);
SegTree st1(a);
SegTree st2();
st2.assign(b);
return 0;
}
I am not sure with this part of c++. Sorry for my bad English.