QOJ.ac

QOJ

時間限制: 3.0 s 記憶體限制: 256 MB 總分: 100 可 Hack ✓

#7203. 四

统计

Peter 有一个序列 $S$,其中每个元素都是一个四元组 $(a, b, c, d)$。初始时,序列 $S$ 为空。随后 Peter 对该序列进行若干次操作:

  • $+ \ k \ a \ b \ c \ d$:Peter 将四元组 $(a, b, c, d)$ 插入到序列 $S$ 中,使得插入后该四元组成为 $S$ 中的第 $k$ 个元素。
  • $? \ a \ b \ c \ d$:Peter 想知道有多少个 $k$ 满足:在他执行操作 $+ \ k \ a \ b \ c \ d$ 后,序列中存在至少两个整数 $i$ 和 $j$,使得 $1 \le i < k < j \le |S|$,且满足 $a \neq a_i, b \neq b_i, c \neq c_i, d \neq d_i$ 以及 $a \neq a_j, b \neq b_j, c \neq c_j, d \neq d_j$。

请帮助 Peter 实现这些操作。

输入格式

输入包含多个测试用例。对于每个测试用例:

第一行包含一个整数 $n$ ($1 \le n \le 200000$),表示操作次数。 接下来的 $n$ 行,每行以一个字符 $type$ ($type \in \{+, ?\}$) 开头。

  • 如果 $type$ 为 $+$,则行内还有五个整数:$k \ a \ b \ c \ d$ ($1 \le k \le |S|+ 1, 1 \le a, b, c, d \le 2^4$)。
  • 如果 $type$ 为 $?$,则行内还有四个整数:$a \ b \ c \ d$ ($1 \le a, b, c, d \le 2^4$)。

注意,询问中的数字经过了编码。如果上一个询问的答案为 $last$,则实际出现的数字 $x$ 为 $x \oplus last$。(假设每个测试用例开始时 $last = 0$。“$\oplus$”表示按位异或。)上述数字范围为解码后的范围。

所有测试用例中 $n$ 的总和不超过 $200000$。

输出格式

对于第二种操作,输出一行包含答案。

样例

输入格式 1

3
+ 1 1 2 3 4
+ 1 1 2 3 4
? 1 2 3 3

输出格式 1

0

输入格式 2

5
+ 1 1 2 3 4
+ 1 1 2 3 4
? 4 3 2 1
+ 0 0 3 2 5
? 5 2 3 0

输出格式 2

1
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.