PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#SRD0000073. Cắt và ghép (Cut and Stick)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Cắt và ghép (Cut and Stick)
Cut and Stick
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Partition each queried range into the minimum number of subsequences. In any subsequence of length , no value may occur more than times. Every element belongs to exactly one subsequence and order is preserved within each subsequence.
Input
Read , the array and inclusive 1-based ranges.
Output
Print the minimum number of subsequences for every query.
Subtasks
- Subtask 1 (10 points): , . ; .
- Subtask 2 (20 points): , . ; .
- Subtask 3 (25 points): , . ; .
- Subtask 4 (45 points): , . ; .
Examples
Input
6 2
1 3 2 3 3 2
1 6
2 5
Output
1
2
Explanation
The six-element range contains three occurrences of 3, meeting the limit of : one piece is enough. For , three copies of 3 exceed the limit 2; two subsequences such as and suffice.