CF1584E.Game with Stones
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Bob decided to take a break from calculus homework and designed a game for himself.
The game is played on a sequence of piles of stones, which can be described with a sequence of integers s1,…,sk, where si is the number of stones in the i-th pile. On each turn, Bob picks a pair of non-empty adjacent piles i and i+1 and takes one stone from each. If a pile becomes empty, its adjacent piles do not become adjacent. The game ends when Bob can't make turns anymore. Bob considers himself a winner if at the end all piles are empty.
We consider a sequence of piles winning if Bob can start with it and win with some sequence of moves.
You are given a sequence a1,…,an, count the number of subsegments of a that describe a winning sequence of piles. In other words find the number of segments [l,r] (1≤l≤r≤n), such that the sequence al,al+1,…,ar is winning.
鲍勃决定暂时放下微积分作业,为自己设计了一个游戏。
该游戏在一个石堆序列上进行,该序列可用一串整数 s1,…,sk 描述,其中 si 表示第 i 个石堆中的石子数量。在每一轮中,鲍勃选择一对非空且相邻的石堆 i 和 i+1,并从每个石堆中各取走一颗石子。若某个石堆变为空,则其相邻石堆不会因此变为相邻。当鲍勃无法再进行任何操作时,游戏结束。若游戏结束时所有石堆均为空,鲍勃便认为自己获胜。
我们称一个石堆序列为“获胜序列”,如果鲍勃可以从该序列出发,并通过某种操作序列赢得游戏。
现给定一个序列 a1,…,an,请计算该序列中有多少个子段(连续子数组)描述了一个获胜序列。换言之,求满足条件的区间 [l,r](其中 1≤l≤r≤n)的个数,使得子序列 al,al+1,…,ar 是一个获胜序列。
输入格式
Each test consists of multiple test cases. The first line contains a single integer t (1≤t≤3⋅105) — the number of test cases. Description of the test cases follows.
The first line of each test case contains a single integer n (1≤n≤3⋅105).
The second line of each test case contains n integers a1,a2,…,an (0≤ai≤109).
It is guaranteed that the sum of n over all test cases does not exceed 3⋅105.
每个测试包含多个测试用例。第一行包含一个整数 t(1≤t≤3⋅105),表示测试用例的数量。随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 n(1≤n≤3⋅105)。
每个测试用例的第二行包含 n 个整数 a1,a2,…,an(0≤ai≤109)。
保证所有测试用例的 n 值之和不超过 3⋅105。
输出格式
Print a single integer for each test case — the answer to the problem.
对每个测试用例,输出一个整数——即该问题的答案。
输入输出样例
输入#1
6 2 2 2 3 1 2 3 4 1 1 1 1 4 1 2 2 1 4 1 2 1 2 8 1 2 1 2 1 2 1 2
输出#1
1 0 4 2 1 3
说明/提示
In the first test case, Bob can't win on subsegments of length 1, as there is no pair of adjacent piles in an array of length 1.
In the second test case, every subsegment is not winning.
In the fourth test case, the subsegment [1,4] is winning, because Bob can make moves with pairs of adjacent piles: (2,3), (1,2), (3,4). Another winning subsegment is [2,3].
在第一个测试用例中,Bob 无法在长度为 1 的子段上获胜,因为长度为 1 的数组中不存在相邻的两堆石子。
在第二个测试用例中,所有子段均非获胜子段。
在第四个测试用例中,子段 [1,4] 是获胜子段,因为 Bob 可以对相邻石子堆进行如下操作:(2,3)、(1,2)、(3,4)。另一个获胜子段是 [2,3]。
输入解题思路,AI测评打分。不知道怎么写?