P26941 [AtCoder] Reversal of the Sequence
NOI
题目描述

Problem Description

There is a sequence of length $ 2N $: $A\ =\ (1,2,\ \ldots\ ,2N)$. Process $ Q $ queries. In the $ i $ -th query, integers $t_i,\ k_i$ are given.

  • When $t_i\ =\ 1$: Output the value of the $ k_i $ -th element from the left in the sequence $ A $.
  • When $t_i\ =\ 2$: Reverse the order of the central $ 2k_i $ elements in the sequence $ A $. That is, reverse the order from the $ N-k_i+1 $ -th element to the $ N+k_i $ -th element from the left.

Input Format

The input is given from the standard input in the following format:

$ N $ $ Q $ $ t_1 $ $ k_1 $ $ t_2 $ $ k_2 $ $\vdots$ $ t_Q $ $ k_Q $

Output Format

For each $ i $ satisfying $ t_i=1 $, output the value of the $ k_i $ -th element from the left in the sequence $ A $ separated by newlines.

Sample Input and Output

Sample Input #1

3 2
2 2
1 4

Sample Output #1

3

Sample Input #2

3 3
2 3
1 3
1 1

Sample Output #2

4
6

Sample Input #3

5 6
2 2
2 1
2 1
2 3
1 2
2 3

Sample Output #3

2

Notes/Hints

Constraints

  • $1\ \leq\ N\ \leq\ 2\ \times\ 10^5$
  • $1\ \leq\ Q\ \leq\ 2\ \times\ 10^5$
  • $1\ \leq\ t_i\ \leq\ 2$
  • There exists at least one $ i $ such that $ t_i=1 $.
  • If $ t_i=1 $, then $1\ \leq\ k_i\ \leq\ 2N$
  • If $ t_i=2 $, then $1\ \leq\ k_i\ \leq\ N$
  • All inputs are integers.

Sample Explanation 1

Initially, the sequence $ A $ is $ (1,2,3,4,5,6) $. In the first query, the central 4 elements are reversed, and the sequence $ A $ becomes $ (1,5,4,3,2,6) $. In the second query, the 4th element from the left is $ 3 $, so output $ 3 $.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 2 2 2 1 4
样例输出
3