#P8932. [JRKSJ R7] Clock Paradox

[JRKSJ R7] Clock Paradox

Background

The problem setter one minute later stopped the problem setter at this moment from writing an interesting background story.

(The background image comes from Phigros artwork. If there is any infringement, please inform the problem setter.)

Problem Description

You are given a string SS, where S=s1s2snS=\overline{s_1s_2\dots s_n}.

There is a string TT, initially T=ST=S. You may perform several operations. In each operation, you can choose a substring of SS and insert it into any position of TT.

You want, after some operations, to make T=s1s1s2s2snsnT=\overline{s_1s_1s_2s_2\dots s_ns_n}. Define f(S)f(S) as the minimum number of operations needed to satisfy this condition.

In addition, the string SS will undergo some changes. Specifically, there are qq modification operations. Each modification gives pp and c\texttt{c}, meaning set spcs_p\gets \texttt{c}. Here c\texttt{c} means any lowercase letter, not the character whose ASCII code is 9999.

You need to output the value of f(S)f(S) at the beginning and after each modification.

Input Format

The first line contains an integer qq, the number of modifications.
The second line contains a string SS consisting only of lowercase letters.
The next qq lines each contain an integer pp and a lowercase letter c\texttt{c}, representing one modification.

Output Format

There are q+1q+1 lines. Each line contains an integer, the answer.

2
aabc
2 b
4 b
2
2
1

Hint

Idea: cyffff, Solution: cyffff, Code: cyffff, Data: cyffff

Clock Paradox - WyvernP (Insane12.6)

The input/output files of this problem are large. Please use appropriate I/O methods.

Hint

A string AA is a substring of string SS if and only if there exist 1lrS1\le l\le r\le |S| such that A=slsl+1srA=\overline{s_ls_{l+1}\dots s_{r}}.

Sample Explanation

Before all modifications, f(S)f(S) is computed as follows:

Initially, S=T=aabcS=T=\texttt{aabc}.

In the first operation, choose the substring aa\texttt{aa} of SS and insert it at the very beginning of TT. After the operation, T=aaaabcT=\texttt{aaaabc}.

In the second operation, choose the substring bc\texttt{bc} of SS and insert it after the 55-th character of TT. After the operation, T=aaaabbccT=\texttt{aaaabbcc}, which meets the requirement.

After the first and second modifications, SS becomes abbc\texttt{abbc} and abbb\texttt{abbb} respectively. After these two modifications, f(S)f(S) is 22 and 11 respectively.

Constraints

This problem uses bundled testdata.

Subtask\text{Subtask} S\vert S\vert\le qq\le Score\text{Score}
11 55 00 1010
22 10410^4 2020
33 5×1055\times10^5 00
44 5×1055\times 10^5
55 3×1063\times10^6 3×1063\times 10^6 3030

For 100%100\% of the testdata, 1S3×1061\le|S|\le3\times10^6, 0q3×1060\le q\le 3\times10^6. It is guaranteed that SS consists only of lowercase letters, and c\texttt{c} is a single lowercase letter.

Translated by ChatGPT 5