Pagini recente » Cod sursa (job #2196841) | Cod sursa (job #54992) | Cod sursa (job #566809) | Cod sursa (job #1522250) | Cod sursa (job #1218827)
#include <fstream>
#include <iostream>
#include <vector>
#include <map>
#include <tr1/unordered_map>
using namespace std;
vector<unsigned int> v;
typedef map<unsigned int, int> my_hash;
//typedef std::tr1::unordered_map<unsigned int, int> my_hash;
unsigned long long count(int n, int limit)
{
my_hash s;
unsigned long long count = 0;
for (int left = 0, right = 0; right < n; right++)
{
s[v[right]]++;
while (s.size() > limit)
{
my_hash::iterator it = s.find(v[left++]);
if (!--it->second)
s.erase(it);
}
count += right - left + 1;
}
return count;
}
int main()
{
ifstream fi("secv5.in");
ofstream fo("secv5.out");
int n, l, u;
fi >> n >> l >> u;
v.reserve(n);
for (int i = 0; i < n; i++)
{
unsigned int x;
fi >> x;
v.push_back(x);
}
fo << count(n, u) - count(n, l - 1) << '\n';
}