CF83A.Magical Array
普及-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Valery is very interested in magic. Magic attracts him so much that he sees it everywhere. He explains any strange and weird phenomenon through intervention of supernatural forces. But who would have thought that even in a regular array of numbers Valera manages to see something beautiful and magical.
Valera absolutely accidentally got a piece of ancient parchment on which an array of numbers was written. He immediately thought that the numbers in this array were not random. As a result of extensive research Valera worked out a wonderful property that a magical array should have: an array is defined as magic if its minimum and maximum coincide.
He decided to share this outstanding discovery with you, but he asks you for help in return. Despite the tremendous intelligence and wit, Valera counts very badly and so you will have to complete his work. All you have to do is count the number of magical subarrays of the original array of numbers, written on the parchment. Subarray is defined as non-empty sequence of consecutive elements.
瓦列里对魔法非常着迷。魔法对他有着如此巨大的吸引力,以至于他处处都能看到魔法。他总是用超自然力量的干预来解释任何奇异或怪异的现象。但谁能想到,即便是在一个普通的数字数组中,瓦列里也能发现某种美丽而神奇的东西。
瓦列里偶然得到了一张古老的羊皮纸,上面写有一个数字数组。他立刻认为这个数组中的数字绝非随机。经过大量研究,瓦列里总结出一种奇妙的性质,即一个“魔法数组”应满足的条件:该数组的最小值与最大值相等。
他决定将这一非凡发现与你分享,但同时也希望你能助他一臂之力。尽管瓦列里拥有极高的智慧与机敏,他的计算能力却非常糟糕,因此你需要帮他完成这项工作。你所需要做的,仅仅是统计出这张羊皮纸上原始数字数组中魔法子数组的个数。其中,“子数组”定义为非空的连续元素序列。
输入格式
The first line of the input data contains an integer n (1 ≤ n ≤ 105). The second line contains an array of original integers _a_1, _a_2, ..., a__n ( - 109 ≤ a__i ≤ 109).
输入数据的第一行包含一个整数 n(1≤n≤105)。第二行包含一个原始整数数组 a1,a2,…,an(−109≤ai≤109)。
输出格式
Print on the single line the answer to the problem: the amount of subarrays, which are magical.
Please do not use the %lld specificator to read or write 64-bit numbers in C++. It is recommended to use cin, cout streams (you can also use the %I64d specificator).
在单行上输出问题的答案:满足“魔法”条件的子数组的数量。
在 C++ 中读取或写入 64 位整数时,请勿使用 %lld 格式说明符。建议使用 cin 和 cout 流(也可使用 %I64d 格式说明符)。
输入输出样例
输入#1
4 2 1 1 4
输出#1
5
输入#2
5 -2 -2 -2 0 1
输出#2
8
说明/提示
Notes to sample tests:
Magical subarrays are shown with pairs of indices [a;b] of the beginning and the end.
In the first sample: [1;1], [2;2], [3;3], [4;4], [2;3].
In the second sample: [1;1], [2;2], [3;3], [4;4], [5;5], [1;2], [2;3], [1;3].
样例测试说明:
魔法子数组用起始和结束位置的索引对 [a;b] 表示。
第一个样例中的魔法子数组:[1;1],[2;2],[3;3],[4;4],[2;3]。
第二个样例中的魔法子数组:[1;1],[2;2],[3;3],[4;4],[5;5],[1;2],[2;3],[1;3]。
输入解题思路,AI测评打分。不知道怎么写?