Carrot Farm
InterviewTime limit3sMemory limit512 MB
Maintain a set of disjoint planted intervals under plant and harvest operations; after each, report the empty or planted area directly left and right of the affected span. Each area is (number of columns) times L.
- Level
Medium6 of 10
- Topics
- Intervals, Tree, Simulation, Implementation
- Solved
- No attempts yet
Problem
Farmer Yam bought a piece of land and will turn it into a carrot farm. The land is a rectangle that is () units wide and () units long, and Yam thinks of it as an integer grid. The cells are numbered along the length and along the width.
Yam wrote down a plan of () actions. There are only two kinds of actions, planting seeds and harvesting, and Yam can mix them in any order. The land is empty at the start. Simulate the plan and report two numbers for every action.
A planting action plant a b sows seeds in cells to along the width, over the full length of the land. The new area never overlaps an existing plantation, but it may touch one. Plantations that touch are merged into a single plantation. After the merge, report the area of the empty land that lies immediately to the left of the plantation just created, and then the area of the empty land that lies immediately to its right.

A harvesting action harvest a b harvests cells to along the width, over the full length of the land. A harvest can split one plantation into two. Every harvested area lies completely inside a single plantation. Report the area of the planted land that lies immediately to the left of the area just harvested, and then the area of the planted land that lies immediately to its right.

An area is the number of cells along the width multiplied by . When there is no such land, report 0.
Input
The first line contains the number of test cases ().
Each test case starts with a line that holds three space separated integers , , and .
Each of the next lines describes one action in the form action a b, where action is either plant or harvest, and and () are the lowest and the highest cell number the action covers.
Output
For each action, print the two numbers you have to report on their own line, separated by a single space.
After the last action of every test case, print a line that contains only --, without the quotes.