#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';
}
#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';
}
heyyy!!!!
ReplyDeletei just got only 60 percent evaluation for this question SER9
same here! please help.
Deletesame 60%
Delete#include
Deleteint 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;
}
SER9
ReplyDeleteONLY 60 PERCENT
ReplyDelete#include
Deleteint 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;
}
#include
Deleteint 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;
}
we have to declare (n) also
ReplyDeleteThere is another SER9 question related to Pokemon so can you share the code for that? :)
ReplyDeleteyes world cup pokemon plzzz
DeleteIf anyone has got the world cup pokemon program version of ser9 100% evaluated then plzz post it below. thank you!
ReplyDelete//worldcup//
ReplyDelete#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;
}
Nothing works
ReplyDelete