QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#863841 | #9584. 顾影自怜 | zhizhu | RE | 0ms | 3840kb | C++14 | 1.8kb | 2025-01-19 23:52:50 | 2025-01-19 23:52:50 |
Judging History
answer
#include <cstdio>
#include <map>
using namespace std;
const int maxn = 100005;
map<int,int> dict;//数:个数
int q[maxn],nums[maxn];
void print(int h,int t) {
printf("head=%d tail=%d\n", h, t);
for (int i = h; i <= t; i++)printf("%d ", q[i]);
printf("\n");
}
int main() {
int t, n, k,res;
scanf("%d", &t);
while (t--) {
scanf("%d%d", &n, &k);
for (int i = 0; i < n; i++)scanf("%d", &nums[i]);
res = 0;
if (k == 1) { printf("%d\n", n * (n + 1) / 2); }
else {
for (int len = 2; len <= n; len++) {
/*printf("\nlen=%d\n", len);*/
int head = 0, tail = -1;
//首先 放第一波
dict.clear();
for (int i = 0; i < len-1; i++) {
if (!dict.count(nums[i]))dict[nums[i]] = 0;
dict[nums[i]]++;
while (head <= tail && nums[q[tail]] <= nums[i])tail--;
q[++tail] = i;
}
/* print(head,tail);*/
//然后 开始移动
for (int i = len-1; i < n; i++) {
if (!dict.count(nums[i]))dict[nums[i]] = 0;
dict[nums[i]]++;
while (head <= tail && nums[q[tail]] < nums[i])tail--;
q[++tail] = i;
while (q[head] < i - len + 1) {
dict[nums[q[head]]]-=1;
head++;
}
/*print(head, tail);
printf("max=%d,dict[]=%d\n", nums[q[head]], dict[nums[q[head]]]);*/
if (dict[nums[q[head]]] >= k)res++;
}
}
}
printf("%d\n", res);
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3840kb
input:
2 5 2 1 3 3 2 2 4 3 1 4 2 1
output:
7 0
result:
ok 2 lines
Test #2:
score: -100
Runtime Error
input:
1 1000000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...