QOJ.ac

QOJ

时间限制: 2.0 s 内存限制: 64 MB 总分: 100

#7197. 你听说过的 24 种数据结构

统计

Bobo 有一个 $\{1, 2, 3, 4\}$ 的排列 $p$ 和一个 $\{1, 2, \dots, n\}$ 的排列 $a$。他想要计算 $a$ 中与 $p$ 相似的子序列的数量。

也就是说,要计算满足以下条件的四元组 $(t_1, t_2, t_3, t_4)$ 的数量:

  • $1 \le t_1 < t_2 < t_3 < t_4 \le n$
  • 对于所有 $1 \le i, j \le 4$,满足 $(p_i - p_j) \cdot (a_{t_i} - a_{t_j}) \ge 0$。

输入格式

第一行包含一个整数 $n$ ($1 \le n \le 2000$)。 第二行包含 4 个整数 $p_1, p_2, p_3, p_4$ ($1 \le p_i \le 4$)。 第三行包含 $n$ 个整数 $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$)。

输出格式

输出一个整数,表示子序列的数量。

样例

样例输入 1

5
1 2 3 4
1 2 3 4 5

样例输出 1

5

样例输入 2

8
1 3 2 4
1 2 5 6 3 4 7 8

样例输出 2

16

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.