Poke man joke

QUESTION

There are a lot of Poke’mons who are jealous of the fact that they do NOT have any specialty, they’re the… normal type of Poke’mon. But, what they fail to realize is that their power is their normalcy, the ability to think, rationalize and then act.\n\nBut, they do have an additional power… Poke’mons like Jigglypuff – which are normal, can figure out if a trainer is real or is a part of Team Rocket. And they need to use their power to a great extent.\n\nIn 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.\n\nYou have to help the normal type Pokemons in figuring out the total number of subarrays having total number of distinct elements same as that of the original array.\n\nInput format:\nThe first line of the input will consist of a single integer N \nThe next line will consist of N integers A1, A2, … , AN.\n\nOutput format: Output the answer to the problem.

“TESTCASE_1”: “5\n1 2 2 1 1\n###—###SEPERATOR—###—\n8”, “TESTCASE_2”: “10\n86 5 34 64 56 60 81 77 36 41\n###—###SEPERATOR—###—\n1”, “TESTCASE_3”: “13\n86 5 34 64 56 60 81 77 36 41 98 67 3\n###—###SEPERATOR—###—\n1”, “TESTCASE_4”: “0\n###—###SEPERATOR—###—\n0”, “TESTCASE_5”: “0\n###—###SEPERATOR—###—\n0

ANSWER

#include<stdio.h>
int main()
{
int a[200005],i,j,n,k=0,m=0,d=0,u,q,flag=0;
long int sum=0;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
 
}
for(i=0;i<n;i++)
{
for(j=0;j<i;j++)
{
if (a[i] == a[j])
break;}
if (i == j){
d++;
k=i; 
//printf("%d",k);
 
}
}
// printf("%d",k);
if(k==0)
{
for(u=n;u>=0;u--)
{
sum=sum+u;
}
}
else
{
while(m<k)
{
if(flag==0)
{sum=sum+n-k;
m++;}
if(m==n)
{
//sum=sum+n-k;
}
if(a[m-1]==a[m])
{
sum=sum+n-k;
flag=1;
m++;
continue;
}
if(a[m-1]!=a[m])
{
for(j=m;j<n;j++)
{
if(a[j]==a[m-1])
{
q=j;
break;
}
 
}
if(j==n)
{
break;
}
if(q<k)
{
sum=sum+n-k;
m++;
flag=1;
continue;
}
if(k<q)
{
k=q;
sum=sum+n-k;
m++;
flag=1;
continue;
}
}
 
}
}
printf("%ld",sum);
 return 0;
}
Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Powered By
CHP Adblock Detector Plugin | Codehelppro