#P10753. Close Letter Sequences

    ID: 12789 Type: Default 1000ms 256MiB

Close Letter Sequences

Close Letter Sequences

On an unusually warm spring afternoon in Moscow's Patrijaršijskim Ribnjačama, two citizens arrive: the editor Mihali Aleksandrovic Berlioz and a young poet known as Bezdomni (the Homeless). Each of them carries a string of N lowercase letters.

Soon, the mysterious professor Woland, a master of dark magic, joins them and exclaims, "Gentlemen, the letter strings in your hands are very interesting. I can instantly tell whether they are close!" He explains that by selecting two consecutive letters of a string and cyclically advancing each letter by one in alphabetical order (i.e. turning ab into bc, or qz into ra), if after applying this operation any number of times independently on the two strings they can be made identical, then the two letter strings are considered close.

Formally, denote a string by \(s = s_1s_2\dots s_N\), and define its difference array as \[ d_i = (s_{i+1} - s_i) \mod 26, \quad 1 \le i \le N-1. \] The strings are close if and only if their difference arrays are identical. (A letter is represented by its position in the alphabet with \(a=0, b=1, \dots, z=25\).)

Professor Woland first tells them whether their strings are close. Then, they perform Q operations. In each operation, one of them selects a consecutive pair of letters in his/her string and performs the cyclic advancement as described. After each operation, Woland again checks and announces whether the two strings are close.

Your task is to simulate the process and output the result before any operation and after each operation.

inputFormat

The first line contains two integers \(N\) and \(Q\) \((2 \le N \le 10^5,\; 1 \le Q \le 10^5)\) representing the length of the strings and the number of operations.

The second line contains a string of length \(N\) consisting of lowercase English letters, representing the first string.

The third line contains a string of length \(N\) consisting of lowercase English letters, representing the second string.

Each of the next \(Q\) lines contains two integers \(k\) and \(pos\) \((k \in {1,2},\; 1 \le pos < N)\) where \(k\) indicates which string to modify (1 for the first string, 2 for the second) and \(pos\) is the 1-indexed starting position of the consecutive pair to update. The operation changes the two letters at positions \(pos\) and \(pos+1\) by cyclically advancing them by one (i.e. replacing a letter \(c\) with \((c+1) \mod 26\); note that \(z\) becomes \(a\)).

outputFormat

Output \(Q+1\) lines. The first line should be either YES if the two strings are close initially or NO otherwise. Then, for each operation, output a line containing YES if the strings are close after the operation or NO otherwise.

sample

3 3
abc
bcd
1 1
2 2
1 2
YES

YES NO YES

</p>