#SRD0000142. Hạt dẻ công bằng và phép XOR thú vị (The Fair Nut and Amusing Xor)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Hạt dẻ công bằng và phép XOR thú vị (The Fair Nut and Amusing Xor)
The Fair Nut and Amusing Xor
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
You are given two arrays and , and a fixed operation length .
An operation chooses exactly consecutive positions of array , chooses any integer , and replaces each chosen with (bitwise XOR). The objective is to make identical to . The similarity is the minimum number of operations needed; if this is impossible, it equals -1.
First determine the initial similarity. Then process modifications sequentially. A modification selects array a or b, a position , and a new value to assign at that position. After each modification, determine the new similarity. Modifications are persistent.
Input
- The first line contains : the array length, operation length and number of modifications.
- The second line contains integers .
- The third line contains integers .
- Each of the following lines contains
s p v. Charactersisaorb, indicating which array to update; is the position assigned to .
Output
Print lines: initially the similarity, then the similarity after each successive modification. Print -1 for impossible states.
Subtasks
- Subtask 1 (20 points): ; ; ; ; ; every update uses
aorb. - Subtask 2 (30 points): ; ; ; ; ; every update uses
aorb. - Subtask 3 (50 points): ; ; ; ; ; every update uses
aorb.
Examples
Example 1
Input
3 3 1
0 4 2
1 2 3
b 2 5
Output
-1
1
Explanation
Initially the position-wise XOR differences are . With , each operation affects all three positions with the same XOR value, so equal differences are required; print -1. After setting , the differences become , and one operation with suffices.