Pagini recente » Cod sursa (job #1771523) | Istoria paginii runda/concurs_27mai | Cod sursa (job #2642770) | Cod sursa (job #734305) | Cod sursa (job #1727492)
#include <cassert>
#include <iostream>
#include <vector>
#include <cstdio>
using namespace std;
const int maxn = (1 << 20) + 5;
const int mod = 99991;
unsigned int v[maxn];
vector <pair <unsigned int, int>> hassh[mod + 5];
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;
}
}
int search_poz(unsigned int p, int x)
{
int sz = hassh[x].size();
for(int i = 0; i < sz; i++)
if(hassh[x][i].first == p)
return i;
return -1;
}
void sterge(unsigned int p)
{
int x = p % mod;
int ind = search_poz(p, x);
assert(ind >= 0);
if(hassh[x][ind].second == 1)
{
swap(hassh[x][ind], hassh[x][hassh[x].size()-1]);
hassh[x].pop_back();
}
else
hassh[x][ind].second--;
}
void insert(unsigned int p)
{
int x = p % mod;
int ind = search_poz(p, x);
if(ind == -1)
hassh[x].push_back(make_pair(p, 1));
else
hassh[x][ind].second++;
}
long long count_substrings(unsigned int p)
{
long long num = 0;
int dim = 0;
for(unsigned int st = 1, dr = 1; dr <= n; dr++)
{
if(search_poz(v[dr], v[dr] % mod) == -1)
dim++;
insert(v[dr]);
while(dim > p)
{
sterge(v[st]);
if(search_poz(v[st], v[st] % mod) == -1)
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);
for(int i = 0; i < mod; i++)
hassh[i].clear();
printf("%lld\n", aux - count_substrings(l - 1));
return 0;
}