tuki2501

sopenp.cpp

Nov 5th, 2021
749
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int N = 2000005;
  5.  
  6. int a[N];
  7.  
  8. signed main() {
  9.   cin.tie(0)->sync_with_stdio(0);
  10.   int n, l, r;
  11.   cin >> n >> l >> r;
  12.   for (int i = 1; i <= n; i++) {
  13.     cin >> a[i];
  14.   }
  15.   map<int,int> cl, cr;
  16.   int pl = 1, pr = 1;
  17.   long long ans = 0;
  18.   for (int i = 1; i <= n; i++) {
  19.     cl[a[i]]++; cr[a[i]]++;
  20.     while (pr < i && (int) cr.size() > r) {
  21.       if (--cr[a[pr]] == 0) cr.erase(a[pr]);
  22.       pr++;
  23.     }
  24.     while (pl <= i && (int) cl.size() >= l) {
  25.       if (--cl[a[pl]] == 0) cl.erase(a[pl]);
  26.       pl++;
  27.     }
  28.     if ((int) cr.size() <= r && (int) cl.size() < l) {
  29.       ans += pl - pr;
  30.     }
  31.   }
  32.   cout << ans << '\n';
  33. }
Advertisement
Add Comment
Please, Sign In to add comment