I'm trying to solve a problem http://www.e-olimp.com.ua/ru/problems/4483. I'm building a segment tree: every node of tree stores 2 minimal elements of particular segment. Code: http://ideone.com/Kjk0BQ. But it fails with memory limit, most likely because of line 110. Is it possible to optimize every time array creation?
Instead of keeping 2 int variable, you can keep a boolean (b) and a integer (m). Boolean is the expected answer. The other variable contains the minimal element in its range. As K is fixed, so
Thus you can avoid that line :s