Problem 2985 --Longest Subarray

2985: Longest Subarray

"
Time Limit $1$ 秒/Second(s) Memory Limit $512$ 兆字节/Megabyte(s)
提交总数 $1$ 正确数量 $1$
裁判形式 标准裁判/Standard Judge 我的状态 尚未尝试
难度 分类标签
You are given two integers C,KC,K and an array of NN integers a1,a2,...,aNa1,a2,...,aN. It is guaranteed that the value of aiai is between 11 to CC
We define that a continuous subsequence al,al+1,...,ar(l≤r)al,al+1,...,ar(l≤r) of array a is a good subarray if and only if the following condition is met: 
∀x∈[1,C],∑i=lr[ai=x]=0or∑i=lr[ai=x]≥K∀x∈[1,C],∑i=lr[ai=x]=0or∑i=lr[ai=x]≥K

It implies that if a number appears in the subarray, it will appear no less than KK times. 
You should find the longest good subarray and output its length. Or you should print 00 if you cannot find any.

There are multiple test cases. 

Each case starts with a line containing three positive integers N,C,K(N,C,K≤105)N,C,K(N,C,K≤105)

The second line contains NN integer a1,a2,...,aN(1≤ai≤C)a1,a2,...,aN(1≤ai≤C)

We guarantee that the sum of NNs, the sum of CCs and the sum of KKs in all test cases are all no larger than 5×1055×105.
For each test case, output one line containing an integer denoting the length of the longest good subarray.
7 4 2
2 1 4 1 4 3 2
4

推荐代码 查看2985 所有题解 上传题解视频得图灵币

本题记录 用 户(点击查看用户) 运行号(点击购买题解) 时 间
算法最快[$575 $ms] 淡意的温柔 591122 2020-06-06 08:15:45
内存最少[$13236 $KB] 淡意的温柔 591122 2020-06-06 08:15:45
第一AC 淡意的温柔 591122 2020-06-06 08:15:45
第一挑战 淡意的温柔 591122 2020-06-06 08:15:45

赛题来源/所属竞赛 2019 Multi-University Training Contest 2 N/A

竞赛编号 竞赛名称 竞赛时间 访问比赛