QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#863848 | #9584. 顾影自怜 | zhizhu | WA | 40ms | 7904kb | C++14 | 1.8kb | 2025-01-20 00:10:22 | 2025-01-20 00:10:23 |
Judging History
answer
#include <cstdio>
#include <map>
using namespace std;
const int maxn = 1000005;
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;
long long 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("%lld\n", n * (n + 1) / 2); }
else {
for (int len = k; 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;
if (i > len - 1)dict[nums[i - len]]--;
while (q[head] < i - len + 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("%lld\n", res);
}
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 5968kb
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
Wrong Answer
time: 40ms
memory: 7904kb
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 ...
output:
3931777312
result:
wrong answer 1st lines differ - expected: '500000500000', found: '3931777312'