QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#863841#9584. 顾影自怜zhizhuRE 0ms3840kbC++141.8kb2025-01-19 23:52:502025-01-19 23:52:50

Judging History

你现在查看的是最新测评结果

  • [2025-01-19 23:52:50]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3840kb
  • [2025-01-19 23:52:50]
  • 提交

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 ...

output:


result: