Rating changes for last rounds are temporarily rolled back. They will be returned soon. ×

Runtime without vector.reserve

Revision en2, by PaciukZvichainyi, 2022-09-23 20:35:53

Why I got Runtime Error on first test w/o vector reserve and got Accepted with reserve?

Without

With

The only difference is line 77 (if you open it in text editor).

Also, it passes test on local machine even without reserve statement.

RE

ImplicitSegmentTree(int l, int r) {
	lb = l; rb = r;
	n = r-l+1;
	next = 0;
	// TODO Change
	// nodes.reserve(4831707);
	nodes.push_back(Node());
	root = &nodes[next++];
}

OK

ImplicitSegmentTree(int l, int r) {
	lb = l; rb = r;
	n = r-l+1;
	next = 0;
	// TODO Change
	nodes.reserve(4831707);
	nodes.push_back(Node());
	root = &nodes[next++];
}

And last: the memory limit isn't a problem with this solution, because even with reserve(1e7) it works fine.

Tags segment tree, memory, runtime error, c++

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English PaciukZvichainyi 2022-09-23 20:35:53 326 Add code example
en1 English PaciukZvichainyi 2022-09-23 20:32:12 593 Initial revision (published)