#P12009. 【MX-X10-T5】[LSOT-4] Masuko or Haru?

【MX-X10-T5】[LSOT-4] Masuko or Haru?

Description

You are given nn binary strings of length mm.

An interval pair is defined as a pair (l,r)(l, r) where 1lrm1 \le l \le r \le m.

An interval set is a collection of interval pairs.

For a binary string aa, a transformation with respect to an interval set SS involves selecting any interval pair (l,r)S(l, r) \in S i[l,r]\forall i \in [l, r], aiai1a_i \gets a_i \oplus 1 , where \oplus denotes bitwise XOR.

Two binary strings aa and bb are equivalent under an interval set SS if aa can be transformed into bb after any number of transformations with respect to SS.

Initially, S=S = \emptyset.

There are qq operations, each being either an insertion or a query:

  • Insertion: Add a given interval pair (l,r)(l, r) to SS.
  • Query: Given xx and yy, determine whether the xx-th and yy-th binary strings are equivalent under the current SS.

Input Format

  • The first line contains three integers nn, mm, qq.
  • The second line contains a binary string of length n×mn \times m. The ((i1)×m+1)((i-1) \times m + 1)-th to (i×m)(i \times m)-th characters represent the ii-th binary string.
  • The next qq lines each start with an integer opop:
    • If op=1op = 1, it is an insertion operation followed by two integers l,rl, r.
    • If op=2op = 2, it is a query operation followed by two integers x,yx, y.

Output Format

For each query, output a single line: Masuko if the two strings are equivalent, otherwise Haru.

2 5 5
1001111001
2 1 2
1 2 3
2 1 2
1 3 4
2 1 2
Haru
Haru
Masuko
10 10 20
1110001000101011110100110000110111001111111110111101001111011111011101000000000111110100010000100110
2 2 1
2 9 6
2 6 10
2 1 1
2 3 2
1 7 9
2 10 10
2 10 4
1 1 7
1 8 8
1 2 3
1 2 7
2 1 9
2 6 1
1 1 3
2 10 7
1 2 4
2 9 1
1 3 7
1 1 5
Haru
Haru
Haru
Masuko
Haru
Masuko
Haru
Haru
Haru
Haru
Haru

Hint

Sample Explanation #1

Initial binary strings are:

10011,
11001.

  • First query: SS is empty. The strings are obviously different.
  • Second query: S={(2,3)}S = \{(2, 3)\}. The first string can only become 10011 or 11111, which cannot match the second string.
  • Third query: S={(2,3),(3,4)}S = \{(2, 3), (3, 4)\}. Applying transformations in sequence converts the first string to the second string. Hence equivalent.

Data Range

This problem uses subtasks with bundled testing.

  • Subtask 1 (17 pts): n,m10n, m \le 10, q20q \le 20.
  • Subtask 2 (14 pts): l=rl = r.
  • Subtask 3 (16 pts): l=r1l = r - 1.
  • Subtask 4 (13 pts): Insertions do not exceed 5000.
  • Subtask 5 (21 pts): All insertions occur before queries.
  • Subtask 6 (19 pts): No additional constraints.

For all data: 1q,n,m5×1061 \le q, n, m \le 5 \times 10^6, n×m107n \times m \le 10^7, 1lrm1 \le l \le r \le m, 1x,yn1 \le x, y \le n, op{1,2}op \in \{1, 2\}.

Translation by DeepSeek R1