#P3602. Koishi Loves Segments

    ID: 2652 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>贪心离散化洛谷原创O2优化洛谷月赛

Koishi Loves Segments

Description

Koishi likes segments.

Each of her nn segments can be represented as a closed interval [l,r][l, r] on the number line. Koishi likes to put all the segments on the number line and then count how many segments cover certain points.

Seeing how happily she plays with segments, Flandre throws her a problem:

There are mm points on the number line that suddenly get excited. If a point is covered by more than xx segments, it will feel terrible and criticize Koishi.

Koishi is very kind. To avoid making the points feel bad and to make herself happy, she wants to place as many segments on the number line as possible.

As usual, Koishi pretends she cannot solve this problem, so she asks you for help, and promises to give you a phone call if you solve it.

Input Format

The first line contains two integers n,mn, m, denoting the number of segments to insert and the number of excited points.

Each of the next nn lines contains two integers l,rl, r (lrl \le r), denoting the endpoints of a segment [l,r][l, r].

Each of the next mm lines contains two integers p,xp, x, meaning that the point at position pp gets excited and requires that it should not be covered by more than xx segments.

Output Format

Output a single integer, denoting the maximum number of segments that can be placed.

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

Hint

  • For 20% of the testdata, 1n,m201 \le n, m \le 20.
  • For 60% of the testdata, 1n,m1001 \le n, m \le 100.
  • For 80% of the testdata, 1n,m50001 \le n, m \le 5000.
  • Constraints: 1xn2×1051 \le x \le n \le 2\times 10^5, 1m4×1051 \le m \le 4\times 10^5, l,r,p107|l|, |r|, |p| \le 10^7.
  • If a point gets excited multiple times, Koishi should satisfy its stricter requirement (i.e., when pp is the same, take the minimum xx).
  • Please use fast I/O appropriately.

Translated by ChatGPT 5