Under construction

Still being built. Things may change

2D Paper Play

Interview

Time limit3sMemory limit512 MB

Summary
For each block, count the sheets with w at least x and h at least y, then answer each query by counting blocks whose count falls in [L, U].
Level

Medium5 of 10

Topics
Sorting, Prefix sum, Implementation
Solved
No attempts yet

Problem

Bob plays with colored paper and blocks on a two-dimensional grid plane. Every block is 1x1, and several blocks can be stacked on the same cell. Suppose there are NN blocks, and let the position of the ii-th block be (xi,yi)(x_i, y_i). In this problem the top-left cell is (1, 1), and the x axis runs left to right. In the top-left layout of the figure below, block 1 is at (2, 2) and block 3 is at (4, 3).

Bob also has MM sheets of paper. The jj-th sheet is wjw_j cells wide and hjh_j cells tall. Paper cannot be rotated.

  • The top-right layout places one 4 x 4 sheet covering (1, 1) through (4, 4). Blocks 1 and 3 fit entirely on this sheet.
  • The bottom-left layout places one 8 x 4 sheet, and it holds 4 blocks.
  • The bottom-right layout places one 9 x 3 sheet, and it holds 3 blocks.

Place the jj-th sheet so that it covers the cells from (1, 1) to (wj,hj)(w_j, h_j). If xi≤wjx_i \le w_j and yi≤hjy_i \le h_j, then the jj-th sheet “includes” the ii-th block. For each ii, let CiC_i be the number of sheets among the MM sheets that include block ii, so 0≤Ci≤M0 \le C_i \le M.

Alice asks QQ questions. The kk-th question gives two integers LkL_k and UkU_k. Find the number of indices ii that satisfy Lk≤Ci≤UkL_k \le C_i \le U_k.

For example, with N=5N = 5, x=[2,4,8,7,3]x = [2, 4, 8, 7, 3], y=[2,3,3,4,5]y = [2, 3, 3, 4, 5], M=3M = 3, w=[4,8,9]w = [4, 8, 9], and h=[4,4,3]h = [4, 4, 3], the values are C1=3C_1 = 3, C2=2C_2 = 2, C3=3C_3 = 3, C4=1C_4 = 1, and C5=0C_5 = 0.

Input

The first line contains the number of test cases TT.

The first line of each test case contains NN, MM, and QQ, separated by spaces. The next NN lines each contain xix_i and yiy_i. The next MM lines each contain wjw_j and hjh_j. The next QQ lines each contain LkL_k and UkU_k.

Output

For each test case, print the answers to the QQ questions on one line, separated by spaces.

Examples1

  1. Example 1

    Input
    2
    5 3 5
    2 2
    8 3
    4 3
    7 4
    3 5
    4 4
    8 4
    9 3
    0 2
    1 3
    0 3
    1 1
    2 3
    5 3 3
    1 1
    2 2
    1 1
    2 2
    3 3
    1 3
    3 1
    2 3
    0 1
    1 2
    0 3
    
    Expected output
    3 4 5 1 3
    3 2 5