#BS0000168. Xóa một khoảng giá trị (Range Deleting)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Xóa một khoảng giá trị (Range Deleting)
Range Deleting
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
You are given an array of integers between and . Choose two integers with . Delete every array element whose value belongs to ; the remaining elements keep their original relative order.
For example, deleting the values in from leaves .
Count the pairs for which the remaining array is non-decreasing. Empty arrays and one-element arrays are non-decreasing. Different pairs are counted separately, even if they produce identical remaining arrays.
Input
- The first line contains integers , the array length and the maximum permitted value.
- The second line contains exactly integers in their original order.
Output
Print the number of valid pairs . The answer may exceed a signed 32-bit integer.
Subtasks
- Subtask 1 (20 points): ; ; for every .
- Subtask 2 (30 points): ; ; for every .
- Subtask 3 (50 points): ; ; for every .
Examples
Input
3 3
2 3 1
Output
4
Explanation
The original array is . There are six possible deletion intervals:
- leaves : valid.
- leaves : valid.
- leaves an empty array: valid.
- leaves : invalid because .
- leaves : valid.
- leaves : invalid because .
Exactly four intervals are valid, so the output is 4.