String Operations
Practice
3.7 (25 votes)
Basic programming
Basics of implementation
Easy
Implementation
String manipulation
Problem
55% Success 7082 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

You are given a string S.

Q number of operations are performed on string S.
In each of these Q operations, you are given an index ind and a character ch. For each operation, you have to update character at index ind in string S to ch, that is, after this operation S[ind]=ch.
It is guaranteed that any index is updated atmost once.
We call the final string after performing Q number of operations as str.

After this, M number of operations are performed on string str.
In each of these M operations, you are given two indices a and b. For each operation, you have to reverse the substring that lies between the indices a and b (inclusive).
We call the final string after performing M operations as fin.

Example: If string is "xyz" and
one of the Q operations is 1a, then string "xyz" now becomes "ayz" as S[1]=a after the operation.
one of the M operations is 13, then "ayz" now becomes "zya" as the substring lying between indices 1 and 3 is reversed.

You have to print string str, string fin and the number of indices which have same characters at them in both strings str and fin.

Input Format:
First line consists of string S.
Next line consists of an integer denoting Q.
Following Q lines contain two integers each: ind and ch.
Next line consists of an integer denoting M.
Following M lines contain two integers each: a and b.

Output Format:
In first line, print string str.
In second line, print string fin.
In third line, print the number of indices which have same characters at them in both strings str and fin.

Input Constraints:
1|S|102; S denotes length of string s.
1Q|S|
1M103
1ind|s|, all ind values are unique.
1ab|s|
ch will always be a lowercase English alphabet.
String S consists of lowercase English alphabets only.
All indices are 1 based.

Please login to use the editor

You need to be logged in to access the code editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
95 votes
Tags:
Basic ProgrammingInclusion-exclusionMath
Points:20
159 votes
Tags:
Ad-HocApprovedEasyOpen
Points:20
59 votes
Tags:
AlgorithmsBasic ProgrammingBasics of ImplementationEasyImplementationMathNumber TheorySieve
Editorial

Login to unlock the editorial