AT_abc482_c [ABC482C] Band Count

Description

There is a grid with $ H $ rows and $ W $ columns. Let $ (i,j) $ denote the cell at the $ i $ -th row from the top and the $ j $ -th column from the left. There are $ N $ pieces placed on the grid, and the $ i $ -th piece is at $ (R_i, C_i) $ . Answer $ Q $ queries. Each query is of one of the following $ 2 $ types. - `1 u d`: Print the number of pieces placed in rows $ u $ through $ d $ . - `2 l r`: Print the number of pieces placed in columns $ l $ through $ r $ .

Input Format

The input is given from Standard Input in the following format: > $ H $ $ W $ $ N $ $ Q $ $ R_1 $ $ C_1 $ $ R_2 $ $ C_2 $ $ \vdots $ $ R_N $ $ C_N $ $ \mathrm{query}_1 $ $ \mathrm{query}_2 $ $ \vdots $ $ \mathrm{query}_Q $ Each query $ \mathrm{query}_q $ is given in one of the following formats: > $ 1 $ $ u $ $ d $ > $ 2 $ $ l $ $ r $

Output Format

Print $ Q $ lines. The $ i $ -th line should contain the answer to the $ i $ -th query.

Explanation/Hint

### Sample Explanation 1 For the $ 1 $ -st query, the pieces in rows $ 2 $ through $ 4 $ are the $ 2 $ -nd, $ 3 $ -rd, and $ 4 $ -th pieces, for a total of $ 3 $ . ### Constraints - $ 1 \leq H, W \leq 10^9 $ - $ 1 \leq N \leq \min(H \times W, 3 \times 10^5) $ - $ 1 \leq R_i \leq H $ - $ 1 \leq C_i \leq W $ - $ (R_i, C_i) \neq (R_j, C_j) $ if $ i \neq j $ . - $ 1 \leq Q \leq 3 \times 10^5 $ - $ 1 \leq u \leq d \leq H $ - $ 1 \leq l \leq r \leq W $ - All input values are integers.