#P5821. 【L&K R-03】密码串匹配

【L&K R-03】密码串匹配

Description

After getting destroyed by the judge, Little L reflected and decided to use a safer password. Little L designed a password that may be as long as 200,000200{,}000 characters and consists only of lowercase letters, and he guarantees that nobody can remember it, guess it, or brute-force it (including Little L himself).

To avoid forgetting the whole password string (no need to avoid it; he has already forgotten it), Little L wrote a program that can store his password string TT, but cannot output it directly (because others might use this program). The first time, Little L reconstructs a string PP of length ll from memory. Later, he will modify one character of PP based on the program’s output. This program can compute the mismatch degree between the current guess string PP and the substring of TT with the same length.

Define the value of character a as 11, character b as 22, and so on, up to character z as 2626. Define the mismatch degree of two strings s,ts,t as the sum of the squares of the differences of their values at corresponding positions.

Now, Little L wants to know whether his program is correct. Please write a similar program as well.

Input Format

The first line contains three integers n,l,mn,l,m, representing the length nn of the password string TT, the length ll of the guess string PP, and the number of operations mm.

The next two lines contain two strings, which are TT and PP.

The next mm lines each start with an integer opop, indicating the type of operation:

  • If op=1op=1, then an integer xx follows, meaning you need to query the mismatch degree between PP and the substring of TT of length ll starting from position xx.
  • If op=2op=2, then an integer xx and a character cc follow, meaning you modify the xx-th character of PP to make it equal to cc.

Output Format

For each operation of type 11, output one line containing the required value.

8 5 3
iamangry
anger
1 4
2 2 m
1 2
218
238

Hint

Please note the special time limit of this problem.

The data size is large, so please optimize constants carefully.

To prevent the problem from being too strict on runtime, this problem provides Bajuyang. You can paste it directly at the very beginning of your code and submit.

In this problem, all indices start from 11.

  • Subtask #1: 3030 points, guaranteed n,m5×103n,m\le 5\times 10^3.
  • Subtask #2: 3030 points, guaranteed there is no operation type 22.
  • Subtask #3: 4040 points, guaranteed n,m2×105n,m\le 2\times 10^5.

For 100%100\% of the testdata, it is guaranteed that 1ln1\le l\le n and 1x1\le x.

For all operations of type 11, it is guaranteed that x1+lnx-1+l\le n.

For all operations of type 22, it is guaranteed that xlx\le l.

Sample Explanation

$(a-a)^2+(n-n)^2+(g-g)^2+(r-e)^2+(y-r)^2=13^2+7^2=218$.

$(a-a)^2+(m-m)^2+(a-g)^2+(n-e)^2+(g-r)^2=6^2+9^2+11^2=238$。

Translated by ChatGPT 5