QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#732966#5459. Goose, goose, DUCK?ChensenCHX#WA 1ms5960kbC++23887b2024-11-10 16:41:262024-11-10 16:41:26

Judging History

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

  • [2024-11-10 16:41:26]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5960kb
  • [2024-11-10 16:41:26]
  • 提交

answer

#include <iostream>
using namespace std;
const int N = 1e6 + 10;
typedef long long LL;
LL a[N];
LL q[N], tt, hh;
int vis[N];
LL ans;

void solve() {
    LL n, k;
    scanf("%lld%lld", &n, &k);
    for (int i = 1; i <= n; i++) {
        scanf("%lld", &a[i]);
    }
    LL last = 0;
    for (int i = 1; i <= n; i++) {
        if (++vis[a[i]] == k) {
            LL tmp = tt - hh;
            LL tmp1 = tmp * (tmp + 1) / 2;
            ans += tmp1 + tmp * (hh - last);
        }
        while (hh <= tt && vis[a[i]] == k) {
            hh++;
            vis[a[q[hh]]]--;
            
            last = hh;
        }
        q[++tt] = i;
    }
    if (hh <= tt) {
        LL tmp = tt - hh;
        LL tmp1 = tmp * (tmp + 1) / 2;
        ans += tmp1 + tmp * (hh - last);
    }
    printf("%lld\n", ans);
}

int main() {
    solve();
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 5960kb

input:

6 2
1 2 2 1 3 3

output:

10

result:

ok 1 number(s): "10"

Test #2:

score: 0
Accepted
time: 1ms
memory: 5948kb

input:

6 1
1 2 3 4 5 6

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 5944kb

input:

100 10
142826 764475 142826 986320 764475 142826 142826 986320 764475 986320 764475 764475 764475 142826 142826 986320 764475 986320 764475 764475 142826 764475 142826 764475 986320 986320 764475 142826 764475 764475 142826 764475 764475 986320 142826 142826 142826 142826 764475 986320 986320 764475...

output:

8842

result:

wrong answer 1st numbers differ - expected: '4309', found: '8842'