PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#SRD0000142. Hạt dẻ công bằng và phép XOR thú vị (The Fair Nut and Amusing Xor)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

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 a1,…,ana_1,\ldots,a_n and b1,…,bnb_1,\ldots,b_n, and a fixed operation length kk.

An operation chooses exactly kk consecutive positions of array aa, chooses any integer xx, and replaces each chosen aia_i with ai⊕xa_i\oplus x (bitwise XOR). The objective is to make aa identical to bb. The similarity is the minimum number of operations needed; if this is impossible, it equals -1.

First determine the initial similarity. Then process qq modifications sequentially. A modification selects array a or b, a position pp, and a new value vv to assign at that position. After each modification, determine the new similarity. Modifications are persistent.

Input

  • The first line contains n,k,qn,k,q: the array length, operation length and number of modifications.
  • The second line contains nn integers a1,…,ana_1,\ldots,a_n.
  • The third line contains nn integers b1,…,bnb_1,\ldots,b_n.
  • Each of the following qq lines contains s p v. Character s is a or b, indicating which array to update; pp is the position assigned to vv.

Output

Print q+1q+1 lines: initially the similarity, then the similarity after each successive modification. Print -1 for impossible states.

Subtasks

  • Subtask 1 (20 points): 1≤n≤401\le n\le 40; 1≤k≤n1\le k\le n; 0≤q≤1000\le q\le 100; 0≤ai,bi,v<2140\le a_i,b_i,v<2^{14}; 1≤p≤n1\le p\le n; every update uses a or b.
  • Subtask 2 (30 points): 1≤n≤30001\le n\le 3000; 1≤k≤n1\le k\le n; 0≤q≤30000\le q\le 3000; 0≤ai,bi,v<2140\le a_i,b_i,v<2^{14}; 1≤p≤n1\le p\le n; every update uses a or b.
  • Subtask 3 (50 points): 1≤n≤2000001\le n\le 200000; 1≤k≤n1\le k\le n; 0≤q≤2000000\le q\le 200000; 0≤ai,bi,v<2140\le a_i,b_i,v<2^{14}; 1≤p≤n1\le p\le n; every update uses a or b.

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 [1,6,1][1,6,1]. With k=3k=3, each operation affects all three positions with the same XOR value, so equal differences are required; print -1. After setting b2=5b_2=5, the differences become [1,1,1][1,1,1], and one operation with x=1x=1 suffices.