Pagini recente » Istoria paginii runda/pebarbamea/clasament | Cod sursa (job #1939354) | Cod sursa (job #1851002) | Cod sursa (job #1507096) | Cod sursa (job #1727473)
#include <unordered_map>
#include <iostream>
#include <cstdio>
using namespace std;
unordered_map <unsigned int, int> marcat;
const int maxn = (1 << 20) + 5;
unsigned int v[maxn];
char T[35];
unsigned int n, l, u;
int poz = 0;
inline void citeste(unsigned int &numar)
{
numar = 0;
while (T[poz] < '0' || T[poz] > '9')
if (++poz == 30)
fread(T, 1, 30, stdin), poz=0;
while ('0' <= T[poz] && T[poz] <= '9')
{
numar = numar * 10 + T[poz] - '0';
if (++poz == 30)
fread(T, 1, 30, stdin), poz=0;
}
}
long long count_substrings(int p)
{
long long num = 0;
int dim = 0;
for(unsigned int st = 1, dr = 1; dr <= n; dr++)
{
if(!marcat[v[dr]])
dim++;
marcat[v[dr]]++;
while(dim > p)
{
marcat[v[st]]--;
if(!marcat[v[st]])
dim--;
st++;
}
num = num + dr - st;
}
return num;
}
int main()
{
freopen("secv5.in", "r", stdin);
freopen("secv5.out", "w", stdout);
citeste(n);
citeste(l);
citeste(u);
for(int i = 1; i <= n; i++)
citeste(v[i]);
long long aux = count_substrings(u);
marcat.clear();
printf("%lld\n", aux - count_substrings(l - 1));
return 0;
}