Encontre números únicos no array

Bem, eu tenho que descobrir quantos números diferentes estão em uma matriz.

Por exemplo, se array for: 1 9 4 5 8 3 1 3 5

O resultado deve ser 6, porque 1,9,4,5,8,3 são únicos e 1,3,5 estão repetindo (não únicos).

Então, aqui está o meu código até agora ..... não está funcionando corretamente.

#include <iostream>

using namespace std;

int main() {
    int r = 0, a[50], n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int j = 0; j < n; j++) {
        for (int k = 0; k < j; k++) {
            if (a[k] != a[j]) r++;
        }
    }
    cout << r << endl;
    return 0;
}

questionAnswers(8)

yourAnswerToTheQuestion