#LCA0000013. Tìm hoán vị vòng trong đoạn (Lynyrd Skynyrd)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Tìm hoán vị vòng trong đoạn (Lynyrd Skynyrd)
Lynyrd Skynyrd
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
You are given a permutation of and an array of values between and .
Select positions of in strictly increasing order; they need not be consecutive. A subsequence of length is valid if its values equal a cyclic rotation of permutation . For example, for , is also valid.
For each query interval , determine whether a valid subsequence of length exactly can be formed using only positions in that interval.
Input
- The first line contains .
- The second line contains permutation .
- The third line contains array values .
- The next lines contain query intervals .
Output
Print one binary string of length : character is 1 if query admits a valid subsequence, otherwise 0. Do not insert spaces.
Subtasks
- Subtask 1 (20 points): ; ; ; ; ; ; là hoán vị.
- Subtask 2 (30 points): ; ; ; ; ; ; là hoán vị.
- Subtask 3 (50 points): ; ; ; là hoán vị.
Examples
Input
3 6 3
2 1 3
1 2 3 1 2 3
1 5
2 6
3 5
Output
110
Explanation
Interval contains , and contains , both valid rotations. Interval contains only , which is not a rotation of .