Universal Cup Judging System

Universal Cup

Time Limit: 3.0 s Memory Limit: 768 MB Total points: 100 Hackable ✓
Statistics

注意:記憶體限制較為特殊。

給你一個整數 $N$ 和一個整數序列 $A = (A_1, A_2, \dots, A_N)$。

你對該序列重複進行操作,直到其長度變為 $1$。在每一步中,你選擇當前序列中的兩個相鄰元素並將它們合併為一個元素。每次合併後,所得序列將按自然順序重新編號。有以下兩種操作可用:

  • AND 操作:將 $A_i$ 和 $A_{i+1}$ 替換為 $(A_i \mathbin{\&} A_{i+1})$。
  • OR 操作:將 $A_i$ 和 $A_{i+1}$ 替換為 $(A_i \mathbin{|} A_{i+1})$。

這裡,運算子 $\&$ 和 $|$ 分別表示位元與(AND)和位元或(OR)操作。

由於每次操作都會使序列長度減少 $1$,因此總共進行恰好 $(N - 1)$ 次操作。

在所有使得最終剩下的元素等於 $0$ 的可能操作序列中,求進行 OR 操作的最大可能次數。

輸入格式

輸入包含多個測試資料。

T
testcase 1
testcase 2
:
testcase T

每組測試資料按以下格式給出:

N
A_1 A_2 ... A_N

資料範圍

  • $1 \le T \le 2^{12}$
  • $2 \le N \le 2^{13}$
  • $0 \le A_i < 2^{13}$
  • 所有測試資料中 $N$ 的總和不超過 $2^{13}$。
  • 所有輸入值均為整數。

輸出格式

輸出在所有滿足最終剩下元素等於 $0$ 的操作序列中,可以進行 OR 操作的最大次數。如果沒有操作序列滿足該條件,則輸出 $-1$。

範例

輸入範例 1

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

輸出範例 1

3
0
5
6

說明

該輸入包含 $4$ 組測試資料。

對於第一組測試資料,我們可以按如下方式進行 $3$ 次第二種操作(OR 操作):

  • 初始時,$A = (3, 0, 1, 4, 1, 5)$。
  • 對 $(A_3, A_4)$ 套用 OR 操作。操作後,$A = (3, 0, 5, 1, 5)$。
  • 對 $(A_1, A_2)$ 套用 AND 操作。操作後,$A = (0, 5, 1, 5)$。
  • 對 $(A_3, A_4)$ 套用 OR 操作。操作後,$A = (0, 5, 5)$。
  • 對 $(A_2, A_3)$ 套用 OR 操作。操作後,$A = (0, 5)$。
  • 對 $(A_1, A_2)$ 套用 AND 操作。操作後,$A = (0)$。

由於最終狀態滿足 $A_1 = 0$,因此滿足條件。

無法在進行 $4$ 次或更多次 OR 操作的情況下滿足條件,因此答案為 $3$。

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#1490EditorialOpen题解jianglyView

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.