Subarray with distinct element hashing

#include <bits/stdc++.h>
using namespace std;

int main()
{
int n;
cin >> n;
unordered_map<int, int> s;
int ans = 0;
int arr[n];
for (int i = 0; i < n; i++)
{
cin >> arr[i];
}
int j = 0;
int i = 0;
while (i < n)
{
//Starting from ith index find the largest unique elements subarray
for (j = i; j < n; j++)
{
if (s.find(arr[j]) == s.end())
{
s.insert(make_pair(arr[j], j));
}
else
{
break;
}
}
//Sum of all uniqe element subarrays from i to jth index
ans += ((j - i + 1) * (j - i + 2)) / 2;
//Since we have already calculated the sum of all the possible subarrays starting from index i
s.erase(arr[i]);
i++;
}
cout << ans << endl;
}

PLz tell what is wrong in this code?I think i am using the correct logic(hopefully) but the implementation is wrong?