QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#863857#9584. 顾影自怜zhizhuTL 145ms11772kbC++141.9kb2025-01-20 00:21:272025-01-20 00:21:34

Judging History

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

  • [2025-01-20 00:21:34]
  • 评测
  • 测评结果:TL
  • 用时:145ms
  • 内存:11772kb
  • [2025-01-20 00:21:27]
  • 提交

answer

#include <cstdio>
#include <map>
using namespace std;
const int maxn = 1000005;
map<long long int,long long int> dict;//数:个数
long long 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() {
    long long int t, n, k;
    long long  res;
    scanf("%lld", &t);
    while (t--) {
        scanf("%lld%lld", &n, &k);
        for (long long int i = 0; i < n; i++)scanf("%lld", &nums[i]);
        res = 0;
        if (k == 1) { res = n*(n+1)/2; printf("%lld\n", res); }
        else {
            for (long long int len = k; len <= n; len++) {
                /* printf("\nlen=%d\n", len);*/
                int head = 0, tail = -1;
                //首先 放第一波
                dict.clear();
                for (long long 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 (long long 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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 5964kb

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: 0
Accepted
time: 40ms
memory: 11772kb

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:

500000500000

result:

ok single line: '500000500000'

Test #3:

score: 0
Accepted
time: 145ms
memory: 5844kb

input:

158921
1 1
1
2 1
1 1
2 2
1 1
2 1
1 2
2 2
1 2
2 1
2 1
2 2
2 1
2 1
2 2
2 2
2 2
3 1
1 1 1
3 2
1 1 1
3 3
1 1 1
3 1
1 1 2
3 2
1 1 2
3 3
1 1 2
3 1
1 1 3
3 2
1 1 3
3 3
1 1 3
3 1
1 2 1
3 2
1 2 1
3 3
1 2 1
3 1
1 2 2
3 2
1 2 2
3 3
1 2 2
3 1
1 2 3
3 2
1 2 3
3 3
1 2 3
3 1
1 3 1
3 2
1 3 1
3 3
1 3 1
3 1
1 3 2
3 2...

output:

1
3
1
3
0
3
0
3
1
6
3
1
6
1
0
6
1
0
6
0
0
6
2
0
6
0
0
6
0
0
6
0
0
6
2
0
6
1
0
6
1
0
6
0
0
6
2
0
6
3
1
6
1
0
6
0
0
6
0
0
6
2
0
6
1
0
6
0
0
6
1
0
6
0
0
6
1
0
6
1
0
6
2
0
6
2
0
6
3
1
10
6
3
1
10
3
1
0
10
3
1
0
10
3
1
0
10
1
0
0
10
4
0
0
10
1
0
0
10
1
0
0
10
1
0
0
10
1
0
0
10
4
0
0
10
1
0
0
10
1
0
0
10
...

result:

ok 158921 lines

Test #4:

score: -100
Time Limit Exceeded

input:

1
1000000 1000
1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 100...

output:


result: