Logo
(追記) (追記ここまで)

22276번 - May I Add a Letter? 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2.5 초 1024 MB3310621.429%

문제

You have a string S of length N and you are asked to perform a sequence of Q updates of two types to S:

  • Append a given character to the end of S.
  • Delete the last character from S.

Initially and after each update, you must calculate the number of distinct strings that occur at least twice as substrings of S.

For example, if S is initially “ABABC”, the answer is 3, as “A”, “B” and “AB” occur twice as substrings of S. If you are asked to append the character “C”, S will become “ABABCC” and the answer will be 4, as now “C” occurs twice too. If you are asked to append “C” again, S will be “ABABCCC” and the answer will be 5, as “CC” occurs twice now. If you are given a delete operation now, S will become “ABABCC” and the answer will be 4 again.

입력

The first line contains a string S of length N (1 ≤ N ≤ 105), indicating the initial value of the string. Each character of S is an uppercase letter. The second line contains a string U of length Q (1 ≤ Q ≤ 105), representing the updates to perform. Each character of U is either an uppercase letter indicating that such a letter must be appended, or the character “-” (hyphen) denoting a delete operation. The updates must be applied in the order they appear in U. It is guaranteed that delete operations are not applied to empty strings.

출력

Output Q + 1 lines, each line with an integer indicating the number of distinct strings that occur at least twice as substrings of S. Line 1 refers to the initial value of S, while line i + 1 refers to the value of S after applying the first i updates (i = 1, 2, . . . , Q).

제한

예제 입력 1

ABABC
CC-

예제 출력 1

3
4
5
4

예제 입력 2

ABAB
A--CC

예제 출력 2

3
5
3
1
1
2

예제 입력 3

HAVE
FUN

예제 출력 3

0
0
0
0

힌트

출처

ICPC > Regionals > Latin America > Latin America Regional Contests > Latin America Regional Contests 2020 M번

  • 문제를 만든 사람: Arthur Nascimento
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /