QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 128 MB 總分: 100

#10763. Xiao Lan's Friend

统计

We have finally reached the last problem of this selection contest. You must be tired of the stories about Xiao Lan and Xiao Bai. To reward all the contestants, the protagonist of this problem is the key character who has appeared throughout this contest—Xiao Lan's friend.

After helping Xiao Lan determine his travel route, Xiao Lan's friend does not want to waste this rare summer vacation. Unlike Xiao Lan, his friend does not want to spend time traveling, but has set his sights on the recently released real-time strategy game, SangoCraft. However, on the road to clearing the game, a mini-game has blocked his path.

"The essence of a nation's war is the war for resources" is the core philosophy of the entire game, and this mini-game is no exception. Simply put, the user needs to select a sub-rectangle on a given rectangular piece of land. The system randomly generates $N$ resource points. The more resource points located within the rectangular area selected by the user, the more rewards the user receives. Tragically, although Xiao Lan's friend possesses excellent abilities, he also has terrible luck; the area he selects never contains a single resource point.

Finally, one day, Xiao Lan's friend decides to file a complaint against the game's manufacturer. To gather evidence, he wants to calculate the number of areas that contain at least one resource point. As a friend of Xiao Lan, this is naturally your duty.

Input

Each input file contains only one test case.

The first line contains two space-separated positive integers $R, C, N$, indicating that the game has generated $N$ resource points on a map of size $[1, R] \times [1, C]$.

The next $N$ lines each contain two integers $x, y$, representing the coordinates of a resource point $(1 \le x \le R, 1 \le y \le C)$.

Output

The output file should contain only one integer, representing the number of areas that contain at least one resource point. Specifically, let the coordinates of the $N$ resource points be $(X_i, Y_i)$ for $i=1..n$. You need to calculate how many quadruplets $(LB, DB, RB, UB)$ satisfy $1 \le LB \le RB \le R$, $1 \le DB \le UB \le C$, and there exists an $i$ such that $LB \le X_i \le RB$ and $DB \le Y_i \le UB$ are both satisfied.

Examples

Input 1

5 5 4
1 2
2 3
3 5
4 1

Output 1

139

Constraints

For 20% of the data, $N \le 50$.

For 40% of the data, $N \le 2000$.

For 100% of the data, $R, C \le 40000, N \le 100000$. The positions of the resource points are distinct, and the positions are generated randomly.

Map size constraint

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.