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.
Medium6IntervalsTreeSimulationImplementationInterviewNo attempts yetTime limit3sMemory limit512 MBFarmer Yam bought a piece of land and will turn it into a carrot farm. The land is a rectangle that is W (1≤W≤108) units wide and L (1≤L≤10) units long, and Yam thinks of it as an integer grid. The cells are numbered 0,1,…,L−1 along the length and 0,1,…,W−1 along the width.
Yam wrote down a plan of n (1≤n≤50000) 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 a to b 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 a to b 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 L. When there is no such land, report 0.
The first line contains the number of test cases T (1≤T≤7).
Each test case starts with a line that holds three space separated integers W, L, and n.
Each of the next n lines describes one action in the form action a b, where action is either plant or harvest, and a and b (0≤a≤b≤W−1) are the lowest and the highest cell number the action covers.
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.