unordered_set

I had this problem, given n and m, n numbers , and the m elements go after this rule, first 2 elements of the m are a and b, and the others are with the formula
R[ i ] = (C * R[i - 1] + D * R[i - 2]) % E. with c , d and e given. The quest is to find how many common elements have the n and m numbers between . i had a solution which is this : and i got 50/100 for wrong anwer and TLE, and with one small change i got 100 but i dont understand why : this is my 100/100 solution :
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

ofstream fout("muzica.out");
ifstream fin("muzica.in");

int main()
{
ll c, d, x, r;
ll a, b, e;
int i, n, m, f = 0;
fin >> n >> m >> a >> b >> c >> d >> e;
unordered_set < ll > s(10 * n);
for (i = 1; i <= n; ++i)
{
fin >> x;
s.insert(x);
}
for (i = 1; i <= m; ++i)
{
if (s.find(a) != s.end())
{
s.erase(a);
++f;
}
r = (c * b + d * a) % e;
a = b;
b = r;
}
fout << f << '\n';
return 0;
}
the 50/100 program had unordered_set < ll > s; instead of unordered_set < ll > s(10 * n); what is the difference ? i dont understand why , maybe teach me a little unordered_set because i dont understand this.
Last edited on
An unordered set is a hash table. See this link for a good description.

http://www.cplusplus.com/reference/unordered_set/unordered_set/

The difference between your 2 lines is that the first calls the default constructor, and the second calls the constructor telling the unordered_set the minimum number of buckets to set up in the hash table. If the number of buckets is too small, there can be performance issues finding elements in the hash table. Increasing the number of buckets (with a constructor argument) can speed up hash table access.

I assume TLE means too long to execute or something like that (I'm not familiar with the abbreviation). Is that what "wrong answer" means, or did you get the wrong result, too? I don't think that there should be any differences (other than speed) between the 2 instantiations of the unordered_set.
thanks, and TLE means time limit exceeded!
Topic archived. No new replies allowed.