A8664 | Non-Secret Cypher
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Berland starts to seize the initiative on the war with Flatland. To drive the enemy from their native land, the berlanders need to know exactly how many more flatland soldiers are left in the enemy's reserve. Fortunately, the scouts captured an enemy in the morning, who had a secret encrypted message with the information the berlanders needed so much.
The captured enemy had an array of positive integers. Berland intelligence have long been aware of the flatland code: to convey the message, which contained a number $m$ , the enemies use an array of integers $a$ . The number of its subarrays, in which there are at least $k$ equal numbers, equals $m$ . The number $k$ has long been known in the Berland army so General Touristov has once again asked Corporal Vasya to perform a simple task: to decipher the flatlanders' message.
Help Vasya, given an array of integers $a$ and number $k$ , find the number of subarrays of the array of numbers $a$ , which has at least $k$ equal numbers.
Subarray $a[i...\ j] (1<=i<=j<=n)$ of array $a=(a_{1},a_{2},...,a_{n})$ is an array, made from its consecutive elements, starting from the $i$ -th one and ending with the $j$ -th one: $a[i...\ j]=(a_{i},a_{i+1},...,a_{j})$ .
The captured enemy had an array of positive integers. Berland intelligence have long been aware of the flatland code: to convey the message, which contained a number $m$ , the enemies use an array of integers $a$ . The number of its subarrays, in which there are at least $k$ equal numbers, equals $m$ . The number $k$ has long been known in the Berland army so General Touristov has once again asked Corporal Vasya to perform a simple task: to decipher the flatlanders' message.
Help Vasya, given an array of integers $a$ and number $k$ , find the number of subarrays of the array of numbers $a$ , which has at least $k$ equal numbers.
Subarray $a[i...\ j] (1<=i<=j<=n)$ of array $a=(a_{1},a_{2},...,a_{n})$ is an array, made from its consecutive elements, starting from the $i$ -th one and ending with the $j$ -th one: $a[i...\ j]=(a_{i},a_{i+1},...,a_{j})$ .
输入格式
The first line contains two space-separated integers $n$ , $k$ $(1<=k<=n<=4·10^{5})$ , showing how many numbers an array has and how many equal numbers the subarrays are required to have, correspondingly.
The second line contains $n$ space-separated integers $a_{i}$ ( $1<=a_{i}<=10^{9}$ ) — elements of the array.
The second line contains $n$ space-separated integers $a_{i}$ ( $1<=a_{i}<=10^{9}$ ) — elements of the array.
输出格式
Print the single number — the number of such subarrays of array $a$ , that they have at least $k$ equal integers.
Please do not use the %lld specifier to read or write 64-bit integers in С++. In is preferred to use the cin, cout streams or the %I64d specifier.
Please do not use the %lld specifier to read or write 64-bit integers in С++. In is preferred to use the cin, cout streams or the %I64d specifier.
输入输出样例
输入 #1
4 2 1 2 1 2
输出 #1
3
输入 #2
5 3 1 2 1 1 3
输出 #2
2
输入 #3
3 1 1 1 1
输出 #3
6
In the first sample are three subarrays, containing at least two equal numbers: (1,2,1), (2,1,2) and (1,2,1,2).
In the second sample are two subarrays, containing three equal numbers: (1,2,1,1,3) and (1,2,1,1).
In the third sample any subarray contains at least one 1 number. Overall they are 6: (1), (1), (1), (1,1), (1,1) and (1,1,1).
In the second sample are two subarrays, containing three equal numbers: (1,2,1,1,3) and (1,2,1,1).
In the third sample any subarray contains at least one 1 number. Overall they are 6: (1), (1), (1), (1,1), (1,1) and (1,1,1).
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted