#K82617. Unique Palindromic Substring Queries

    ID: 36016 Type: Default 1000ms 256MiB

Unique Palindromic Substring Queries

Unique Palindromic Substring Queries

Given a non-empty string S consisting of lowercase letters, you will be given Q queries. In each query, you are provided with an index i (1-indexed) and a character c. The query instructs you to change the character at position i in S to c. After each query, determine whether the updated string S contains at least one unique palindromic substring.

A palindromic substring is a contiguous subsequence of characters that reads the same forwards and backwards. Formally, a substring S[l...r] is a palindrome if:

[ S[l...r] = S[r...l] \quad \text{for } 1 \leq l \leq r \leq |S| ]

Note that every non-empty string always contains at least one palindromic substring (each individual character is a palindrome). Therefore, for all valid queries on a non-empty string, the answer will be YES.

inputFormat

The input is read from standard input and has the following format:

S
Q
i1 c1
i2 c2
... 
 iQ cQ

Here,

  • S is the initial string,
  • Q is the number of queries, and
  • Each query consists of an index i (1-indexed) and a character c separated by a space.

outputFormat

The output should be printed to standard output. For each query, output a single line containing either YES or NO, indicating whether the updated string contains at least one unique palindromic substring.

## sample
abacaba
5
1 b
2 a
3 c
4 d
5 e
YES

YES YES YES YES

</p>