fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main() {
  4. unordered_map<int,int> counts;
  5. int n,l,r;
  6. cin>>n>>l>>r;
  7. vector<int> v(n);
  8. for(int i=0;i<n;i++) cin>>v[i];
  9. int a=0,b=-1;
  10. int64_t answer = 0;
  11. while(a<n) {
  12. while(b + 1 < n && counts[v[b+1]] == 0 && b-a+2 <= r) counts[v[++b]]++; // while the next element on the right isn't a duplicate, we move the right pointer
  13. answer += max(0, (b - a + 1) - l + 1);
  14. counts[v[a++]]--;
  15. }
  16. cout<<answer<<endl;
  17.  
  18. }
Success #stdin #stdout 0s 15240KB
stdin
5 1 3
1 2 1 2 1
stdout
9