Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- typedef long long ll;
- typedef unsigned long long ull;
- #define vi vector<int>
- #define vll vector<ll>
- #define tests int t; cin >> t; while(t--)
- #define pb push_back
- using namespace std;
- template <typename T>
- istream& operator >> (istream& i, vector<T>& v) {
- for(T& j : v) i >> j;
- return i;
- }
- template <typename T>
- ostream& operator << (ostream& o, const vector<T>& v) {
- for(T j : v) o << j;
- return o;
- }
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL); cout.tie(NULL);
- int n, k; cin >> n >> k;
- vi v(n); cin >> v;
- int arr[(int)1e5+5] = {0};
- ll i = 0, j = 0, count = 0, prev = 0;
- int elem = 0;
- while(j < n) {
- while(j < n) {
- if(arr[v[j]] == 0) {
- if(elem == k) {
- break;
- }
- elem++;
- }
- arr[v[j++]]++;
- }
- count += (j-prev)*(j-prev+1)/2+(j-prev)*(prev-i);
- prev = j;
- if(arr[v[i]] == 1) {
- elem--;
- }
- arr[v[i++]]--;
- }
- cout << count;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement