#SRD0000111. AquaMoon và những củ khoai tây (AquaMoon and Potatoes)
Bài tập thuộc lộ trình
Mục lục đề ⌄
AquaMoon và những củ khoai tây (AquaMoon and Potatoes)
AquaMoon and Potatoes
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
AquaMoon has three integer arrays , , and , each of length . All three arrays are indexed from to , and every element is an integer between and , inclusive.
To organize her potato farm, AquaMoon performs operations. Only array may change; arrays and remain fixed. There are two types of operations:
-
Type
1 k x: Assign , replacing its previous value. This is an assignment, not an increment. -
Type
2 r: Consider all triples of integer indices satisfyingand
Every such triple contributes exactly one potato. Count all qualifying triples using the current state of array .
In the expression , the value is used as an index into array ; similarly, denotes the entry of at index . For example, if , then .
Operations must be processed in their given order. After an assignment, subsequent queries use the updated value until that position is assigned again.
Input
- The first line contains two integers : the length of each array and the number of operations, respectively.
- The second line contains integers , describing the initial array .
- The third line contains integers , describing array .
- The fourth line contains integers , describing array .
- Each of the next lines specifies one operation in exactly one of these forms:
1 k x: assign ;2 r: count qualifying triples among positions through .
Output
For each operation of type 2, print one integer on its own line: the number of qualifying triples at the time of that operation. Print the answers in the same order as the type 2 operations in the input.
Subtasks
- Subtask 1 (10 points): ; ; for every ; each operation is either
1 k x() or2 r(); at least one operation is of type2. - Subtask 2 (20 points): ; ; for every ; each operation is either
1 k x() or2 r(); at least one operation is of type2. - Subtask 3 (30 points): ; ; for every ; each operation is either
1 k x() or2 r(); at least one operation is of type2. - Subtask 4 (40 points): ; ; for every ; each operation is either
1 k x() or2 r(); at least one operation is of type2.
Examples
Example 1
Input
5 4
1 2 3 4 5
2 3 4 5 1
5 1 2 3 4
2 5
1 2 3
2 4
2 5
Output
3
0
2
Explanation
Initially, , , and .
- Operation 1,
2 5: Exactly three triples satisfy the condition: , , and . For instance, for , , , and . For the other two triples, the three values are all equal to and , respectively. The answer is . - Operation 2,
1 2 3: Array becomes . Assignments produce no output. - Operation 3,
2 4: None of the triples within the first four positions of the updated array satisfy the equality, so the answer is . - Operation 4,
2 5: The valid triples are and . Both have , , and . The answer is .
Example 2
Input
4 6
1 1 1 1
1 1 1 1
1 1 1 1
2 4
1 2 2
2 4
1 2 1
2 3
2 4
Output
4
2
1
4
Explanation
Both and contain only the value , so at every position. Thus, the remaining condition is .
- Initially, all four entries of are . Every selection of three increasing indices from is valid, giving triples.
- After assigning , only positions contain . For the query on the first four positions, the middle index must be . The valid triples are and , so the answer is .
- After restoring , the query
2 3has exactly one valid triple, , so it outputs . - The final query
2 4again has all four valid triples.