PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#FT0000181. Truy vấn xâu đối xứng (Palindrome Queries)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Truy vấn xâu đối xứng (Palindrome Queries)
Palindrome Queries
Source: CSES
Version: Phuoc Hung OJ Extended
Problem Statement
Given a lowercase English string of length , with 1-based positions, process operations in order. Command 1 k x replaces the character at position by ; it does not insert a new character. Command 2 a b checks whether the contiguous substring is a palindrome, meaning its forward and reversed readings are identical. Both endpoints are included, and previous updates affect all later queries.
Input
The first line contains . The second contains the string of exactly lowercase characters. The next lines are either 1 k x or 2 a b.
Output
For every type-2 query print YES if the substring is a palindrome, and NO otherwise. Output is case-sensitive.
Subtasks
- Subtask 1 (20 points): ; ; has exactly lowercase English letters; each command is
1 x cwith , lowercasec, or2 L Rwith ; at least one type-2 query in PHOJ tests. - Subtask 2 (30 points): ; ; has exactly lowercase English letters; each command is
1 x cwith , lowercasec, or2 L Rwith ; at least one type-2 query in PHOJ tests. - Subtask 3 (50 points): ; ; has exactly lowercase English letters; each command is
1 x cwith , lowercasec, or2 L Rwith ; at least one type-2 query in PHOJ tests.
Examples
Example 1
Input
7 5
aybabtu
2 3 5
1 3 x
2 3 5
1 5 x
2 3 5
Output
YES
NO
YES
Explanation
2 3 5: substringbab; reversedbab; printYES.1 3 x: replacebbyxat position 3; the string becomesayxabtu. No output.2 3 5: substringxab; reversedbax; printNO.1 5 x: replacebbyxat position 5; the string becomesayxaxtu. No output.2 3 5: substringxax; reversedxax; printYES.
Example 2
Input
5 5
abcba
2 1 5
1 1 z
2 1 5
1 3 z
2 2 4
Output
YES
NO
YES
Explanation
2 1 5: substringabcba; reversedabcba; printYES.1 1 z: replaceabyzat position 1; the string becomeszbcba. No output.2 1 5: substringzbcba; reversedabcbz; printNO.1 3 z: replacecbyzat position 3; the string becomeszbzba. No output.2 2 4: substringbzb; reversedbzb; printYES.