#abc258c. C - Rotation

C - Rotation

Score : 300300 points

问题描述

你将获得两个正整数 NNQQ,以及一个长度为 NN 的由小写英文字母组成的字符串 SS

处理 QQ 个查询。每个查询属于以下两种类型之一。

  • 1 x: 依次执行 xx 次以下操作:删除 SS 的最后一个字符,并将其添加到开头。
  • 2 x: 输出 SS 的第 xx 个字符。

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

Problem Statement

You are given positive integers NN and QQ, and a string SS of length NN consisting of lowercase English letters.

Process QQ queries. Each query is of one of the following two types.

  • 1 x: Perform the following xx times in a row: delete the last character of SS and append it to the beginning.
  • 2 x: Print the xx-th character of SS.

Constraints

  • 2N5×1052 \le N \le 5 \times 10^5
  • 1Q5×1051 \le Q \le 5 \times 10^5
  • 1xN1 \le x \le N
  • S=N|S|=N
  • SS consists of lowercase English letters.
  • At least one query in the format 2 x.
  • NN, QQ, xx are all integers.

Input

Input is given from Standard Input in the following format:

NN QQ

SS

query1\mathrm{query}_1

query2\mathrm{query}_2

\vdots

queryQ\mathrm{query}_Q

Each query is in the following format, where tt is 11 or 22:

tt xx

Output

For each query in the format 2 x, print the answer in a single line.

Sample Input 1

3 3
abc
2 2
1 1
2 2

Sample Output 1

b
a

In the 11-st query, SS is abc, so the 22-nd character b should be printed. In the 22-nd query, SS is changed from abc to cab. In the 33-rd query, SS is cab, so the 22-nd character a should be printed.

Sample Input 2

10 8
dsuccxulnl
2 4
2 7
1 2
2 7
1 1
1 2
1 3
2 5

Sample Output 2

c
u
c
u

update @ 2024/3/10 10:57:21