Pagini recente » Cod sursa (job #1591915) | Cod sursa (job #2921706) | Cod sursa (job #1684191) | Cod sursa (job #1145870) | Cod sursa (job #2952297)
// grea raw
#include <iostream>
#include <fstream>
#include <queue>
#include <map>
using namespace std;
ifstream fin("secv5.in");
ofstream fout("secv5.out");
const int NMAX = (1 << 20);
int n;
int v[NMAX + 1];
int solve(int lim){
map <int, int> f;
f[v[1]] = 1;
queue <int> Q;
Q.push(1);
int ans = 0;
for(int i = 1; i <= n; i++){
Q.push(i);
f[v[i]]++;
while(!Q.empty() && (int)f.size() > lim){
int Front = v[Q.front()];
Q.pop();
f[Front]--;
if(f[Front] <= 0)
f.erase(Front);
}
if(!Q.empty()){
ans += (i - Q.front() + 1);
}
}
return ans;
}
int main(){
int l, u;
fin >> n >> l >> u;
for(int i = 1; i <= n; i++){
fin >> v[i];
}
fout << solve(u) - solve(l - 1) << '\n';
return 0;
}