QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#516670#5459. Goose, goose, DUCK?no_RED_no_DEADWA 1ms5764kbC++201.3kb2024-08-12 20:15:272024-08-12 20:15:27

Judging History

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

  • [2024-08-12 20:15:27]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5764kb
  • [2024-08-12 20:15:27]
  • 提交

answer

#include "bits/stdc++.h"
using namespace std;
using ll = long long;

const ll N = 1e6 + 1;
const ll M = 1e9 + 7;

ll n, k;
ll a[N], cnt[N];
map<ll, ll> m;

ll cal(ll k) {
    m.clear(); ll j = 0, res = 0; m[0] = n;
    for (int i = 1; i <= n; i ++) cnt[i] = 0;
    for (int i = 1; i <= n; i ++) {
        while (m.rbegin()->first < k && j + 1 <= n) {
            m[cnt[a[j + 1]]] --; if (m[cnt[a[j + 1]]] == 0) m.erase(cnt[a[j + 1]]);
            cnt[a[j + 1]] ++;
            m[cnt[a[j + 1]]] ++;
            j ++;
            // cout << "Spec: " << j << ' ' << m.rbegin()->first << endl;
        }
        // cout << "Debug: " << i << ' ' << j << endl;
        // for (auto [x, y]: m) cout << x << ' ' << y << endl;
        
        if (j - i > 0) res += j - i;
        if (m.rbegin()->first < k) res ++;
        m[cnt[a[i]]] --; if (m[cnt[a[i]]] == 0) m.erase(cnt[a[i]]);
        cnt[a[i]] --;
        m[cnt[a[i]]] ++;
    }
    return res;
}

void doTest(ll testID) {
    cin >> n >> k;
    for (int i = 1; i <= n; i ++) cin >> a[i];
    // cout << cal(k) << endl;
    cout << cal(k) - cal(k - 1);
}

signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0);

    int test = 1; 
    // cin >> test;
    for (int _ = 1; _ <= test; _ ++) doTest(test);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 5664kb

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: 5764kb

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:

204

result:

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