mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-08 21:58:49 +00:00
40 lines
704 B
C++
40 lines
704 B
C++
#include <iostream>
|
|
#include <unordered_map>
|
|
#include <unordered_set>
|
|
|
|
using std::cin;
|
|
using std::cout;
|
|
const char endl = '\n';
|
|
|
|
const int N = 1e6 + 5;
|
|
|
|
int n, m, a[N];
|
|
long long ans;
|
|
std::unordered_set<int> set;
|
|
std::unordered_map<int, int> map;
|
|
|
|
int main() {
|
|
std::ios::sync_with_stdio(false);
|
|
cin.tie(nullptr);
|
|
|
|
cin >> n >> m;
|
|
|
|
for (int i = 1; i <= n; i++) {
|
|
cin >> a[i];
|
|
}
|
|
|
|
for (int i = 1, j = 0; i <= n - m + 1; i++) {
|
|
while (j < n && set.size() < m) {
|
|
set.insert(a[++j]);
|
|
map[a[j]]++;
|
|
}
|
|
|
|
if (set.size() == m) ans += n - j + 1;
|
|
if (!--map[a[i]]) set.erase(a[i]);
|
|
}
|
|
|
|
cout << ans << endl;
|
|
|
|
return 0;
|
|
}
|