QOJ.ac

QOJ

Limite de temps : 4 s Limite de mémoire : 256 MB Points totaux : 140

#13682. Dojave

Statistiques

今年最大的一场赛事对克罗地亚队来说以悲剧告终。CERC 有史以来最具影响力的理论家、著名网页 CERC Tips 的创始人,同时也是业余时间里优秀的贝斯手,在他最近的一次表现中未能带领他的队伍晋级决赛。

为了度过他的存在主义危机,我们的主角开始玩一些概率游戏。他尤其对以下游戏感兴趣:

给你一个正整数 $M$。我们的主角面前有一个数组 $0, 1, 2, \dots, 2^M - 1$ 的排列。

电脑会选择该排列的一个非空连续子序列,并将其在东南欧某个国家的首都上空点亮。

我们的知己在努力忍住因回忆往事而流下的泪水后,必须选择该排列中的两个不同元素并交换它们的位置。当且仅当交换后被点亮的子序列中所有元素的按位异或(XOR)和恰好为 $2^M - 1$ 时,我们的主角获胜。

我们的英雄想要知道,电脑可以点亮多少个不同的连续子序列,使得他能够获胜。

请帮助我们的英雄克服他的(身份)危机,让我们最喜欢的网页能够重新活跃起来。

输入格式

输入的第一行包含一个整数 $M$($1 \le M \le 20$)。

第二行包含 $2^M$ 个空格分隔的整数,构成数组 $0, 1, 2, \dots, 2^M - 1$ 的一个排列。

输出格式

输出电脑可以点亮的、能让我们的英雄获胜的连续子序列的总数。

子任务

在占总分 50% 的测试数据中,满足 $1 \le M \le 14$。

样例

输入样例 1

2
0 1 2 3

输出样例 1

9

输入样例 2

3
3 7 0 4 6 1 5 2

输出样例 2

33

输入样例 3

4
13 0 15 12 4 8 7 3
11 14 6 10 1 5 9 2

输出样例 3

133

说明

样例 1 说明:

在第一个样例中,如果电脑选择子序列 [1 2 3],我们的英雄可以交换数字 03。在这种情况下,除了整个数组之外,对于任何被选择的连续子序列,他实际上都可以获胜。

样例 2 说明:

在第二个样例中,如果电脑选择整个数组 [3 7 0 4 6 1 5 2] 作为被点亮的子序列,无论交换哪两个元素,我们的英雄都无法改变该子序列的异或和(其为 0)。

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.