Submission

Status:

[P][P][P][P][P][-SSSS]

Subtask/Task Score:

{17/17}{17/17}{17/17}{17/17}{17/17}{0/17}

Score: 85

User: NealonX90

Problemset: ละลานตา

Language: cpp

Time: 0.012 second

Submitted On: 2026-10-16 11:40:35

#include <bits/stdc++.h>
using namespace std;

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int n , k;cin >> n >> k;
    vector<int> j(n);
    for (auto & l : j) cin >> l;
    unordered_map<int,int> mp;
    int sl = 0;
    int cnt = 0;
    int ans = 0;
    for (int fs = 0 ; fs < n ; fs++) {
        if (mp[j[fs]] == 0) {
            cnt++;
        }
        mp[j[fs]] += 1;
        while (cnt >= k) {
            mp[j[sl]] -= 1;
            if (mp[j[sl]] == 0) {
                cnt -= 1;
            }
            sl += 1;
        }
        ans += sl;
    }
    cout << ans;
}