Jian-Jia is building a wall by stacking bricks of the same size together. This wall consists of
Jian-Jia builds the wall as follows. Initially there are no bricks in any column. Then, Jian-Jia goes through
- In an adding phase, Jian-Jia adds bricks to those columns in the given range that have less than
bricks, so that they have exactly bricks. He does nothing on the columns having or more bricks. - In a removing phase, Jian-Jia removes bricks from those columns in the given range that have more than
bricks, so that they have exactly bricks. He does nothing on the columns having bricks or less.
Your task is to determine the final shape of the wall.
Example
We assume that there are
phase | type | range | height |
---|---|---|---|
0 | add | columns |
|
1 | remove | columns |
|
2 | remove | columns |
|
3 | add | columns |
|
4 | add | columns |
|
5 | remove | columns |
Since all columns are initially empty, after phase
Given the description of the buildWall
.
buildWall(n, k, op, left, right, height, finalHeight)
n
: the number of columns on the wall.k
: the number of phases.op
: array of length ;op[i]
is the type of phase : for an adding phase and for a removing phase, for .left
andright
: arrays of length ; the range of columns in phase starts with columnleft[i]
and ends with columnright[i]
(including endpointsleft[i]
andright[i]
), for . You will always haveleft[i]
right[i]
.height
: array of lengthk
;height[i]
is the height parameter of phase , for .finalHeight
: array of length ; you should return your results by placing the final number of bricks in column intofinalHeight[i]
, for .
Subtasks
For all subtasks the height parameters of all phases are nonnegative integers less or equal to
subtask | points | note | ||
---|---|---|---|---|
1 | 8 | no additional limits | ||
2 | 24 | all adding phases are before all removing phases | ||
3 | 29 | no additional limits | ||
4 | 39 | no additional limits |
Implementation details
Your submission should implement the subprogram described above using the following signatures.
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]);
Comments
that's a pretty long wall
who's gonna pay for it?
MEXICOOOOO!