CF1438E.Yurii Can Do Everything

省选/NOI-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Yurii is sure he can do everything. Can he solve this task, though?

He has an array aa consisting of nn positive integers. Let's call a subarray a[l...r]a[l...r] good if the following conditions are simultaneously satisfied:

  • l+1≤r−1l+1 \leq r-1, i. e. the subarray has length at least 33;
  • (al⊕ar)=(al+1+al+2+…+ar−2+ar−1)(a_l \oplus a_r) = (a_{l+1}+a_{l+2}+\ldots+a_{r-2}+a_{r-1}), where ⊕\oplus denotes the bitwise XOR operation.

In other words, a subarray is good if the bitwise XOR of the two border elements is equal to the sum of the rest of the elements.

Yurii wants to calculate the total number of good subarrays. What is it equal to?

An array cc is a subarray of an array dd if cc can be obtained from dd by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.

尤里确信自己无所不能。但他能解决这个题目吗?

他有一个由 nn 个正整数组成的数组 aa。我们称子数组 a[l...r]a[l...r] 是“好的”,当且仅当同时满足以下两个条件:

  • l+1≤r−1l+1 \leq r-1,即该子数组长度至少为 33;
  • (al⊕ar)=(al+1+al+2+…+ar−2+ar−1)(a_l \oplus a_r) = (a_{l+1}+a_{l+2}+\ldots+a_{r-2}+a_{r-1}),其中 ⊕\oplus 表示按位异或运算。

换言之,一个子数组是“好的”,当且仅当其两端元素的按位异或值等于其余所有元素之和。

尤里希望计算出“好的”子数组的总数。这个总数是多少?

数组 cc 是数组 dd 的一个子数组,当且仅当 cc 可通过从 dd 的开头删除若干(可能为零个或全部)元素,并从 dd 的末尾删除若干(可能为零个或全部)元素而得到。

输入格式

The first line contains a single integer nn (3≤n≤2⋅1053 \leq n \leq 2\cdot 10^5) — the length of aa.

The second line contains nn integers a1,a2,…,ana_1,a_2,\ldots,a_n (1≤ai<2301 \leq a_i \lt 2^{30}) — elements of aa.

第一行包含一个整数 nn(3≤n≤2⋅1053 \leq n \leq 2\cdot 10^5)—— 数组 aa 的长度。

第二行包含 nn 个整数 a1,a2,…,ana_1,a_2,\ldots,a_n(1≤ai<2301 \leq a_i \lt 2^{30})—— 数组 aa 的元素。

输出格式

Output a single integer — the number of good subarrays.

输出一个整数——好子数组的个数。

输入输出样例

  • 输入#1

    8
    3 1 2 3 1 2 3 15

    输出#1

    6
  • 输入#2

    10
    997230370 58052053 240970544 715275815 250707702 156801523 44100666 64791577 43523002 480196854

    输出#2

    2

说明/提示

There are 66 good subarrays in the example:

  • [3,1,2][3,1,2] (twice) because (3⊕2)=1(3 \oplus 2) = 1;
  • [1,2,3][1,2,3] (twice) because (1⊕3)=2(1 \oplus 3) = 2;
  • [2,3,1][2,3,1] because (2⊕1)=3(2 \oplus 1) = 3;
  • [3,1,2,3,1,2,3,15][3,1,2,3,1,2,3,15] because (3⊕15)=(1+2+3+1+2+3)(3 \oplus 15) = (1+2+3+1+2+3).

示例中有 66 个“好”子数组:

  • [3,1,2][3,1,2](出现两次),因为 (3⊕2)=1(3 \oplus 2) = 1;
  • [1,2,3][1,2,3](出现两次),因为 (1⊕3)=2(1 \oplus 3) = 2;
  • [2,3,1][2,3,1],因为 (2⊕1)=3(2 \oplus 1) = 3;
  • [3,1,2,3,1,2,3,15][3,1,2,3,1,2,3,15],因为 (3⊕15)=(1+2+3+1+2+3)(3 \oplus 15) = (1+2+3+1+2+3)。

输入解题思路,AI测评打分。不知道怎么写?

首页