QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#863836#9588. 可重集合AInfinity_DreamWA 0ms4224kbC++141.8kb2025-01-19 23:40:382025-01-19 23:40:38

Judging History

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

  • [2025-01-19 23:40:38]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:4224kb
  • [2025-01-19 23:40:38]
  • 提交

answer

#include <cstdio>
#include <map>
using namespace std;
const int maxn = 100005;
map<int,int> dict;//Êý£º¸öÊý
int q[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,nums[maxn],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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 4224kb

input:

4
1 100
1 999
1 10
2 100

output:

0
499500
0
499500
0
499500
0

result:

wrong answer 1st lines differ - expected: '1', found: '0'