QOJ.ac

QOJ

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

#988. 將燈光歸還至盒子

Statistics

Wesley 需要拆下他的節日燈飾。他有一排 $N$ 個燈泡,其中一些可能處於開啟狀態。Wesley 需要在拔掉插頭前讓所有燈泡都熄滅(否則他會遭受致命的電擊)。

每個燈泡都有一個對應的開關可以用來開啟或關閉該燈泡,且 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.