QOJ.ac

QOJ

Limite de temps : 1 s Limite de mémoire : 512 MB Points totaux : 100

#6183. Stadium Surveillance Problem

Statistiques

The competition venue is divided into a grid of $r$ rows and $c$ columns, where each workstation is located within a grid cell. Surveillance cameras are located at the $(r + 1) \times (c + 1)$ intersections of the grid lines. Horizontal grid lines are numbered $0$ to $r$ from top to bottom, and vertical grid lines are numbered $0$ to $c$ from left to right. The position of each camera can be represented by its grid line coordinates as a tuple $(x, y)$. Each camera can face one of four directions: "top-right", "top-left", "bottom-left", or "bottom-right", numbered $1$ to $4$ respectively, corresponding to the quadrants. The monitoring range for each direction is shown in the figure below.

$$\begin{matrix}2&1\\3&4\end{matrix}$$

Due to constraints on wiring and signals, the orientation of each camera must be chosen from a specific set $S$, where $S \subseteq \{ 1, 2, 3, 4 \}$.

Venue Surveillance Problem: Given the grid dimensions, the positions of the cameras $(x_i, y_i)$, and the set of allowed orientations $S$, calculate the maximum number of workstations that can be monitored in this environment.

Input

The input file provides multiple test cases.

The first line contains a positive integer $k$, representing the size of the set $S$.

The second line contains the elements of the set $S$ in ascending order.

The third line contains a positive integer $t$, representing the number of test cases.

For each test case:

The first line contains three positive integers $n, r, c$, representing $n$ cameras in the venue and a grid of $r$ rows and $c$ columns.

The next $n$ lines each contain two positive integers $x_i, y_i$, representing the position of the $i$-th camera at $(x_i, y_i)$.

Output

For each test case, output the maximum number of workstations that can be monitored in the corresponding environment. Output each result on a new line.

Examples

Input 1

4
1 2 3 4
1
3 6 8
4 2
1 4
5 6

Output 1

44

Subtasks

For $100\%$ of the test data, $n \leq 10^5$, $0 \leq x_i \leq r \leq 10^9$, and $0 \leq y_i \leq c \leq 10^9$.

For $100\%$ of the test data, $\sum n \leq 10^5$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.