Pagini recente » Cod sursa (job #2576274) | Cod sursa (job #2947309) | Cod sursa (job #2715215) | Cod sursa (job #386556) | Cod sursa (job #1779212)
#include <bits/stdc++.h>
#define per pair<unsigned int,unsigned int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define MOD 666013
using namespace std;
unsigned int n,l,u;
unsigned int a[1048581];
vector <per> Hash[MOD+5];
inline void add(unsigned int x,unsigned int cnt)
{
unsigned int mask = x % MOD;
for (auto it = Hash[mask].begin(); it!=Hash[mask].end(); ++it)
{
per y = *it;
if (y.f==x)
{
Hash[mask].erase(it);
Hash[mask].pb(mp(x,y.s+cnt));
return ;
}
}
Hash[mask].pb(mp(x,1));
return ;
}
inline bool find(unsigned int x)
{
unsigned int mask = x % MOD;
for (auto &it : Hash[mask])
if (it.f==x&&it.s>0)return true;
return false;
}
inline long long solve(unsigned int x)
{
unsigned int dist = 0, p1 = 1;
long long sol = 0LL;
for (unsigned int i = 1; i<=n; ++i)
{
if (find(a[i])==false)
++dist;
add(a[i],1);
while(dist>x)
{
add(a[p1],-1);
if (find(a[p1])==false)--dist;
++p1;
}
sol += 1ll*(i-p1+1);
}
for (unsigned int i = 0 ; i <= MOD; ++i)
Hash[i].clear();
return sol;
}
class InputReader {
public:
InputReader() {}
InputReader(const char *file_name) {
input_file = fopen(file_name, "r");
cursor = 0;
fread(buffer, SIZE, 1, input_file);
}
inline InputReader &operator >>(unsigned int &n) {
while(buffer[cursor] < '0' || buffer[cursor] > '9') {
advance();
}
n = 0;
while('0' <= buffer[cursor] && buffer[cursor] <= '9') {
n = n * 10 + buffer[cursor] - '0';
advance();
}
return *this;
}
private:
FILE *input_file;
static const int SIZE = 1 << 17;
int cursor;
char buffer[SIZE];
inline void advance() {
++ cursor;
if(cursor == SIZE) {
cursor = 0;
fread(buffer, SIZE, 1, input_file);
}
}
};
int main()
{
InputReader fin("secv5.in");
freopen("secv5.out","w",stdout);
fin >> n >> l >> u;
for (unsigned int i = 1; i<=n; ++i)
fin >> a[i];
printf("%d\n",solve(u) - solve(l-1));
return 0;
}