#abc199c. C - IPFL

C - IPFL

Score : 300300 points

问题描述

我们有一个长度为 2N2N 的字符串 SS

您将得到针对此字符串的 QQ 个查询操作。在第 ii 个查询中,给定三个整数 TiT_i, AiA_iBiB_i,执行以下操作:

  • 如果 Ti=1T_i = 1:交换 SS 中第 AiA_i 个和第 BiB_i 个字符;
  • 如果 Ti=2T_i = 2:交换字符串 SS 的前 NN 个字符和后 NN 个字符(此时 AiA_iBiB_i 的值不使用)。 例如,如果 SSFLIP,这个查询会让它变为 IPFL

按照给出的顺序处理完所有 QQ 个查询后,打印字符串 SS

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

We have a string SS of length 2N2N.
You are given QQ queries on this string.
In the ii-th query, given three integers TiT_i, AiA_i, and BiB_i, do the following:

  • if Ti=1T_i = 1: swap the AiA_i-th and BiB_i-th characters of SS;
  • if Ti=2T_i = 2: swap the first NN characters and last NN characters of SS (the values AiA_i and BiB_i are not used).
    For example, if SS is FLIP, this query makes it IPFL.

Print the string SS after processing all QQ queries in the order they are given.

Constraints

  • 1N2×1051 \le N \le 2 \times 10^5
  • SS is a string of length 2N2N consisting of uppercase English letters.
  • 1Q3×1051 \le Q \le 3 \times 10^5
  • TiT_i is 11 or 22.
  • If Ti=1T_i = 1, 1Ai<Bi2N1 \le A_i \lt B_i \le 2N.
  • If Ti=2T_i = 2, Ai=Bi=0A_i = B_i = 0.

Input

Input is given from Standard Input in the following format:

NN

SS

QQ

T1T_1 A1A_1 B1B_1

T2T_2 A2A_2 B2B_2

T3T_3 A3A_3 B3B_3

\hspace{21pt} \vdots

TQT_Q AQA_Q BQB_Q

Output

Print the string SS after processing the queries.

Sample Input 1

2
FLIP
2
2 0 0
1 1 4

Sample Output 1

LPFI

The 11-st query swaps the first NN characters and last NN characters of SS, making it IPFL.
The 22-nd query swaps the 11-st and 44-th characters of SS, 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
}