Pagini recente » Cod sursa (job #462756) | Cod sursa (job #208469) | Cod sursa (job #2633044) | Cod sursa (job #402641) | Cod sursa (job #3271776)
#include <bits/stdc++.h>
using namespace std;
ifstream f("secv5.in");
ofstream g("secv5.out");
const int32_t MAX_DIM = (1 << 20);
int32_t N, U, L;
int32_t a[MAX_DIM + 5];
int32_t fr[MAX_DIM + 5];
vector<int32_t> v;
int64_t nrSecv(int32_t x)
{
memset(fr, 0, sizeof(fr));
int64_t cnt = 0;
int32_t st = 1, nr = 0;
for (int32_t dr = 1; dr <= N; dr++)
{
if (++fr[a[dr]] == 1)
nr++;
while (nr > x && st <= dr)
{
if (--fr[a[st]] == 0)
nr--;
st++;
}
cnt += (dr - st + 1);
}
return cnt;
}
int main()
{
f >> N >> U >> L;
for (int32_t i = 1; i <= N; i++)
{
f >> a[i];
v.push_back(a[i]);
}
sort(v.begin(), v.end());
v.resize(unique(v.begin(), v.end()) - v.begin());
for (int32_t i = 1; i <= N; i++)
{
vector<int32_t> :: iterator it = lower_bound(v.begin(), v.end(), a[i]);
a[i] = (int32_t)(it - v.begin());
}
// for (int32_t i = 1; i <= N; i++)
// cout << a[i] << ' ';
//
// cout << '\n';
// cout << nrSecv(L) << ' ' << nrSecv(U - 1) << '\n';
g << (int64_t)(nrSecv(L) - nrSecv(U - 1)) << '\n';
f.close();
g.close();
return 0;
}