

Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 300 点
問題文
長さ 2N の文字列 S があります。
この文字列に対して Q 個のクエリが与えられます。i 番目のクエリでは 3 つの整数 T_i, A_i, B_i が与えられるので、以下の処理をします。
- T_i = 1 のとき : S の A_i 文字目と B_i 文字目を入れ替える
- T_i = 2 のとき : S の前半 N 文字と後半 N 文字を入れ替える(A_i, B_i の値は用いない)
例えば S がFLIP
のときにこのクエリを処理すると、S はIPFL
となる。
これら Q 個のクエリを与えられた順に全て処理した後の S を出力してください。
制約
- 1 \le N \le 2 \times 10^5
- S は長さ 2N の英大文字のみからなる文字列
- 1 \le Q \le 3 \times 10^5
- T_i は 1 または 2
- T_i = 1 のとき、1 \le A_i \lt B_i \le 2N
- T_i = 2 のとき、A_i = B_i = 0
入力
入力は以下の形式で標準入力から与えられる。
N S Q T_1 A_1 B_1 T_2 A_2 B_2 T_3 A_3 B_3 \hspace{21pt} \vdots T_Q A_Q B_Q
出力
クエリ処理後の S を出力せよ。
入力例 1
2 FLIP 2 2 0 0 1 1 4
出力例 1
LPFI
1 番目のクエリでは S の前半 N 文字と後半 N 文字を入れ替えるため、S は IPFL
となります。
2 番目のクエリでは S の 1 文字目と 4 文字目を入れ替えるため、S は LPFI
となります。
入力例 2
2 FLIP 6 1 1 3 2 0 0 1 1 2 1 2 3 2 0 0 1 1 4
出力例 2
ILPF
Score : 300 points
Problem Statement
We have a string S of length 2N.
You are given Q queries on this string.
In the i-th query, given three integers T_i, A_i, and B_i, do the following:
- if T_i = 1: swap the A_i-th and B_i-th characters of S;
- if T_i = 2: swap the first N characters and last N characters of S (the values A_i and B_i are not used).
For example, if S isFLIP
, this query makes itIPFL
.
Print the string S after processing all Q queries in the order they are given.
Constraints
- 1 \le N \le 2 \times 10^5
- S is a string of length 2N consisting of uppercase English letters.
- 1 \le Q \le 3 \times 10^5
- T_i is 1 or 2.
- If T_i = 1, 1 \le A_i \lt B_i \le 2N.
- If T_i = 2, A_i = B_i = 0.
Input
Input is given from Standard Input in the following format:
N S Q T_1 A_1 B_1 T_2 A_2 B_2 T_3 A_3 B_3 \hspace{21pt} \vdots T_Q A_Q B_Q
Output
Print the string S after processing the queries.
Sample Input 1
2 FLIP 2 2 0 0 1 1 4
Sample Output 1
LPFI
The 1-st query swaps the first N characters and last N characters of S, making it IPFL
.
The 2-nd query swaps the 1-st and 4-th characters of S, making it LPFI
.
Sample Input 2
2 FLIP 6 1 1 3 2 0 0 1 1 2 1 2 3 2 0 0 1 1 4
Sample Output 2
ILPF