#P3740. [HAOI2014] 贴海报

    ID: 1298 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>2014河南线段树各省省选离散化枚举,暴力

[HAOI2014] 贴海报

Description

The city of Bytetown is holding a mayoral election, and all voters can freely express their opinions about the candidates. For unified management, the city committee has prepared an electoral wall for voters to post posters.

The posting rules are as follows:

  1. The electoral wall is a rectangle of length NN units, with each unit being a cell.
  2. The height of every posted poster must be the same as the height of the electoral wall.
  3. Each poster is denoted by A B, meaning it covers from cell AA to cell BB.
  4. A later poster may cover earlier posters or parts of them.

Please determine how many posters are still visible on the electoral wall after all posters have been posted.

Input Format

The first line contains two positive integers NN and MM, the length of the electoral wall and the number of posters, respectively.

Each of the next MM lines contains two positive integers AiA_i and BiB_i, denoting the position covered by a poster.

All numbers are positive integers, separated by a single space.

Output Format

Output the number of posters that remain visible after all posters have been posted.

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

4

Hint

Constraints

10N1000000010 \le N \le 10000000, 1M10001 \le M \le 1000, 1AiBi100000001 \le A_i \le B_i \le 10000000.

Translated by ChatGPT 5