#SRD0000075. Jeff và việc xóa các chu kỳ (Jeff and Removing Periods)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Jeff và việc xóa các chu kỳ (Jeff and Removing Periods)
Jeff and Removing Periods
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
One operation chooses equal-valued elements whose positions form an arithmetic progression in the current sequence, deletes them, then arbitrarily permutes the remaining elements. For every independent interval of the original array, output the minimum operations needed to delete all its elements.
Input
Read , the sequence, , then inclusive ranges.
Output
Print the minimum number of operations per query.
Subtasks
- Subtask 1 (10 points): , . ; .
- Subtask 2 (20 points): , . ; .
- Subtask 3 (25 points): , . ; .
- Subtask 4 (45 points): , . ; .
Examples
Input
5
2 2 1 1 2
5
1 5
1 1
2 2
1 3
2 3
Output
2
1
1
2
2
Explanation
In , the positions of value 1 are 3 and 4, an arithmetic progression; remove them first and then remove all copies of 2, using two operations. Single-element intervals take one operation. Range has two distinct values, so two operations are needed.