QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 512 MB Total points: 100

#988. 将灯放回盒子里

Statistics

Wesley 需要拆下他的节日彩灯。他有一排 $N$ 个彩灯,其中一些可能处于开启状态。Wesley 需要在拔掉电源之前让所有彩灯都熄灭(否则他会遭受致命的电击)。

每个彩灯都有一个对应的开关,可以用来开启或关闭该灯。从第 1 秒开始,Wesley 每秒最多可以使用其中一个开关。然而,这些彩灯非常不稳定,在接下来的 $M$ 秒内,它们会自行切换状态!具体来说,在第 $i$ 秒结束时,第 $b_i$ 个彩灯的状态会发生翻转:如果它原来是关的,则会开启;如果它原来是开的,则会关闭。Wesley 希望尽快拆下彩灯,因此他想知道在理想情况下,所有彩灯熄灭的最早时间。特别地,请输出最小的 $i$,使得通过某种开关使用序列,所有彩灯能在第 $i$ 秒结束时熄灭。注意,如果所有彩灯初始时都是熄灭的,则最小的 $i$ 为 0。

输入格式

第一行包含两个整数 $N$ 和 $M$,分别表示彩灯的数量和彩灯将发生的自动状态改变次数($1 \le N, M \le 2 \cdot 10^5$)。

第二行包含 $N$ 个整数 $a_1, a_2, \dots, a_N$($0 \le a_i \le 1$),表示彩灯的初始状态。其中 $a_i = 1$ 表示第 $i$ 个彩灯初始为开启状态,$a_i = 0$ 表示其为关闭状态。

第三行(最后一行)包含 $M$ 个整数 $b_1, b_2, \dots, b_M$,表示第 $b_i$ 个彩灯在第 $i$ 秒结束时会翻转其状态($1 \le b_i \le N$)。

输出格式

输出一个整数,表示 Wesley 将所有彩灯熄灭所需的最早时间(以秒为单位)。注意,如果所有彩灯在 $M$ 秒过去之前就能熄灭,Wesley 将忽略后续的任何翻转并立即拆下它们。

样例

输入 1

3 3
1 1 1
1 2 3

输出 1

2

输入 2

5 8
0 1 0 1 1
1 2 2 1 4 3 2 1

输出 2

4

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.