QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 512 MB Total points: 100

#169. 甜甜圈装饰

Statistics

甜甜圈制作师的早晨总是很早。D先生,也被称为甜甜圈先生,是一位了不起的甜甜圈制作师。今天,他像往常一样在日出前就来到厨房准备制作甜甜圈。

转眼间,D先生用娴熟的手法炸好了 $N$ 个甜甜圈。但是,这些刚炸好的甜甜圈还不能直接摆上柜台。它们还需要经过几道装饰工序,例如填入奶油、蘸上巧克力、撒上可爱的彩色装饰物等。总共有 $K$ 道装饰工序,编号为 $1$ 到 $K$,每道工序都必须按照 $1, 2, \dots, K$ 的顺序恰好执行一次,才能将甜甜圈制成可供销售的商品。

随后,D先生将 $N$ 个甜甜圈排成一排。他似乎打算一次性按顺序完成每道装饰工序。然而,他到底在做什么呢?昨晚熬夜的D先生在每道工序中只装饰了连续区间内的一部分甜甜圈。这显然是个错误!不仅如此,他有些工序执行了零次或多次,而且工序的顺序也是混乱的。那些没有经过正确流程装饰的甜甜圈不能作为商品出售,因此他必须把它们扔掉。

幸运的是,有数据记录了他所执行的工序序列。这些数据包含以下信息:对于每道工序,记录了被装饰甜甜圈的连续区间 $[l, r]$ 以及该工序的 ID $x$。请编写一个程序,根据给定的记录数据,计算出有多少个甜甜圈可以作为商品摆上柜台。

输入格式

输入的第一行包含两个整数 $N$ 和 $K$,其中 $N$ ($1 \le N \le 2 \cdot 10^5$) 是D先生炸好的甜甜圈数量,$K$ ($1 \le K \le 2 \cdot 10^5$) 是需要对甜甜圈进行的装饰工序数量。第二行包含一个整数 $T$ ($1 \le T \le 2 \cdot 10^5$),表示D先生执行的工序信息数量。接下来的 $T$ 行,每行包含三个整数 $l_i, r_i$ 和 $x_i$,表示D先生执行的第 $i$ 道工序:第 $i$ 道工序应用于甜甜圈的区间 $[l_i, r_i]$ ($1 \le l_i \le r_i \le N$),且该工序的 ID 为 $x_i$ ($1 \le x_i \le K$)。

输出格式

输出可以作为商品出售的甜甜圈数量。

样例

输入 1

3 2
3
1 2 1
2 3 2
3 3 1

输出 1

1

输入 2

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

输出 2

2

输入 3

10 1
2
2 9 1
5 7 1

输出 3

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.