链接:
https://ac.nowcoder.com/acm/contest/57361/L
来源:牛客网
Misaka Mikoto has a pattern string sss. Let ∣s∣|s|∣s∣ be the length of sss, sis_isi be the iii-th character of sss, and s[l∼r]s[l\sim r]s[l∼r] be the substring from the lll-th character to the rrr-th character, that is, slsl+1⋯srs_ls_{l+1}\cdots s_{r}slsl+1⋯sr.
In this problem, all characters are represented by an integer.
You need to perform mmm operations. There are two types of operations:
-
1 x c1\ x\ c1 x c: change sxs_xsx to ccc.
-
2 t2\ t2 t: given a text string ttt, find the number of times sss occurs as a substring in ttt and the longest border of sss.
The longest border of sss means the largest number r(1≤r<∣s∣)r(1\le r<|s|)r(1≤r<∣s∣) that s[1∼r]s[1\sim r]s[1∼r] is the same as s[(∣s∣−r+1)∼∣s∣]s[(|s|-r+1)\sim|s|]s[(∣s∣−r+1)∼∣s∣]. If such rrr doesn't exist, let the longest border of sss be 000.
Let's call the operation 222 "query".
Given two integers b,pb,pb,p, let xi,yix_i,y_ixi,yi be the answer to the first and the second question of the iii-th query, you only need to output (∑ xi×yi×bi)modp\left(\sum\ x_i \times y_i \times b^i\right) \bmod p(∑ xi×yi×bi)modp.
For some reason, the operations are encrypted. Let zzz be the value of xi×yix_i \times y_ixi×yi of the last query (if there aren't any queries before, let zzz be 000). For operation 111, you are given two integers x′,c′x',c'x′,c′, which means x=(x′⊕z)mod∣s∣+1x=(x'\oplus z)\bmod |s|+1x=(x′⊕z)mod∣s∣+1 and c=c′⊕zc=c'\oplus zc=c′⊕z. For operation 222, you are given an integer nnn and nnn integers t1′∼tn′t'_1\sim t'_nt1′∼tn′, which means ∣t∣=n|t|=n∣t∣=n and ti=ti′⊕zt_i=t'_i\oplus zti=ti′⊕z.