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: yourmom
Problemset: ละลานตา
Language: cpp
Time: 0.008 second
Submitted On: 2026-10-08 20:30:16
#include <iostream>
#include <vector>
using namespace std;
const int MAX_COLOR = 100005;
int color_count[MAX_COLOR];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N, K;
if (!(cin >> N >> K)) return 0;
vector<int> C(N);
for (int i = 0; i < N; ++i) {
cin >> C[i];
}
long long ans = 0;
int L = 0;
int distinct_colors = 0;
for (int R = 0; R < N; ++R) {
if (color_count[C[R]] == 0) {
distinct_colors++;
}
color_count[C[R]]++;
while (distinct_colors >= K) {
ans += (N - R);
color_count[C[L]]--;
if (color_count[C[L]] == 0) {
distinct_colors--;
}
L++;
}
}
cout << ans << "\n";
return 0;
}