Silver Mine
Time limit1sMemory limit1024 MB
After each flip of a full row or column of an N by N grid, print the maximum mine count in a K by K window of lattice points and how many windows reach it.
- Level
Hard8 of 10
- Topics
- Segment tree, Prefix sum, Sliding window
- Solved
- No attempts yet
Problem
A country is nicknamed the Land of Silver. Many undeveloped silver mines are believed to exist there. Silver mines can only be placed on the lattice points whose x and y coordinates are each between 1 and N, inclusive. Originally, the country had no silver mines at all. Feeling sorry for it, the wizard Messi decided to use magic to create silver mines there. Messi has two kinds of magic. The first removes the silver mine from each point with x coordinate equal to a given value that has one, and creates one at each point that has none. The second applies the same operation to the N points with a given y coordinate. A silver mine developer buys a square plot R with sides parallel to the x or y axis, measuring , and develops every silver mine inside R. The x and y coordinates of the corners of R must be integers between 1 and N, inclusive. The development profit is the number of silver mines inside R or on its boundary. The developer finds every region R that gives the maximum profit. Each time Messi uses magic, find the maximum profit the developer can earn by buying a square plot, and the number of ways to achieve that maximum. Become a silver tycoon! Note that buying a square plot lets the developer develop exactly one lattice point's silver mine.
Input
The first line contains N, K, and Q, separated by spaces. Each of the next Q lines contains a and b, separated by a space. If a = 1, the states of the lattice points with x coordinate b are flipped. If a = 2, the states of the lattice points with y coordinate b are flipped. (, )
Output
After each magic use by Messi, print on one line the maximum number of silver mines the developer can develop, and the number of ways to achieve it, separated by a space.
Constraints