Eggscavation

Given up to 100000 shell species (each in at most 4 cells) and egg insertions, answer queries for the probability that a random K x K scoop covers at least V species and no egg.

Hard9GeometryPrefix sumCombinatoricsImplementationNo attempts yetTime limit10sMemory limit512 MB

Problem

You are taking a vacation. Writing C shell scripts got old, so you have decided to collect seashells instead.

The island nation of Cartesia has a square beach made of an N×NN \times N grid of square cells. Your shovel scoops up one K×KK \times K square subgrid of the beach, and that subgrid must lie entirely inside the beach, so there are exactly (NK+1)2(N - K + 1)^2 places where you can dig.

There are MM undiscovered species of shells buried under the cells. Species ii has SiS_i shells, one in each of SiS_i grid cells, with 1Si41 \le S_i \le 4. A scientist back home pays you one dollar for every distinct species you bring back. Extra shells of a species you already have are worth nothing, so the profit of a scoop is the number of species that have at least one shell inside the dug subgrid.

A dodo bird runs around the beach. Every so often it buries an egg in a grid cell, including cells that already hold eggs or shells. If the K×KK \times K subgrid you dig contains at least one dodo egg, the scientists get angry that you are harming an endangered species and nobody pays you anything, so that scoop has a profit of 0 dollars.

At several points in time you want the probability that a scoop, chosen uniformly at random among all the places where you can dig, earns a profit of at least a given amount.

Input

The first line contains two integers NN and KK, the size of the beach and the size of the shovel (1N25001 \le N \le 2500, 1KN1 \le K \le N).

The second line contains the integer MM, the number of species of shells (0M1050 \le M \le 10^5). Each of the next MM lines describes one species. Line ii starts with the integer SiS_i (1Si41 \le S_i \le 4) and continues with 2×Si2 \times S_i more integers, the cells between (1,1)(1, 1) and (N,N)(N, N) where the SiS_i shells of that species are buried. Cell (r,c)(r, c) is the cell in row rr and column cc.

The next line contains TT (1T100001 \le T \le 10\,000). Each of the next TT lines is one point in time, given from oldest to newest, in one of these two forms:

  • 1 A B: the dodo just buried an egg in cell (A,B)(A, B) (1A,BN1 \le A, B \le N).
  • 2 V: report the probability that a random dig at this moment has a profit of at least VV dollars (1V1091 \le V \le 10^9). Computing this probability removes nothing and adds nothing, so the shells and the eggs stay where they are.

Output

For each 2 V line, print on its own line the probability that a random scoop earns a profit of at least VV dollars.

Print the probability rounded to exactly five digits after the decimal point, and round up when the sixth digit is 5 or more. A probability of 8/98/9 prints as 0.88889, a probability of 0 prints as 0.00000, and a probability of 1 prints as 1.00000.