[ABC279E] 鬼脚图单步擦除 (Cheating Amidakuji)
Score : 500 points Problem Statement N vertical bars and M horizontal bars connecting them. Each of the horizontal bars is perpendicular to the vertical ones, and their heights are different. Horizontal bar i (1 \leq i \leq M) connects vertical bars A_i and A_i+1. Let us trace the path from the top of vertical bar 1, and let the score be the number of the vertical bar we reach at the bottom. For each i=1,2,\dots,M, answer the following question.
- Let S_i be the score assuming that horizontal bar i is erased. Find S_i. Note that horizontal bars are not actually erased, so the questions are independent of each other. Below is a more formal description of the problem. --> You are given a sequence of length M consisting of integers between 1 and N-1, inclusive: A=(A_1,A_2,\dots,A_M). Answer the following question for i=1, 2, \dots, M. There is a sequence B=(B_1,B_2,\dots,B_N). Initially, we have B_j=j for each j. Let us perform the following operation for k=1, 2, \dots, i-1, i+1, \dots, M in this order (in other words, for integers k between 1 and M except i in ascending order). Swap the values of B_{A_k} and B_{A_k+1}. After all the operations, let S_i be the value of j such that B_j=1. Find S_i. Constraints 2 \leq N \leq 2\times 10^5 1 \leq M \leq 2\times 10^5 1 \leq A_i \leq N-1\ (1\leq i \leq M) All values in the input are integers. Input The input is given from Standard Input in the following format: N M A_1 A_2 \dots A_M Output Print M lines. The i-th line (1\leq i \leq M) should contain the value S_i as an integer.