#6053. [SWERC 2020] Figurines
[SWERC 2020] Figurines
[SWERC 2020] Figurines
题目描述
:::align{center}
:::
Bob has a lot of mini figurines. He likes to display some of them on a shelf above his computer screen and he likes to regularly change which figurines appear. This ever-changing decoration is really enjoyable. Bob takes care of never adding the same mini figurine more than once. Bob has only mini figurines and after days he arrives at the point where each of the figurines have been added and then removed from the shelf (which is thus empty).
Bob has a very good memory. He is able to remember which mini figurines were displayed on each of the past days. So Bob wants to run a little mental exercise to test its memory and computation ability. For this purpose, Bob numbers his figurines with the numbers and selects a sequence of integers all in the range . Then, Bob computes a sequence in the following way: and where is the modulo operation and is the number of figurines displayed on day that have a number higher or equal to . The result of Bob's computation is .
More formally, if we note the subset of corresponding to figurines displayed on the shelf on day , we have:
- is the empty set;
- is obtained from by inserting and removing some elements.
Each element is inserted and removed exactly once and thus, the last set is also the empty set. The computation that Bob performs corresponds to the following program:
$$\begin{array}{l} x_0 \leftarrow 0 \\ \text{for } i \in [0;N-1] \\ \;\;\;\;\;\;\; x_{i+1} \leftarrow (x_i + \#\{y \in S(d_i) ~\text{ such that } ~ y \ge x_i\}) \mod N \\ \text{output } x_N \end{array}$$Bob asks you to verify his computation. For that he gives you the numbers he used during its computation (the ) as well as the log of which figurines he added or removed every day. Note that a mini figurine added on day and removed on day is present on a day when . You should tell him the number that you found at the end of the computation.
输入格式
The input is composed of $2N+1$ lines. - The first line contains the integer $N$. - Lines $2$ to $N+1$ describe the figurines added and removed. Line $i+1$ contains space-separated $+j$ or $-j$, with $0 \le jLimits
输出格式
The output should contain a single line with a single integer which is $x_N$.3
+0 +2
-0 +1
-1 -2
1
2
2
2
提示
**Sample Explanation**The output is since
- first, since and ;
- then, since and ;
- and finally, since and . 标签: P13864|2020|可持久化线段树|ICPC