QOJ.ac

QOJ

実行時間制限: 3 s メモリ制限: 1024 MB 満点: 100

#1986. 小雕像

統計

Bob 有许多迷你手办。他喜欢把其中一些展示在电脑屏幕上方的架子上,并且喜欢定期更换展示的手办。这种不断变化的装饰非常有趣。Bob 非常注意从不重复添加同一个迷你手办。Bob 总共有 $N$ 个迷你手办,在 $N$ 天后,他完成了所有 $N$ 个手办的添加和移除(此时架子是空的)。

Bob 的记忆力非常好。他能够记住过去每一天架子上展示了哪些迷你手办。因此,Bob 想进行一个小小的心理练习来测试他的记忆力和计算能力。为此,Bob 将他的手办编号为 $0, \dots, N-1$,并选择了一个包含 $N$ 个整数的序列 $d_0, \dots, d_{N-1}$,所有整数都在范围 $[0, N]$ 内。然后,Bob 按以下方式计算序列 $x_0, \dots, x_N$:$x_0 = 0$,且 $x_{i+1} = (x_i + y_i) \pmod N$,其中 $\pmod$ 是取模运算,$y_i$ 是在第 $d_i$ 天展示的编号大于或等于 $x_i$ 的手办数量。Bob 计算的结果是 $x_N$。

更正式地说,如果我们记 $S(i)$ 为第 $i$ 天架子上展示的手办集合(即 $\{0, \dots, N-1\}$ 的子集),我们有: $S(0)$ 是空集; $S(i)$ 是通过在 $S(i-1)$ 中插入和移除某些元素得到的。

每个元素 $0 \le j < N$ 恰好被插入和移除一次,因此最后一个集合 $S(N)$ 也是空集。Bob 执行的计算对应于以下程序:

$x_0 \leftarrow 0$ for $i \in [0, N-1]$ $x_{i+1} \leftarrow (x_i + \#\{y \in S(d_i) \text{ such that } y \ge x_i\}) \pmod N$ output $x_N$

Bob 请你验证他的计算。为此,他提供了计算过程中使用的数字($d_0, \dots, d_{N-1}$)以及他每天添加或移除哪些手办的记录。注意,在第 $i$ 天添加并在第 $j$ 天移除的迷你手办,在第 $k$ 天($i \le k < j$)时是存在的。你应该告诉他你在计算结束时得到的数字。

输入格式

输入包含 $2N + 1$ 行。 第一行包含整数 $N$。 第 $2$ 行到第 $N+1$ 行描述了手办的添加和移除。第 $i+1$ 行包含以空格分隔的 $+j$ 或 $-j$(其中 $0 \le j < N$),表示在第 $i$ 天添加或移除了手办 $j$。该行可能为空。一行中可能同时包含 $+j$ 和 $-j$,按该顺序执行。 * 第 $N+2$ 行到第 $2N+1$ 行描述了序列 $d_0, \dots, d_{N-1}$。第 $N+2+i$ 行包含整数 $d_i$,其中 $0 \le d_i \le N$。

输出格式

输出应包含一行,即单个整数 $x_N$。

数据范围

  • $1 \le N \le 100\,000$

样例

样例输入 1

3
+0 +2
-0 +1
-1 -2
1
2
2

样例输出 1

2

说明

输出为 $2$,因为: 首先,$x \leftarrow 2$,因为 $S(1) = \{0, 2\}$ 且 $\#\{y \in S(1) \text{ such that } y \ge 0\} = 2$; 然后,$x \leftarrow 0$,因为 $S(2) = \{1, 2\}$ 且 $\#\{y \in S(2) \text{ such that } y \ge 2\} = 1$; * 最后,$x \leftarrow 2$,因为 $S(2) = \{1, 2\}$ 且 $\#\{y \in S(2) \text{ such that } y \ge 0\} = 2$。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.