#include<iostream>
#include<queue>
#include<set>
usingnamespace std;
int main()
{
int n;
cin>>n;
queue<int>q; //takes elements
set<int>s,dis; //s keeps count of current unique elements, dis for totol unique
int arr[n]; //array for taking input
for(int i=0;i<n;i++)
{
cin>>arr[i];
dis.insert(arr[i]);
}
int k=dis.size(); //k is number of unique elements
longlongint ans=0;
for(int i=0;i<n;i++)
{
s.insert(arr[i]);
q.push(arr[i]);
int prev=q.front();
if(s.size()==k) //if unique elements till now is same as total unique
{
while(q.front()==prev)
{
ans+=n-i;
q.pop();
}
s.erase(s.find(prev));
}
}
cout<<ans;
return 0;
}
In an array, which consists of N elements, A1, A2, ..., AN, if a subarray has the total number of distinct elements as that of the original array, that determines the presence of Team Rocket.
at least keep the story going, invent something about the meaning of the numbers
and don't use a trademark