#SRD0000048. Serega và các truy vấn thú vị (Serega and Fun)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Serega và các truy vấn thú vị (Serega and Fun)
Serega and Fun
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Given an array with , process the following operations in their original order:
1 l' r': cyclically rotate the inclusive interval one position to the right.2 l' r' k': count the elements equal to in the inclusive interval .
Every supplied parameter is encoded. Let be the most recent answer to a type-2 operation, initially . Decode each supplied parameter as
Decode only the parameters present in the operation; swap if after decoding. Update after every count operation. Queries must be handled online and in order.
Input
The first line contains , the second line contains the array values, and the third line contains . The next lines contain encoded 1 l' r' or 2 l' r' k' operations. All encoded parameters belong to .
Output
For every type-2 operation, print its count on a separate line.
Subtasks
- Subtask 1 (10 points): ; . Every query parameter is encoded using the latest answer.
- Subtask 2 (20 points): ; . Every query parameter is encoded using the latest answer.
- Subtask 3 (25 points): ; . Every query parameter is encoded using the latest answer.
- Subtask 4 (45 points): ; . Every query parameter is encoded using the latest answer.
Examples
Input
7
6 6 2 7 4 2 5
7
1 3 6
2 2 4 2
2 2 4 7
2 2 2 5
1 2 6
1 1 4
2 1 7 3
Output
2
1
0
0
Explanation
Initially . The second operation counts the value in the rotated array and returns , so the following operation must decode its parameters using . The four count queries return 2, 1, 0, and 0 respectively; a rotation never changes lastans.