SER9

 #include<stdio.h>
#include<math.h>
#include<stdlib.h>
unsigned long * distinct(unsigned long a[],int N);
unsigned char search(unsigned long *b,int l,int r,unsigned long a);
unsigned char occur(unsigned long *a,int l,int r,unsigned long n);
int last;
int main()
{
    long int N,i;
    unsigned long *a,*b;
    unsigned long long count=0;
    scanf("%ld",&N);
    if(N<1 || N>2*pow(10,5))
    return 0;
    a=malloc(N*sizeof(unsigned long));
    for(i=0;i<N;i++)
    {
        scanf("%ld",&a[i]);
        if(a[i]<1 || a[i]>pow(10,9))
        return 0;
    }
    b=calloc(N,sizeof(unsigned long));
    b=distinct(a,N);
    if(last!=0)
    count=N-last;
    else
    {
        count=(N*(N+1))/2;
        printf("%llu",count);
        return 0;
    }
    i=1;
    while(i<N)
    {
        if(search(a,i,last,a[i-1])=='y')
        {
            count+=N-last;
            i++;
            continue;
        }
        else if(occur(a,last+1,N-1,a[i-1])=='n')
        break;
        count+=N-last;
        i++;
    }
    printf("%llu",count);
    return 0;
   
}
unsigned long * distinct(unsigned long a[],int N)
{
    unsigned long *b;
    b=calloc(N,sizeof(unsigned long));
    int i,j=1;
    b[0]=a[0];
    for(i=1;i<N;i++)
    {
        if(search(b,0,j,a[i])=='n')
        {
            b[j]=a[i];
            j++;
            last=i;
        }
    }
    return b;
}
unsigned char search(unsigned long *b,int l,int r,unsigned long a)
{
    int i;
    for(i=l;i<=r;i++)
    {
        if(b[i]==a)
        return 'y';
    }
    return 'n';
}
unsigned char occur(unsigned long *a,int l,int r,unsigned long n)
{
    int i;
    for(i=l;i<=r;i++)
    {
        if(a[i]==n)
        {
            last=i;
            return 'y';
        }
    }
    return 'n';
}

14 comments:

  1. heyyy!!!!
    i just got only 60 percent evaluation for this question SER9

    ReplyDelete
    Replies
    1. #include
      int main()
      {
      int i,f,t,q;
      long long int s=0,w;
      scanf("%d",&n);
      for(i=0;i<n;i++)
      {
      scanf("%d",&f);
      scanf("%lld",&w);
      scanf("%d",&t);
      if(f==1)
      {
      s=s+w;
      }
      if(f==2)
      {
      printf("%lld\n",s);
      s=0;
      }
      }
      return 0;
      }

      Delete
  2. Replies
    1. #include
      int main()
      {
      int i,f,t,q;
      long long int s=0,w;
      scanf("%d",&n);
      for(i=0;i<n;i++)
      {
      scanf("%d",&f);
      scanf("%lld",&w);
      scanf("%d",&t);
      if(f==1)
      {
      s=s+w;
      }
      if(f==2)
      {
      printf("%lld\n",s);
      s=0;
      }
      }
      return 0;
      }

      Delete
    2. #include
      int main()
      {
      int i,f,t,q,n;
      long long int s=0,w;
      scanf("%d",&n);
      for(i=0;i<n;i++)
      {
      scanf("%d",&f);
      scanf("%lld",&w);
      scanf("%d",&t);
      if(f==1)
      {
      s=s+w;
      }
      if(f==2)
      {
      printf("%lld\n",s);
      s=0;
      }
      }
      return 0;
      }

      Delete
  3. There is another SER9 question related to Pokemon so can you share the code for that? :)

    ReplyDelete
  4. If anyone has got the world cup pokemon program version of ser9 100% evaluated then plzz post it below. thank you!

    ReplyDelete
  5. //worldcup//
    #include
    using namespace std;
    long long int countDistictSubarray(int arr[], int n);
    int main()
    {
    int t, a[50];
    cin>>t;
    for(int i=0;i>a[i];
    if(a[1] != 4)
    {if(a[0]==2)
    cout<
    using namespace std;
    int main() {
    int a,f=0,s=0,flag=0;
    cin>>a;
    int arr[a][3];
    for(int i=0;i>arr[i][j];
    if(arr[i][0]==2)
    {
    for(int k=f;k<i;k++)
    {flag=1;
    s=s+arr[k][1];
    }
    if(flag==1)
    cout<<s<<"\n";
    flag=0;
    s=0;
    f=i+1;
    }
    }
    }


    return 0;
    }

    ReplyDelete

SRM ELAB SOLUTUONS   DATA-STRUCTURE                                                                             **IF THE PROGRAM DON...