编程介的小学生 2018-12-21 14:12 采纳率: 20.5%
浏览 206
已采纳

这个问题是不是使用分治的办法解决?C语言怎么实现,具体的实现

Problem Description
After all the difficulties, Psyche and Cupid are finally getting married.

No ordinary pearls can hold Cupid's love for Psyche. So he has collected the Jewelry of Gods at the top of Mount Olympus to make her a chain.

There are n beads on the chain. The i-th bead is of the type Ai.

Being pretty in appearance and generous in her heart, Psyche decides to give one consecutive part of the chain to her mother.

To meet her mother's particular taste, that part must have at least one type of bead that appears x times exactly.

Psyche wants to know the number of ways to choose a part of the chain for her mother.

Note that two parts [L1,R1] and [L2,R2] are different only if L1≠L2 or R1≠R2.

Input
The first line of the input contains an integer T (1≤T≤15), which denotes the number of test cases.

For each test case, the first line contains two integers n,x (1≤n≤105,1≤x≤n).

The second line contains n integers, the i-th integer denotes Ai (0≤Ai≤109).

Output
For each test case, print an integer which denotes the number of parts Psyche can choose.

Sample Input
2
3 1
1 2 1
4 2
2 3 2 2

Sample Output
6
3

  • 写回答

1条回答

  • threenewbee 2019-08-24 23:56
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧