Pagini recente » Cod sursa (job #841826) | Cod sursa (job #204604) | Cod sursa (job #2722726) | Cod sursa (job #532560) | Cod sursa (job #2618715)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("secv5.in");
ofstream fout("secv5.out");
const int nmax = 1048576, mod = 666013;
int n, a, b, v[nmax + 5], contor, st;
vector <pair <int, int> > h[mod];
unsigned long long ans;
bool Adauga(int x)
{
int m = x % mod;
for (int i = 0; i < h[m].size(); ++i)
{
if (h[m][i].first == x)
{
++h[m][i].second;
return false;
}
}
h[m].push_back({x, 1});
return true;
}
bool Sterge(int x)
{
int m = x % mod;
for (int i = 0; i < h[m].size(); ++i)
{
if (h[m][i].first == x)
{
if (h[m][i].second == 1)
{
swap(h[m][i], h[m][h[m].size() - 1]);
h[m].pop_back();
return true;
}
else
{
h[m][i].second--;
return false;
}
}
}
}
int main()
{
fin >> n >> a >> b;
st = 1;
contor = 0;
for (int i = 1; i <= n; ++i)
{
fin >> v[i];
if (Adauga(v[i]) == true)
{
++contor;
while (contor > b)
{
if (Sterge(v[st]) == true)
{
--contor;
}
++st;
}
}
ans += (i - st + 1);
}
while (st <= n) Sterge(v[st++]);
st = 1;
contor = 0;
for (int i = 1; i <= n; ++i)
{
if (Adauga(v[i]) == true)
{
++contor;
while (contor > a - 1)
{
if (Sterge(v[st]) == true)
{
--contor;
}
++st;
}
}
ans -= (i - st + 1);
}
fout << ans;
fin.close();
fout.close();
return 0;
}