Pagini recente » Cod sursa (job #204985) | Cod sursa (job #2181898) | Cod sursa (job #2485433) | Cod sursa (job #2021077) | Cod sursa (job #2735528)
#include <bits/stdc++.h>
namespace FastRead {
const int Dim(1e6);
char buff[Dim];
int pos, len;
inline char nc() {
if (pos == len) {
pos = 0;
len = fread(buff, 1, Dim, stdin);
if (!len) return EOF;
}
return buff[pos++];
}
template<class T> inline void Read(T& x) {
char ch;
int sgn(1);
while (!isdigit(ch = nc()))
if (ch == '-')
sgn = -1;
x = ch - '0';
while (isdigit(ch = nc()))
x = x * 10 + (ch - '0');
x *= sgn;
}
}
using namespace FastRead;
using namespace std;
void DAU(const string& task = "") {
if (!task.empty())
freopen((task + ".in").c_str(), "r", stdin),
freopen((task + ".out").c_str(), "w", stdout);
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
void PLEC() {
exit(0);
}
#define int unsigned int
class Zaharel {
public:
Zaharel() {}
Zaharel(const int& _n) :
n(_n), ind(0), pos(0), v(_n + 1), vec(_n + 1) {}
inline void Insert(const int& val) {
v[pos] = {val, ++pos};
}
inline long long Query(const int& st, const int& dr) const {
return Query(dr) - Query(st - 1);
}
inline void Compute() {
sort(v.begin(), v.end());
for (int i = 1; i <= n; ++i) {
if (v[i].first != v[i - 1].first)
++ind;
vec[v[i].second] = ind;
}
}
private:
inline long long Query(const int& x) const {
vector<int> freq(ind + 1);
int i = 1, curr = 0;
long long res = 0;
for (int j = 1; j <= n; ++j) {
++freq[vec[j]];
if (freq[vec[j]] == 1)
++curr;
while (curr > x) {
--freq[vec[i]];
if (!freq[vec[i]])
--curr;
++i;
}
res += j - i + 1;
}
return res;
}
int n, ind, pos;
vector<pair<int, int>> v;
vector<int> vec;
};
int n, l, r, x;
signed main() {
DAU("secv5");
Read(n), Read(l), Read(r);
Zaharel zaharel(n);
for (int i = 1; i <= n; ++i) {
Read(x);
zaharel.Insert(x);
}
zaharel.Compute();
cout << zaharel.Query(l, r);
PLEC();
}