#abc340b. B - Append

B - Append

Score: 200200 points

问题描述

你有一个空的序列 AA。有 QQ 个查询操作需要按照给定顺序进行处理。

查询操作有两种类型:

  • 1 x: 将数值 xx 添加到序列 AA 的末尾。
  • 2 k: 从序列 AA 的末尾开始找到第 kk 个值。当此查询给出时,保证序列 AA 的长度至少为 kk

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

Problem Statement

You have an empty sequence AA. There are QQ queries given, and you need to process them in the order they are given.
The queries are of the following two types:

  • 1 x: Append xx to the end of AA.
  • 2 k: Find the kk-th value from the end of AA. It is guaranteed that the length of AA is at least kk when this query is given.

Constraints

  • 1Q1001 \leq Q \leq 100
  • In the first type of query, xx is an integer satisfying 1x1091 \leq x \leq 10^9.
  • In the second type of query, kk is a positive integer not greater than the current length of sequence AA.

Input

The input is given from Standard Input in the following format:

QQ

query1\mathrm{query}_1

query2\mathrm{query}_2

\vdots

queryQ\mathrm{query}_Q

Each query is in one of the following two formats:

11 xx

22 kk

Output

Print qq lines, where qq is the number of queries of the second type.
The ii-th line should contain the answer to the ii-th such query.

Sample Input 1

5
1 20
1 30
2 1
1 40
2 3

Sample Output 1

30
20
  • Initially, AA is empty.
  • The first query appends 2020 to the end of AA, making A=(20)A=(20).
  • The second query appends 3030 to the end of AA, making A=(20,30)A=(20,30).
  • The answer to the third query is 3030, which is the 11-st value from the end of A=(20,30)A=(20,30).
  • The fourth query appends 4040 to the end of AA, making A=(20,30,40)A=(20,30,40).
  • The answer to the fifth query is 2020, which is the 33-rd value from the end of A=(20,30,40)A=(20,30,40).

update @ 2024/3/10 01:32:30