QOJ.ac

QOJ

Limite de temps : 2 s Limite de mémoire : 64 MB Points totaux : 100

#12614. Fortune Telling

Statistiques

Director K loves fortune-telling and often performs various kinds. Today, he decided to use cards to predict the performance of this year's Japanese IOI team.

The method of fortune-telling is as follows:

  • First, arrange all cards in a rectangular grid with $M$ rows and $N$ columns, all facing face-up.
  • For each $i = 1, \dots, K$, perform the operation: "Flip all cards located from the $A_i$-th to the $B_i$-th row from the top, and from the $C_i$-th to the $D_i$-th column from the left." That is, if we denote the card at the $a$-th row from the top and $b$-th column from the left as $(a, b)$, for each $i$, flip all cards $(a, b)$ that satisfy $A_i \le a \le B_i$ and $C_i \le b \le D_i$.
  • After the operations are finished, the result of the fortune-telling is determined by the number of cards that are face-up.

Director K realized that the number of times he would have to flip the cards is too large, so he decided not to use the cards to perform the fortune-telling, but instead to calculate only the number of cards that are face-up after the operations are finished.

Task

Given the number of rows $M$, the number of columns $N$, the number of operations $K$, and the instructions for the $K$ operations, write a program to calculate the number of cards that are face-up after the operations.

Constraints

  • $1 \le M \le 1\,000\,000\,000 (= 10^9)$
  • $1 \le N \le 1\,000\,000\,000 (= 10^9)$
  • $1 \le K \le 100\,000 (= 10^5)$

Input

Read the following from standard input:

  • The first line contains three space-separated integers $M, N, K$, representing that the cards are arranged in $M$ rows and $N$ columns, and that there are $K$ operations to be performed.
  • The $(1 + i)$-th line ($1 \le i \le K$) contains four integers $A_i, B_i, C_i, D_i$ ($1 \le A_i \le B_i \le M, 1 \le C_i \le D_i \le N$), representing that the $i$-th operation flips all cards from the $A_i$-th to the $B_i$-th row and from the $C_i$-th to the $D_i$-th column.

Output

Output the number of cards that are face-up after $K$ operations in a single line to standard output.

Subtasks

For 30% of the test cases, $K \le 3\,000$.

Examples

Input 1

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

Output 1

11

Note

In this example, the $K = 3$ operations are performed as follows. Representing face-up cards as $\square$ and face-down cards as $\blacksquare$:

Initial state: $\square\square\square\square\square$ $\square\square\square\square\square$ $\square\square\square\square\square$ $\square\square\square\square\square$ $\square\square\square\square\square$ $\square\square\square\square\square$

$\downarrow$

$\square\square\square\square\square$ $\blacksquare\blacksquare\blacksquare\blacksquare\square$ $\blacksquare\blacksquare\blacksquare\blacksquare\square$ $\blacksquare\blacksquare\blacksquare\blacksquare\square$ $\square\square\square\square\square$ $\square\square\square\square\square$

$\downarrow$

$\square\square\square\square\square$ $\blacksquare\blacksquare\blacksquare\blacksquare\square$ $\blacksquare\blacksquare\blacksquare\blacksquare\square$ $\blacksquare\blacksquare\square\square\blacksquare$ $\square\square\blacksquare\blacksquare\blacksquare$ $\square\square\blacksquare\blacksquare\blacksquare$

$\downarrow$

$\square\square\blacksquare\blacksquare\blacksquare$ $\blacksquare\blacksquare\square\square\blacksquare$ $\blacksquare\blacksquare\blacksquare\blacksquare\square$ $\blacksquare\blacksquare\square\square\blacksquare$ $\square\square\blacksquare\blacksquare\blacksquare$ $\square\square\blacksquare\blacksquare\blacksquare$

Final state: The number of face-up cards in the final state is 11.

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.