Pagini recente » Cod sursa (job #569528) | Cod sursa (job #1598334) | Cod sursa (job #508562) | Cod sursa (job #338381) | Cod sursa (job #2450517)
#include <fstream>
#include <unordered_map>
#define ll unsigned int
using namespace std;
ifstream f("secv5.in");
ofstream g("secv5.out");
int n, r,l;
ll v[(1 << 20) + 1];
long long secv(int lungime)
{
unordered_map <ll,ll> hs;
long long sol = 0;
for(int i = 1, ultim = 1; i <= n; ++i)
{
hs[v[i]]++;
while(lungime < hs.size())
{
hs[v[ultim]]--;
if(!hs[v[ultim]]) hs.erase(v[ultim]);
ultim++;
}
sol = sol + (i - ultim + 1);
}
return sol;
}
int main()
{
f >> n >> l >> r;
for(int i = 1; i <= n; ++i)
f >> v[i];
g << secv(r) - secv(l - 1);
return 0;
}