#P15565. [COCI 2025/2026 #5] 剪刀 / Škare

    ID: 17429 远端评测题 3000ms 512MiB 尝试: 0 已通过: 0 显示难度普及− 上传者: 标签>模拟O2优化COCI(克罗地亚)2026STL

[COCI 2025/2026 #5] 剪刀 / Škare

Background

The full score for this problem is 5050.

Problem Description

To master the skill of using scissors, Fran came up with a new training method.

He has a paper strip of length nn centimeters and a pair of scissors, and he asks Lana to give him cutting instructions.

Lana will give Fran a total of kk instructions, each of the form: “Cut the xx-th strip at a point ll centimeters from the left end.”

At the beginning, Fran has only one strip. After the first cut, it becomes two pieces with lengths ll and n−ln-l. After that, each time he cuts one piece, the two newly created pieces replace the original piece and stay in the same position in the sequence.

More formally: suppose there are currently mm strips with lengths a1,a2,…,ama_1,a_2,\dots,a_m in order. If Lana tells him to cut the xx-th strip at ll centimeters, then the new sequence becomes: $a_1,a_2,\dots,a_{x-1},\,l,\,a_x-l,\,a_{x+1},\dots,a_m$.

After all cuts are done, they want to verify whether the process was correct. One way is to count how many different strip lengths appear in the final sequence. Please compute this number.

Input Format

The first line contains two natural numbers n,kn,k (2≤n≤5002 \le n \le 500,1≤k<n1 \le k < n), representing the original strip length and the number of instructions.

The next kk lines each contain two natural numbers xi,lix_i,l_i (1≤xi≤i1 \le x_i \le i, and 1≤li≤L−11 \le l_i \le L-1, where LL is the length of the xix_i-th strip at that time), meaning to cut the xix_i-th strip from left to right at lil_i centimeters from its left end.

Output Format

Output one line with an integer, representing how many different lengths of strips remain after all cuts are completed.

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

Hint

Sample Explanation

Explanation for Sample #1: [5]→[2,3][5] \to [2,3].

Explanation for Sample #2: [6]→[4,2]→[2,2,2][6] \to [4,2] \to [2,2,2].

Explanation for Sample #3: [10]→[2,8]→[2,3,5]→[2,3,2,3][10] \to [2,8] \to [2,3,5] \to [2,3,2,3].

Subtasks

Subtask Score Constraint
11 99 k≤3k \le 3
22 66 For all ii, li=1l_i = 1
33 1313 For all ii, xi=ix_i = i
44 2222 No additional constraints

Translated by ChatGPT 5