QOJ.ac

QOJ

حد الوقت: 2 s حد الذاكرة: 64 MB مجموع النقاط: 100

#12614. 占卜

الإحصائيات

K 理事长喜欢占卜,经常进行各种各样的占卜。今天,他决定用卡片来占卜今年 IOI 日本代表队的表现。

占卜的方法如下:

  • 首先,将卡片排成 $M$ 行 $N$ 列的矩形,所有卡片正面朝上。
  • 对于 $i = 1, \dots, K$,执行以下操作:“将从上往下数第 $A_i$ 行到第 $B_i$ 行,且从左往右数第 $C_i$ 列到第 $D_i$ 列范围内的所有卡片翻面”。也就是说,若将从上往下数第 $a$ 行、从左往右数第 $b$ 列的卡片记为 $(a, b)$,则对于每个 $i$,将满足 $A_i \le a \le B_i$ 且 $C_i \le b \le D_i$ 的所有卡片 $(a, b)$ 翻面。
  • 操作结束后,根据正面朝上的卡片数量得出占卜结果。

K 理事长发现中途翻转卡片的次数实在太多,于是决定不再实际使用卡片进行占卜,而是只计算操作结束后正面朝上的卡片数量。

题目描述

给定行数 $M$、列数 $N$、操作次数 $K$ 以及 $K$ 次操作的指令,请编写一个程序,计算操作结束后正面朝上的卡片数量。

数据范围

$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)$

输入格式

从标准输入读取以下内容:

  • 第 1 行包含三个整数 $M, N, K$,以空格分隔,表示卡片排成 $M$ 行 $N$ 列,且操作次数为 $K$ 次。
  • 第 $1 + i$ 行 ($1 \le i \le K$) 包含四个整数 $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$),表示第 $i$ 次操作是将从上往下数第 $A_i$ 行到第 $B_i$ 行,且从左往右数第 $C_i$ 列到第 $D_i$ 列范围内的所有卡片翻面。

输出格式

将 $K$ 次操作后正面朝上的卡片数量输出到标准输出,占一行。

子任务

在所有测试数据中,有 30% 的分值满足 $K \le 3\,000$。

样例

样例输入 1

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

样例输出 1

11

说明

在此例中,$K = 3$ 次操作执行过程如下。 若用 $\square$ 表示正面朝上的卡片,用 $\blacksquare$ 表示背面朝上的卡片:

初始状态 $\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$

最终状态

最终状态下正面朝上的卡片数量为 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.