Submission

Status:

[P][P][P][P][P][PPPPP]

Subtask/Task Score:

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

Score: 100

User: NealonX90

Problemset: ละลานตา

Language: cpp

Time: 0.015 second

Submitted On: 2026-10-16 11:41:43

#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;
    long long 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;
}